From 525b741b6fbb178b11c6a2b3ccd4bf9ff9e98e0c Mon Sep 17 00:00:00 2001 From: Thomas Wiest Date: Tue, 28 Oct 2014 14:43:15 -0400 Subject: Added Docker image build stuff --- roles/docker_img_puppet/README.md | 36 +++++++++ roles/docker_img_puppet/defaults/main.yml | 2 + .../files/puppet_container/Dockerfile | 32 ++++++++ .../files/puppet_container/service.rb | 18 +++++ .../files/puppet_container/start.rb | 86 ++++++++++++++++++++++ roles/docker_img_puppet/handlers/main.yml | 2 + roles/docker_img_puppet/meta/main.yml | 14 ++++ roles/docker_img_puppet/tasks/main.yml | 10 +++ roles/docker_img_puppet/vars/main.yml | 2 + 9 files changed, 202 insertions(+) create mode 100644 roles/docker_img_puppet/README.md create mode 100644 roles/docker_img_puppet/defaults/main.yml create mode 100644 roles/docker_img_puppet/files/puppet_container/Dockerfile create mode 100755 roles/docker_img_puppet/files/puppet_container/service.rb create mode 100755 roles/docker_img_puppet/files/puppet_container/start.rb create mode 100644 roles/docker_img_puppet/handlers/main.yml create mode 100644 roles/docker_img_puppet/meta/main.yml create mode 100644 roles/docker_img_puppet/tasks/main.yml create mode 100644 roles/docker_img_puppet/vars/main.yml (limited to 'roles/docker_img_puppet') diff --git a/roles/docker_img_puppet/README.md b/roles/docker_img_puppet/README.md new file mode 100644 index 000000000..57ff5b6b4 --- /dev/null +++ b/roles/docker_img_puppet/README.md @@ -0,0 +1,36 @@ +Role Name +========= + +The purpose of this role is to setup files to do the puppet docker image build + +Requirements +------------ + +Docker + +Role Variables +-------------- + +None + +Dependencies +------------ + +None + +Example Playbook +---------------- + + - hosts: servers + roles: + - docker_img_puppet + +License +------- + +ASL 2.0 + +Author Information +------------------ + +Thomas Wiest diff --git a/roles/docker_img_puppet/defaults/main.yml b/roles/docker_img_puppet/defaults/main.yml new file mode 100644 index 000000000..1f563defd --- /dev/null +++ b/roles/docker_img_puppet/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for docker_img_puppet diff --git a/roles/docker_img_puppet/files/puppet_container/Dockerfile b/roles/docker_img_puppet/files/puppet_container/Dockerfile new file mode 100644 index 000000000..0bc72d389 --- /dev/null +++ b/roles/docker_img_puppet/files/puppet_container/Dockerfile @@ -0,0 +1,32 @@ +# This FROM gives us the proper oo-rhui certs, basic runtime env vars, basic repos, etc. +# Otherwise we can't install anything +FROM rhel6ops + +MAINTAINER Thomas Wiest + +RUN yum -y update ; yum clean all + +# Container Specific RPMs +RUN yum -y install puppet3 crontabs cronie-anacron cronie system-config-firewall-base httpd mod_ssl ruby193-rubygem-zbxapi mod_security rhc-site-static; yum clean all + +# BEGIN: These are to fake out puppet + +RUN rm /usr/sbin/lokkit ; ln -s /bin/true /usr/sbin/lokkit + +# END: These are to fake out puppet + +# Container specific files +ADD start.rb /usr/local/sbin/start.rb +ADD service.rb /sbin/service + +# Ensure the scripts are executable +RUN chmod 755 /sbin/service /usr/local/sbin/start.rb + +RUN yum -y install strace ; yum clean all + +# Get rid of puppet deprecation warnings +RUN sed -i 's/^.*manifest =.*$//' /etc/puppet/puppet.conf ; \ + sed -i 's/^.*manifestdir =.*$//' /etc/puppet/puppet.conf ; \ + sed -i 's/^.*modulepath =.*$//' /etc/puppet/puppet.conf + +CMD ["/usr/local/sbin/start.rb"] diff --git a/roles/docker_img_puppet/files/puppet_container/service.rb b/roles/docker_img_puppet/files/puppet_container/service.rb new file mode 100755 index 000000000..40779c270 --- /dev/null +++ b/roles/docker_img_puppet/files/puppet_container/service.rb @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby + +require 'fileutils' + +if __FILE__ == $0 + abort "\nUsage: #{File.basename($0)} \n\n" unless ARGV.size == 2 + + name = ARGV[0] + action = ARGV[1] + + SERVICE_IPC_DIR = '/var/run/ctr-ipc/service' + + FileUtils.mkdir_p(SERVICE_IPC_DIR) + + File.open("#{SERVICE_IPC_DIR}/#{name}", 'w') do |f| + f.print action + end +end diff --git a/roles/docker_img_puppet/files/puppet_container/start.rb b/roles/docker_img_puppet/files/puppet_container/start.rb new file mode 100755 index 000000000..f1dd940ba --- /dev/null +++ b/roles/docker_img_puppet/files/puppet_container/start.rb @@ -0,0 +1,86 @@ +#!/usr/bin/env ruby + +require 'fileutils' + +CTR_CONFIG_FLAG = '/shared/var/run/ctr-ipc/flag/ctr_configured' + + +class Start + def self.setup_shared_dirs() + puts '_' + puts 'Setting up dirs in shared volume' + puts '--------------------------------' + mtab = File.read('/etc/mtab') + + shared_dirs = mtab.grep(/ \/shared\//).collect { |line| line.split(' ')[1] } + + shared_dirs.each do |sh_dir| + orig_dir = sh_dir.gsub(/^\/shared/,'') + + next if File.symlink?(orig_dir) + + if File.exist?(orig_dir) + cmd = "cp -vaf #{orig_dir} #{File.dirname(sh_dir)}" + puts "Running: #{cmd}" + system(cmd) + + cmd = "rm -vrf #{orig_dir}" + puts "Running: #{cmd}" + system(cmd) + end + + FileUtils.ln_s(sh_dir, orig_dir, {:verbose => true}) + end + puts 'Done.' + puts '_' + end + + def self.run_puppet_agent() + puts '_' + puts 'Running Puppet Agent' + puts '--------------------' + exitcode = nil + 1.upto(3) do |ctr| + unless ctr == 1 + puts '_' + puts "Previous puppet run failed with exit code [#{exitcode}], running again..." + puts '_' + end + + system("bash -c 'time /usr/bin/puppet agent -t'") + exitcode = $?.exitstatus + puts "Exit Code [#{exitcode}]" + + break if exitcode == 0 || exitcode == 2 + end + + raise "Puppet run failed, retries exhausted." if exitcode != 0 && exitcode != 2 + + puts 'Done.' + puts '_' + + puts '_' + puts 'Creating ctr_configured flag' + FileUtils.mkdir_p(File.dirname(CTR_CONFIG_FLAG)) + FileUtils.touch(CTR_CONFIG_FLAG) + puts 'Done.' + puts '_' + end + + def self.exec_puppetd() + puts '_' + puts 'Exec-ing puppet daemon' + puts '---------------------' + puts "Starting puppet agent..." + exec("bash -c '/usr/bin/puppet agent --no-daemonize --detailed-exitcodes --verbose'") + end +end + +if __FILE__ == $0 + $stdout.sync = true + $stderr.sync = true + + Start.setup_shared_dirs() + Start.run_puppet_agent() + Start.exec_puppetd() +end diff --git a/roles/docker_img_puppet/handlers/main.yml b/roles/docker_img_puppet/handlers/main.yml new file mode 100644 index 000000000..9b5fe2b3d --- /dev/null +++ b/roles/docker_img_puppet/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for docker_img_build diff --git a/roles/docker_img_puppet/meta/main.yml b/roles/docker_img_puppet/meta/main.yml new file mode 100644 index 000000000..40f83bf2f --- /dev/null +++ b/roles/docker_img_puppet/meta/main.yml @@ -0,0 +1,14 @@ +--- +galaxy_info: + author: Thomas Wiest + description: Tools to do docker image builds + company: Red Hat + license: ASL 2.0 + min_ansible_version: 1.6 + platforms: + - name: EL + versions: + - 7 + categories: + - docker +dependencies: [] diff --git a/roles/docker_img_puppet/tasks/main.yml b/roles/docker_img_puppet/tasks/main.yml new file mode 100644 index 000000000..87741b6c1 --- /dev/null +++ b/roles/docker_img_puppet/tasks/main.yml @@ -0,0 +1,10 @@ +--- +- name: deploy puppet image build files + file: dest=/usr/local/etc/containers/puppet_container mode=755 state=directory + +- name: deploy puppet image build files + copy: "src=puppet_container/{{ item.name }} dest=/usr/local/etc/containers/puppet_container/{{ item.name }} mode={{ item.mode }}" + with_items: + - { name: 'Dockerfile', mode: '644' } + - { name: 'service.rb', mode: '755' } + - { name: 'start.rb', mode: '755' } diff --git a/roles/docker_img_puppet/vars/main.yml b/roles/docker_img_puppet/vars/main.yml new file mode 100644 index 000000000..3abe3ae6a --- /dev/null +++ b/roles/docker_img_puppet/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for docker_img_puppet -- cgit v1.2.3