79 lines
2.4 KiB
Plaintext
79 lines
2.4 KiB
Plaintext
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", "#{BUILD_DIR}/util")
|
|
|
|
task :package do
|
|
commit = (ENV["GIT_COMMIT"] || `git rev-parse HEAD`).chomp()
|
|
branch = (ENV["GIT_BRANCH"] || `git symbolic-ref -q HEAD`).chomp()
|
|
branch = branch.gsub('refs/heads/', '').gsub('origin/', '').gsub('/', '_')
|
|
build_number = (ENV["BUILD_NUMBER"] || "dev").chomp()
|
|
|
|
if branch == "master"
|
|
deploy_name = "#{PACKAGE_NAME}-#{commit}"
|
|
else
|
|
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",
|
|
"--after-install=#{postinstall.path}",
|
|
"--prefix=#{INSTALL_DIR_PATH}",
|
|
"-C", "#{REPO_ROOT}",
|
|
"--depends=python-mysqldb",
|
|
"--depends=python-django",
|
|
"--depends=python-pip",
|
|
"--depends=python-flup",
|
|
"--depends=python-numpy",
|
|
"--depends=python-scipy",
|
|
"--depends=python-matplotlib",
|
|
"--depends=python-libxml2",
|
|
"--depends=python2.7-dev",
|
|
"--depends=libxml2-dev",
|
|
"--depends=libxslt-dev",
|
|
"--depends=python-markdown",
|
|
"--depends=python-pygments",
|
|
"--depends=mysql-client",
|
|
"--name=#{deploy_name}",
|
|
"--version=#{VERSION}",
|
|
"--iteration=#{build_number}",
|
|
"-a", "all",
|
|
"."]
|
|
system(*args) || raise("fpm failed to build the .deb")
|
|
end
|
|
end
|