From 79476eca6ea6882379f5ebd91872ca80ed98c9b4 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Mon, 26 Mar 2012 15:05:29 -0400 Subject: [PATCH] Add a post-install script that points the link to the correct revision --- rakefile | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/rakefile b/rakefile index e5d530c4ac..692c40d25d 100644 --- a/rakefile +++ b/rakefile @@ -1,10 +1,19 @@ require 'rake/clean' require 'tempfile' +# Build Constants REPO_ROOT = File.dirname(__FILE__) BUILD_DIR = File.join(REPO_ROOT, "build") + +# Packaging constants +DEPLOY_DIR = "/opt/wwc" +PACKAGE_NAME = "mitx" +LINK_PATH = File.join(DEPLOY_DIR, PACKAGE_NAME) +VERSION = "0.1" + +# Set up the clean and clobber tasks CLOBBER.include('build') -CLEAN.include("#{BUILD_DIR}/*.deb") +CLEAN.include("#{BUILD_DIR}/*.deb", "#{BUILD_DIR}/util") task :package do commit = (ENV["GIT_COMMIT"] || `git rev-parse HEAD`).chomp() @@ -13,20 +22,37 @@ task :package do build_number = (ENV["BUILD_NUMBER"] || "dev").chomp() if branch == "master" - package_name = "mitx" + deploy_name = "#{PACKAGE_NAME}-#{commit}" else - package_name = "mitx-#{branch}" + deploy_name = "#{PACKAGE_NAME}-#{branch}-#{commit}" end + INSTALL_DIR_PATH = File.join(DEPLOY_DIR, deploy_name) FileUtils.mkdir_p(BUILD_DIR) Dir.chdir(BUILD_DIR) do + + postinstall = Tempfile.new('postinstall') + postinstall.write <<-POSTINSTALL.gsub(/^\s*/, '') + #! /bin/sh + set -e + set -x + + service gunicorn stop + rm #{LINK_PATH} + ln -s #{INSTALL_DIR_PATH} #{LINK_PATH} + service gunicorn start + POSTINSTALL + postinstall.close() + FileUtils.chmod(0755, postinstall.path) + args = ["fakeroot", "fpm", "-s", "dir", "-t", "deb", "--exclude=build", "--exclude=rakefile", "--exclude=.git", "--exclude=**/*.pyc", - "--prefix=/opt/wwc/mitx-#{commit}", + "--after-install=#{postinstall.path}", + "--prefix=#{INSTALL_DIR_PATH}", "-C", "#{REPO_ROOT}", "--depends=python-mysqldb", "--depends=python-django", @@ -42,8 +68,8 @@ task :package do "--depends=python-markdown", "--depends=python-pygments", "--depends=mysql-client", - "--name=#{package_name}-#{commit}", - "--version=0.1", + "--name=#{deploy_name}", + "--version=#{VERSION}", "--iteration=#{build_number}", "-a", "all", "."]