Skip to content

Instantly share code, notes, and snippets.

@mmb
Created Jun 13, 2014
Embed
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'
FileUtils.mkdir_p(work_dir)
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
end
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}"
end
docker_file << "\n"
end
# 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
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment