diff options
Diffstat (limited to 'bootstrap')
| -rw-r--r-- | bootstrap/.gitignore | 2 | ||||
| -rw-r--r-- | bootstrap/config.yaml.example | 4 | ||||
| -rwxr-xr-x | bootstrap/pillar_config.rb | 60 | ||||
| -rwxr-xr-x | bootstrap/run_salt.sh | 24 |
4 files changed, 90 insertions, 0 deletions
diff --git a/bootstrap/.gitignore b/bootstrap/.gitignore new file mode 100644 index 0000000..ecbfae1 --- /dev/null +++ b/bootstrap/.gitignore @@ -0,0 +1,2 @@ +config.yaml +config.yaml.gentoo-basimage diff --git a/bootstrap/config.yaml.example b/bootstrap/config.yaml.example new file mode 100644 index 0000000..e7d8996 --- /dev/null +++ b/bootstrap/config.yaml.example @@ -0,0 +1,4 @@ +registry: + url: ~ + username: ~ + password: ~ diff --git a/bootstrap/pillar_config.rb b/bootstrap/pillar_config.rb new file mode 100755 index 0000000..44fa02c --- /dev/null +++ b/bootstrap/pillar_config.rb @@ -0,0 +1,60 @@ +#!/usr/bin/ruby + +require "digest/sha1" +require "digest" +require "getoptlong" +require "json" +require "socket" +require "yaml" + +def sha() + seed = "" + File.open("/dev/urandom", "r") do |f| + seed = "#{f.sysread(24)}" + end + Digest::SHA1.hexdigest(seed) +end + +def process_yaml(build_basedir, local_build) + env_yaml_path = "#{File.dirname($0)}/config.yaml" + if ! File.file?(env_yaml_path) + STDERR.puts "Unable to find config.yaml. Exiting." + exit(1) + end + tag = sha()[0..23] + yml = YAML.load_file(env_yaml_path) + yml["gentoo_baseimage"] = {} + yml["gentoo_baseimage"]["image_name"] = "gentoo_baseimage" + yml["gentoo_baseimage"]["container_name"] = "gentoo_baseimage" + yml["gentoo_baseimage"]["build_dir"] = "#{build_basedir}/gentoo_baseimage" + yml["ansible"] = {} + yml["ansible"]["build_dir"] = "#{build_basedir}/ansible" + yml["ci"] = {} + yml["ci"]["build_dir"] = "#{build_basedir}/ci" + yml["ci"]["tag"] = tag + yml["ci"]["local_build"] = YAML.load(local_build) + yml +end + +def main() + build_basedir = nil + local_build = "false" + opts = GetoptLong.new(["--build-basedir", "-d", GetoptLong::REQUIRED_ARGUMENT], + ["--local-build", "-l", GetoptLong::REQUIRED_ARGUMENT]) + opts.each do |opt, arg| + case opt + when "--build-basedir" + build_basedir = arg + when "--local-build" + local_build = arg + end + end + if ! build_basedir + raise "--build-basedir must be supplied." + end + yml = process_yaml(build_basedir, local_build) + puts yml.to_json +end + +main() +exit(0) diff --git a/bootstrap/run_salt.sh b/bootstrap/run_salt.sh new file mode 100755 index 0000000..47a9a4f --- /dev/null +++ b/bootstrap/run_salt.sh @@ -0,0 +1,24 @@ +#!/bin/bash -e + +working_dir="${1}" +build_basedir="${2}" +local_build="${3}" +python=$(which python2 || false) + +salt_running_p() { + ps -ef | grep -F "salt-call" | grep -v "grep" + return ${?} +} + +while salt_running_p; do + sleep 5 +done + +${python} $(which salt-call) \ + --local \ + --pillar-root=${working_dir}/pillar \ + --file-root=${working_dir}/salt \ + state.highstate \ + pillar="$($(dirname ${0})/pillar_config.rb --build-basedir=${build_basedir} --local-build=${local_build})" + +exit 0 |
