diff --git a/packer/docker/centos/Dockerfile b/packer/docker/centos/Dockerfile new file mode 100644 index 0000000..e8ffeb3 --- /dev/null +++ b/packer/docker/centos/Dockerfile @@ -0,0 +1,22 @@ +FROM centos:7 + +# This Dockerfile is used to build the contiv/centos-systemd image, used by the packer script. +# This is based on the Dockerfile sample here: +# https://github.com/docker-library/docs/tree/master/centos#dockerfile-for-systemd-base-image +MAINTAINER "Madhav Puri" + +ENV container docker + +RUN (cd /lib/systemd/system/sysinit.target.wants/; \ +for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \ +rm -f /lib/systemd/system/multi-user.target.wants/*;\ +rm -f /etc/systemd/system/*.wants/*;\ +rm -f /lib/systemd/system/local-fs.target.wants/*; \ +rm -f /lib/systemd/system/sockets.target.wants/*udev*; \ +rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \ +rm -f /lib/systemd/system/basic.target.wants/*;\ +rm -f /lib/systemd/system/anaconda.target.wants/*; + +VOLUME [ "/sys/fs/cgroup" ] + +CMD ["/usr/sbin/init"] diff --git a/packer/docker/centos/Makefile b/packer/docker/centos/Makefile new file mode 100644 index 0000000..d9433c7 --- /dev/null +++ b/packer/docker/centos/Makefile @@ -0,0 +1,13 @@ +all: build start stop + +start: + docker run -it contiv/centos7 /bin/bash + +stop: + docker rm -f contiv/centos7 + +build: + version=$$(cat VERSION) atlas_token="dummy" packer build --only build --force centos.json + +release-build: + version=$$(cat VERSION) atlas_token=${ATLAS_TOKEN} packer build --only release --force centos.json diff --git a/packer/docker/centos/VERSION b/packer/docker/centos/VERSION new file mode 100644 index 0000000..49d5957 --- /dev/null +++ b/packer/docker/centos/VERSION @@ -0,0 +1 @@ +0.1 diff --git a/packer/docker/centos/centos.json b/packer/docker/centos/centos.json new file mode 100644 index 0000000..5d75b20 --- /dev/null +++ b/packer/docker/centos/centos.json @@ -0,0 +1,85 @@ +{ + "builders": [ + { + "name": "build", + "type": "docker", + "image": "contiv/centos-systemd:latest", + "pull": true, + "commit": true, + "volumes": { + "/sys/fs/cgroup":"/sys/fs/cgroup:ro", + "/tmp/$(mktemp -d)":"/run" + }, + "run_command": ["--privileged", "-d", "-i", "-t", "{{.Image}}", "/usr/sbin/init"] + }, + { + "name": "release", + "type": "docker", + "image": "contiv/centos-systemd:latest", + "pull": true, + "commit": true, + "volumes": { + "/sys/fs/cgroup":"/sys/fs/cgroup:ro", + "/tmp/systemdtest":"/run" + }, + "run_command": ["-privileged", "-d", "-i", "-t", "{{.Image}}", "/usr/sbin/init"] + } + ], + "post-processors": [[ + { + "type": "docker-tag", + "repository": "contiv/centos7", + "tag": "{{ user `version` }}", + "only": ["build", "release"] + }, + { + "type": "docker-push", + "only": ["release"] + } + ]], + "provisioners": [ + { + "type": "shell", + "environment_vars": [ + "http_proxy={{user `http_proxy`}}", + "https_proxy={{user `https_proxy`}}", + "ftp_proxy={{user `ftp_proxy`}}", + "rsync_proxy={{user `rsync_proxy`}}", + "no_proxy={{user `no_proxy`}}" + ], + "scripts": [ + "../../centos/script/ansible.sh", + "script/packer.sh" + ] + }, + { + "type": "ansible-local", + "playbook_dir": "../../../vendor/ansible", + "playbook_file": "../../../vendor/ansible/site.yml", + "inventory_groups": "devtest", + "extra_arguments": [ + "--extra-vars", + "'{\"env\":{ \"http_proxy\":\"{{user `http_proxy`}}\", \"https_proxy\":\"{{user `https_proxy`}}\", \"no_proxy\":\"{{user `no_proxy`}}\", \"ftp_proxy\":\"{{user `ftp_proxy`}}\", \"rsync_proxy\":\"{{user `rsync_proxy`}}\" }, \"validate_certs\":\"no\", \"docker_version\":\"1.11.1\"}'", + "--tags", + "prebake-for-dev,prebake-for-test" + ] + }, + { + "type": "shell", + "scripts": [ + "script/post_provision.sh" + ] + } + ], + "variables": { + "ftp_proxy": "{{env `ftp_proxy`}}", + "http_proxy": "{{env `http_proxy`}}", + "https_proxy": "{{env `https_proxy`}}", + "no_proxy": "{{env `no_proxy`}}", + "rsync_proxy": "{{env `rsync_proxy`}}", + "ssh_password": "vagrant", + "ssh_username": "vagrant", + "atlas_token": "{{ env `atlas_token` }}", + "version": "{{ env `version` }}" + } +} diff --git a/packer/docker/centos/script/packer.sh b/packer/docker/centos/script/packer.sh new file mode 100644 index 0000000..f6178e2 --- /dev/null +++ b/packer/docker/centos/script/packer.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -xe + +rm -f /usr/sbin/packer diff --git a/packer/docker/centos/script/post_provision.sh b/packer/docker/centos/script/post_provision.sh new file mode 100644 index 0000000..21d619b --- /dev/null +++ b/packer/docker/centos/script/post_provision.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -xe + +# enable docker for auto-restart, and cleanly shut it down +# before stopping the container +systemctl enable docker +systemctl stop docker + +# cleanup any temp files created as part of provision +rm -rf /tmp/*