Skip to content

Instantly share code, notes, and snippets.

Created June 13, 2014 05:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
convert a bosh job into a Dockerfile that builds a container with all the job's packages installed
require 'yaml'
require 'fileutils'
job = ARGV[0]
job_spec = YAML.load_file(File.join('jobs', job, 'spec'))
packages = job_spec['packages']
work_dir = 'docker'
docker_file = open(File.join(work_dir, 'Dockerfile'), 'w')
docker_file << "FROM ubuntu\n"
docker_file << "ADD pre_packaging /build\n"
docker_file << "RUN mkdir -p /var/vcap/packages\n"
docker_file << "\n"
pre_packaging_dir = FileUtils.mkdir_p(File.join(work_dir, 'pre_packaging'))
def package_deps(package)
spec = YAML.load_file(File.join('packages', package, 'spec'))
deps = (spec.fetch('dependencies', [])).map { |p| package_deps(p) }.flatten
deps << package
build_order = packages.inject([]) { |order, p| order + package_deps(p) }.uniq
build_order.each do |package|
package_dir = File.join('packages', package)
pre_packaging_script = File.join(package_dir, 'pre_packaging')
FileUtils.mkdir_p(File.join(pre_packaging_dir, package))
packaging_script = File.join(package_dir, 'packaging')
open(packaging_script) do |f|
docker_file << "# #{package}\n"
docker_file << "ENV BOSH_INSTALL_TARGET /var/vcap/packages/#{package}\n"
docker_file << "RUN cd /build/#{package}\n\n"
f.each_line do |line|
docker_file << "RUN #{line}"
docker_file << "\n"
# create temp dir
# puts package files in temp dir
# if pre_packaging script
# set BUILD_DIR to temp dir
# cd temp dir
# run prepackaging script
# tar up temp dir and put in docker/pre_packaging/package
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment