Skip to content

Commit

Permalink
add packer build for centos based container image
Browse files Browse the repository at this point in the history
Signed-off-by: Madhav Puri <[email protected]>
  • Loading branch information
mapuri committed Jul 1, 2016
1 parent fecc5d9 commit 1372d30
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packer/docker/centos/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" <[email protected]>

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"]
13 changes: 13 additions & 0 deletions packer/docker/centos/Makefile
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions packer/docker/centos/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1
85 changes: 85 additions & 0 deletions packer/docker/centos/centos.json
Original file line number Diff line number Diff line change
@@ -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` }}"
}
}
5 changes: 5 additions & 0 deletions packer/docker/centos/script/packer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -xe

rm -f /usr/sbin/packer
11 changes: 11 additions & 0 deletions packer/docker/centos/script/post_provision.sh
Original file line number Diff line number Diff line change
@@ -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/*

0 comments on commit 1372d30

Please sign in to comment.