aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorWilliam Yeh <william.pjyeh@gmail.com>2016-05-30 11:46:11 +0800
committerWilliam Yeh <william.pjyeh@gmail.com>2016-05-30 11:46:11 +0800
commitf966242805e67f91bffdc5f9eb02096bb5e1f856 (patch)
treeadbc4d5e7779f470dbf6e94b244ea33a9d9842d9
parent84d31fd8edaec467b7a22c9fcf9b0f3097539e6a (diff)
downloaddocker-ansible-f966242805e67f91bffdc5f9eb02096bb5e1f856.tar.gz
docker-ansible-f966242805e67f91bffdc5f9eb02096bb5e1f856.tar.zst
docker-ansible-f966242805e67f91bffdc5f9eb02096bb5e1f856.zip
Add: new `mini` series for building minimal images from playbooks.
-rw-r--r--.travis.yml9
-rw-r--r--README.md12
-rw-r--r--circle.yml9
-rw-r--r--mini-alpine3/Dockerfile28
-rwxr-xr-xmini-alpine3/ansible-playbook-wrapper49
-rw-r--r--mini-alpine3/apk-list14
-rwxr-xr-xmini-alpine3/install-ansible.sh26
-rw-r--r--mini-alpine3/pip-list11
-rwxr-xr-xmini-alpine3/prepare-pkg-list.sh68
-rwxr-xr-xmini-alpine3/uninstall-ansible.sh26
-rw-r--r--mini-test/Dockerfile.alpine315
-rw-r--r--mini-test/playbook.yml5
12 files changed, 270 insertions, 2 deletions
diff --git a/.travis.yml b/.travis.yml
index 4e5dfcb..ea6cc78 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -58,6 +58,11 @@ before_install:
58 - docker build -t ansible_master_centos7_onbuild master-centos7-onbuild 58 - docker build -t ansible_master_centos7_onbuild master-centos7-onbuild
59 - docker build -t ansible_master_centos6_onbuild master-centos6-onbuild 59 - docker build -t ansible_master_centos6_onbuild master-centos6-onbuild
60 60
61
62 - docker build -t ansible_mini_apline3 mini-alpine3
63 - docker build -t nginx_apline3 -f mini-test/Dockerfile.alpine3 mini-test
64
65
61script: 66script:
62 - docker run -i ansible_xenial > result-ubuntu16.04 67 - docker run -i ansible_xenial > result-ubuntu16.04
63 - docker run -i ansible_trusty > result-ubuntu14.04 68 - docker run -i ansible_trusty > result-ubuntu14.04
@@ -109,6 +114,8 @@ script:
109 - docker run -i ansible_master_centos6_onbuild > result-master-centos6-onbuild 114 - docker run -i ansible_master_centos6_onbuild > result-master-centos6-onbuild
110 115
111 116
117 - docker run -i nginx_apline3 2> result-nginx-alpine3
118
112 119
113 - echo "==> Validating the test results..." 120 - echo "==> Validating the test results..."
114 - sh -c "[ -s result-ubuntu16.04 ]" 121 - sh -c "[ -s result-ubuntu16.04 ]"
@@ -157,3 +164,5 @@ script:
157 - sh -c "[ -s result-master-debian7-onbuild ]" 164 - sh -c "[ -s result-master-debian7-onbuild ]"
158 - sh -c "[ -s result-master-centos7-onbuild ]" 165 - sh -c "[ -s result-master-centos7-onbuild ]"
159 - sh -c "[ -s result-master-centos6-onbuild ]" 166 - sh -c "[ -s result-master-centos6-onbuild ]"
167
168 - sh -c "[ -s result-nginx-alpine3 ]"
diff --git a/README.md b/README.md
index f0baebb..8abe0cc 100644
--- a/README.md
+++ b/README.md
@@ -18,11 +18,12 @@ These are Docker images for [Ansible](https://github.com/ansible/ansible) softwa
18 18
19- OS: Debian (jessie, wheezy), Ubuntu (xenial, trusty, precise), CentOS (7, 6), Alpine (3). 19- OS: Debian (jessie, wheezy), Ubuntu (xenial, trusty, precise), CentOS (7, 6), Alpine (3).
20 20
21- Ansible: three version series - 21- Ansible: four series -
22 22
23 1. the most recent *stable* version; 23 1. the most recent *stable* version;
24 2. old 1.9 version; 24 2. old 1.9 version;
25 3. the *experimental* version. 25 3. the *experimental* version;
26 4. for building *minimal* images from playbooks; i.e., the Ansible body will be removed when mission completed.
26 27
27 28
28## Images and tags 29## Images and tags
@@ -96,6 +97,13 @@ These are Docker images for [Ansible](https://github.com/ansible/ansible) softwa
96 - `williamyeh/ansible:master-centos6-onbuild` 97 - `williamyeh/ansible:master-centos6-onbuild`
97 98
98 99
100### Minimal series (the Ansible body will be removed when mission completed):
101
102- Onbuild series:
103
104 - `williamyeh/ansible:mini-alpine3`
105
106
99 107
100## For the impatient 108## For the impatient
101 109
diff --git a/circle.yml b/circle.yml
index 60cbe28..9fc121f 100644
--- a/circle.yml
+++ b/circle.yml
@@ -59,6 +59,11 @@ dependencies:
59 - docker build -t ansible_master_centos7_onbuild master-centos7-onbuild 59 - docker build -t ansible_master_centos7_onbuild master-centos7-onbuild
60 - docker build -t ansible_master_centos6_onbuild master-centos6-onbuild 60 - docker build -t ansible_master_centos6_onbuild master-centos6-onbuild
61 61
62
63 - docker build -t ansible_mini_apline3 mini-alpine3
64 - docker build -t nginx_apline3 -f mini-test/Dockerfile.alpine3 mini-test
65
66
62test: 67test:
63 override: 68 override:
64 - docker run -i ansible_xenial > result-ubuntu16.04 69 - docker run -i ansible_xenial > result-ubuntu16.04
@@ -111,6 +116,8 @@ test:
111 - docker run -i ansible_master_centos6_onbuild > result-master-centos6-onbuild 116 - docker run -i ansible_master_centos6_onbuild > result-master-centos6-onbuild
112 117
113 118
119 - docker run -i nginx_apline3 2> result-nginx-alpine3
120
114 121
115 - echo "==> Validating the test results..." 122 - echo "==> Validating the test results..."
116 - sh -c "[ -s result-ubuntu16.04 ]" 123 - sh -c "[ -s result-ubuntu16.04 ]"
@@ -159,3 +166,5 @@ test:
159 - sh -c "[ -s result-master-debian7-onbuild ]" 166 - sh -c "[ -s result-master-debian7-onbuild ]"
160 - sh -c "[ -s result-master-centos7-onbuild ]" 167 - sh -c "[ -s result-master-centos7-onbuild ]"
161 - sh -c "[ -s result-master-centos6-onbuild ]" 168 - sh -c "[ -s result-master-centos6-onbuild ]"
169
170 - sh -c "[ -s result-nginx-alpine3 ]"
diff --git a/mini-alpine3/Dockerfile b/mini-alpine3/Dockerfile
new file mode 100644
index 0000000..2287deb
--- /dev/null
+++ b/mini-alpine3/Dockerfile
@@ -0,0 +1,28 @@
1# Dockerfile for building Alpine-based image, via Ansible playbooks.
2#
3# @see https://github.com/gliderlabs/docker-alpine/blob/master/docs/usage.md
4#
5# Version 1.0
6#
7
8
9# pull base image
10FROM alpine:3.3
11
12MAINTAINER William Yeh <william.pjyeh@gmail.com>
13
14#ENV APK_LIST apk-list
15#ENV PIP_LIST pip-list
16
17
18COPY . /tmp
19
20ONBUILD COPY . /tmp
21ONBUILD RUN \
22 cd /tmp && \
23 ./prepare-pkg-list.sh && \
24 ./install-ansible.sh && \
25 ./ansible-playbook-wrapper && \
26 ./uninstall-ansible.sh && \
27 cd / && \
28 rm -rf /tmp/*
diff --git a/mini-alpine3/ansible-playbook-wrapper b/mini-alpine3/ansible-playbook-wrapper
new file mode 100755
index 0000000..0ba45e6
--- /dev/null
+++ b/mini-alpine3/ansible-playbook-wrapper
@@ -0,0 +1,49 @@
1#!/bin/sh
2#
3# Simple wrapper for executing ansible-galaxy and ansible-playbook
4# with local connection.
5#
6# USAGE:
7# ansible-playbook-wrapper [other ansible-playbook arguments]
8#
9# ENVIRONMENT VARIABLES:
10#
11# - REQUIREMENTS: requirements filename; default = "requirements.yml"
12# - PLAYBOOK: playbook filename; default = "playbook.yml"
13# - INVENTORY: inventory filename; default = "/etc/ansible/hosts"
14#
15
16
17#
18# install Galaxy roles, if any
19#
20
21if [ -z "$REQUIREMENTS" ]; then
22 REQUIREMENTS=requirements.yml
23fi
24
25if [ -f "$REQUIREMENTS" ]; then
26 ansible-galaxy install -r $REQUIREMENTS
27fi
28
29
30#
31# execute playbook
32#
33
34if [ -z "$PLAYBOOK" ]; then
35 PLAYBOOK=playbook.yml
36fi
37
38
39if [ -z "$INVENTORY" ]; then
40 exec ansible-playbook \
41 $PLAYBOOK \
42 --connection=local \
43 "$@"
44else
45 exec ansible-playbook \
46 -i $INVENTORY $PLAYBOOK \
47 --connection=local \
48 "$@"
49fi
diff --git a/mini-alpine3/apk-list b/mini-alpine3/apk-list
new file mode 100644
index 0000000..eec27a4
--- /dev/null
+++ b/mini-alpine3/apk-list
@@ -0,0 +1,14 @@
1#
2# packages to be installed via APK;
3# lines beginning with "! " (an exclamation mark, followed by a space) will *not* be *uninstalled* afterwards.
4#
5
6
7# ssl
8openssl ca-certificates
9
10# python-runtime
11python py-pip
12
13# build-dependencies
14python-dev libffi-dev openssl-dev build-base
diff --git a/mini-alpine3/install-ansible.sh b/mini-alpine3/install-ansible.sh
new file mode 100755
index 0000000..98dede0
--- /dev/null
+++ b/mini-alpine3/install-ansible.sh
@@ -0,0 +1,26 @@
1#!/bin/sh
2#
3# Simple wrapper for installing ansible
4#
5
6
7echo "===> Adding prerequisites..."
8
9cat ___APK_INSTALL_LIST | \
10 while read ITEM; do
11 apk --update add $ITEM
12 done
13
14cat ___PIP_INSTALL_LIST | \
15 while read ITEM; do
16 pip install --upgrade $ITEM
17 done
18
19
20echo "===> Installing Ansible..."
21pip install ansible
22
23
24echo "===> Adding hosts for convenience..." && \
25mkdir -p /etc/ansible && \
26echo 'localhost' > /etc/ansible/hosts
diff --git a/mini-alpine3/pip-list b/mini-alpine3/pip-list
new file mode 100644
index 0000000..0df21dd
--- /dev/null
+++ b/mini-alpine3/pip-list
@@ -0,0 +1,11 @@
1#
2# packages to be installed via PIP;
3# lines beginning with "! " (an exclamation mark, followed by a space) will *not* be *uninstalled* afterwards.
4#
5
6
7# pip itself
8pip
9
10# for ansible
11cffi
diff --git a/mini-alpine3/prepare-pkg-list.sh b/mini-alpine3/prepare-pkg-list.sh
new file mode 100755
index 0000000..67c720d
--- /dev/null
+++ b/mini-alpine3/prepare-pkg-list.sh
@@ -0,0 +1,68 @@
1#!/bin/sh
2#
3# Prepare the list of packages to be installed/uninstalled.
4#
5# ENVIRONMENT VARIABLES:
6#
7# - APK_LIST: APK package list; default = "apk-list"
8# - PIP_LIST: PIP package list; default = "pip-list"
9#
10
11echo "===> Preparing APK package list..."
12
13if [ -z "$APK_LIST" ]; then
14 APK_LIST=apk-list
15fi
16
17if [ -f "$APK_LIST" ]; then
18
19 awk '/^#/ {next} \
20 { split($0,arrayA); \
21 for (i in arrayA) { \
22 if (arrayA[i] == "!") { continue; } \
23 print arrayA[i] \
24 } \
25 }' \
26 $APK_LIST > ___APK_INSTALL_LIST
27
28 awk '/^(#|!)/ {next} \
29 { split($0,arrayA); for (i in arrayA) print arrayA[i] }' \
30 $APK_LIST |
31 awk '{ L[n++] = $0 } \
32 END { while(n--) \
33 print L[n] }' \
34 > ___APK_UNINSTALL_LIST
35
36fi
37#cat ___APK_INSTALL_LIST
38#cat ___APK_UNINSTALL_LIST
39
40
41echo "===> Preparing PIP package list..."
42
43if [ -z "$PIP_LIST" ]; then
44 PIP_LIST=pip-list
45fi
46
47if [ -f "$PIP_LIST" ]; then
48
49 awk '/^#/ {next} \
50 { split($0,arrayA); \
51 for (i in arrayA) { \
52 if (arrayA[i] == "!") { continue; } \
53 print arrayA[i] \
54 } \
55 }' \
56 $PIP_LIST > ___PIP_INSTALL_LIST
57
58 awk '/^(#|!)/ {next} \
59 { split($0,arrayA); for (i in arrayA) print arrayA[i] }' \
60 $PIP_LIST |
61 awk '{ L[n++] = $0 } \
62 END { while(n--) \
63 print L[n] }' \
64 > ___PIP_UNINSTALL_LIST
65
66fi
67#cat ___PIP_INSTALL_LIST
68#cat ___PIP_UNINSTALL_LIST
diff --git a/mini-alpine3/uninstall-ansible.sh b/mini-alpine3/uninstall-ansible.sh
new file mode 100755
index 0000000..173c51d
--- /dev/null
+++ b/mini-alpine3/uninstall-ansible.sh
@@ -0,0 +1,26 @@
1#!/bin/sh
2#
3# Simple wrapper for uninstall ansible and related stuff.
4#
5
6
7echo "===> Removing Ansible..."
8pip uninstall -y ansible
9
10echo "===> Removing PIP packages..."
11cat ___PIP_UNINSTALL_LIST | \
12 while read ITEM; do
13 pip uninstall -y $ITEM
14 done
15
16echo "===> Removing APK packages..."
17cat ___APK_UNINSTALL_LIST | \
18 while read ITEM; do
19 apk del $ITEM
20 done
21
22
23echo "===> Cleaning up package list..."
24rm -rf /var/lib/python2.7 /usr/lib/python2.7
25rm -rf /etc/ansible /root/.ansible /root/.cache /root/.ash_history
26rm -rf /var/cache/apk
diff --git a/mini-test/Dockerfile.alpine3 b/mini-test/Dockerfile.alpine3
new file mode 100644
index 0000000..78e7521
--- /dev/null
+++ b/mini-test/Dockerfile.alpine3
@@ -0,0 +1,15 @@
1# Dockerfile for building (near-)minimal nginx
2#
3
4
5# pull base image
6FROM ansible_mini_apline3
7
8MAINTAINER William Yeh <william.pjyeh@gmail.com>
9
10#ENV APK_LIST apk-list
11#ENV PIP_LIST pip-list
12
13ENTRYPOINT ["/usr/sbin/nginx"]
14#CMD ["-g", "daemon off;"]
15CMD ["-v"]
diff --git a/mini-test/playbook.yml b/mini-test/playbook.yml
new file mode 100644
index 0000000..898dfc5
--- /dev/null
+++ b/mini-test/playbook.yml
@@ -0,0 +1,5 @@
1- hosts: all
2 become: True
3 tasks:
4 - name: install nginx
5 apk: name=nginx state=present