Created
September 29, 2017 09:48
-
-
Save dhiemstra/a2dee5fb600136efa3d69544f91d4e78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Setenv | |
# TODO: Find something better for this.. | |
# TODO: Find a way to get the project name | |
# TODO: Rename to pre-recieve? | |
HOME = "/Users/dhiemstra/Projects/docker/builder/local" | |
BIN_PATH = "#{HOME}/bin" | |
REPOS_PATH = "#{HOME}/repos" | |
BUILDS_PATH = "#{HOME}/builds" | |
RELEASES_PATH = "#{HOME}/releases" | |
SHARE_PATH = "#{HOME}/share" | |
puts "Running post-receive hook.." | |
require 'yaml' | |
def exec(command) | |
puts "Running: #{command}" | |
system(command) | |
exit 1 if $?.exitstatus > 0 | |
end | |
# Read commit info | |
out = STDIN.read | |
old_ref, sha1, ref_name = out.split | |
# Create build path | |
share_path = "#{SHARE_PATH}/homepage" | |
build_path = "#{BUILDS_PATH}/#{sha1}" | |
exec "mkdir -p #{build_path}" | |
# Checkout repository | |
puts "Ref #{ref_name} received. Building release in '#{build_path}'" | |
exec "git --work-tree=\"#{build_path}\" --git-dir=\"#{ENV['PWD']}\" checkout -f #{sha1}" | |
# Read pipeline | |
Dir.chdir build_path do | |
pipeline = YAML.load(File.read('build.yml')) | |
docker_args = [ | |
"--rm", | |
"-v #{build_path}:/app", | |
"-v #{share_path}:/data", | |
"-w /app", | |
pipeline['image'] | |
].join(' ') | |
# Iniitalize image | |
puts "Pulling image: #{pipeline['image']}" | |
exec "docker pull #{pipeline['image']}" | |
# Run build | |
pipeline['commands'].each do |cmd| | |
exec "docker run #{docker_args} #{cmd}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: registry.gitlab.com/dhiemstra/rails:2.3.4-node6 | |
target: public | |
environment: | |
LANG: C.UTF-8 | |
commands: | |
- curl -o /usr/local/bin/phraseapp -Ls https://github.com/phrase/phraseapp-client/releases/download/1.4.5/phraseapp_linux_386 | |
- chmod +x /usr/local/bin/phraseapp | |
- bundle install --without development test staging | |
- yarn install | |
- /usr/local/bin/phraseapp pull | |
- rake data:all --trace | |
- npm rebuild node-sass | |
- bundle exec middleman build -e production |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment