Skip to content

Commit 1372d30

Browse files
committed
add packer build for centos based container image
Signed-off-by: Madhav Puri <[email protected]>
1 parent fecc5d9 commit 1372d30

File tree

6 files changed

+137
-0
lines changed

6 files changed

+137
-0
lines changed

packer/docker/centos/Dockerfile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM centos:7
2+
3+
# This Dockerfile is used to build the contiv/centos-systemd image, used by the packer script.
4+
# This is based on the Dockerfile sample here:
5+
# https://github.com/docker-library/docs/tree/master/centos#dockerfile-for-systemd-base-image
6+
MAINTAINER "Madhav Puri" <[email protected]>
7+
8+
ENV container docker
9+
10+
RUN (cd /lib/systemd/system/sysinit.target.wants/; \
11+
for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
12+
rm -f /lib/systemd/system/multi-user.target.wants/*;\
13+
rm -f /etc/systemd/system/*.wants/*;\
14+
rm -f /lib/systemd/system/local-fs.target.wants/*; \
15+
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
16+
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
17+
rm -f /lib/systemd/system/basic.target.wants/*;\
18+
rm -f /lib/systemd/system/anaconda.target.wants/*;
19+
20+
VOLUME [ "/sys/fs/cgroup" ]
21+
22+
CMD ["/usr/sbin/init"]

packer/docker/centos/Makefile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
all: build start stop
2+
3+
start:
4+
docker run -it contiv/centos7 /bin/bash
5+
6+
stop:
7+
docker rm -f contiv/centos7
8+
9+
build:
10+
version=$$(cat VERSION) atlas_token="dummy" packer build --only build --force centos.json
11+
12+
release-build:
13+
version=$$(cat VERSION) atlas_token=${ATLAS_TOKEN} packer build --only release --force centos.json

packer/docker/centos/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1

packer/docker/centos/centos.json

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"builders": [
3+
{
4+
"name": "build",
5+
"type": "docker",
6+
"image": "contiv/centos-systemd:latest",
7+
"pull": true,
8+
"commit": true,
9+
"volumes": {
10+
"/sys/fs/cgroup":"/sys/fs/cgroup:ro",
11+
"/tmp/$(mktemp -d)":"/run"
12+
},
13+
"run_command": ["--privileged", "-d", "-i", "-t", "{{.Image}}", "/usr/sbin/init"]
14+
},
15+
{
16+
"name": "release",
17+
"type": "docker",
18+
"image": "contiv/centos-systemd:latest",
19+
"pull": true,
20+
"commit": true,
21+
"volumes": {
22+
"/sys/fs/cgroup":"/sys/fs/cgroup:ro",
23+
"/tmp/systemdtest":"/run"
24+
},
25+
"run_command": ["-privileged", "-d", "-i", "-t", "{{.Image}}", "/usr/sbin/init"]
26+
}
27+
],
28+
"post-processors": [[
29+
{
30+
"type": "docker-tag",
31+
"repository": "contiv/centos7",
32+
"tag": "{{ user `version` }}",
33+
"only": ["build", "release"]
34+
},
35+
{
36+
"type": "docker-push",
37+
"only": ["release"]
38+
}
39+
]],
40+
"provisioners": [
41+
{
42+
"type": "shell",
43+
"environment_vars": [
44+
"http_proxy={{user `http_proxy`}}",
45+
"https_proxy={{user `https_proxy`}}",
46+
"ftp_proxy={{user `ftp_proxy`}}",
47+
"rsync_proxy={{user `rsync_proxy`}}",
48+
"no_proxy={{user `no_proxy`}}"
49+
],
50+
"scripts": [
51+
"../../centos/script/ansible.sh",
52+
"script/packer.sh"
53+
]
54+
},
55+
{
56+
"type": "ansible-local",
57+
"playbook_dir": "../../../vendor/ansible",
58+
"playbook_file": "../../../vendor/ansible/site.yml",
59+
"inventory_groups": "devtest",
60+
"extra_arguments": [
61+
"--extra-vars",
62+
"'{\"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\"}'",
63+
"--tags",
64+
"prebake-for-dev,prebake-for-test"
65+
]
66+
},
67+
{
68+
"type": "shell",
69+
"scripts": [
70+
"script/post_provision.sh"
71+
]
72+
}
73+
],
74+
"variables": {
75+
"ftp_proxy": "{{env `ftp_proxy`}}",
76+
"http_proxy": "{{env `http_proxy`}}",
77+
"https_proxy": "{{env `https_proxy`}}",
78+
"no_proxy": "{{env `no_proxy`}}",
79+
"rsync_proxy": "{{env `rsync_proxy`}}",
80+
"ssh_password": "vagrant",
81+
"ssh_username": "vagrant",
82+
"atlas_token": "{{ env `atlas_token` }}",
83+
"version": "{{ env `version` }}"
84+
}
85+
}

packer/docker/centos/script/packer.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
set -xe
4+
5+
rm -f /usr/sbin/packer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -xe
4+
5+
# enable docker for auto-restart, and cleanly shut it down
6+
# before stopping the container
7+
systemctl enable docker
8+
systemctl stop docker
9+
10+
# cleanup any temp files created as part of provision
11+
rm -rf /tmp/*

0 commit comments

Comments
 (0)