diff options
author | William Yeh <william.pjyeh@gmail.com> | 2016-05-30 11:46:11 +0800 |
---|---|---|
committer | William Yeh <william.pjyeh@gmail.com> | 2016-05-30 11:46:11 +0800 |
commit | f966242805e67f91bffdc5f9eb02096bb5e1f856 (patch) | |
tree | adbc4d5e7779f470dbf6e94b244ea33a9d9842d9 | |
parent | 84d31fd8edaec467b7a22c9fcf9b0f3097539e6a (diff) | |
download | docker-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.yml | 9 | ||||
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | circle.yml | 9 | ||||
-rw-r--r-- | mini-alpine3/Dockerfile | 28 | ||||
-rwxr-xr-x | mini-alpine3/ansible-playbook-wrapper | 49 | ||||
-rw-r--r-- | mini-alpine3/apk-list | 14 | ||||
-rwxr-xr-x | mini-alpine3/install-ansible.sh | 26 | ||||
-rw-r--r-- | mini-alpine3/pip-list | 11 | ||||
-rwxr-xr-x | mini-alpine3/prepare-pkg-list.sh | 68 | ||||
-rwxr-xr-x | mini-alpine3/uninstall-ansible.sh | 26 | ||||
-rw-r--r-- | mini-test/Dockerfile.alpine3 | 15 | ||||
-rw-r--r-- | mini-test/playbook.yml | 5 |
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 | |||
61 | script: | 66 | script: |
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 ]" | ||
@@ -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 | ||
@@ -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 | |||
62 | test: | 67 | test: |
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 | ||
10 | FROM alpine:3.3 | ||
11 | |||
12 | MAINTAINER William Yeh <william.pjyeh@gmail.com> | ||
13 | |||
14 | #ENV APK_LIST apk-list | ||
15 | #ENV PIP_LIST pip-list | ||
16 | |||
17 | |||
18 | COPY . /tmp | ||
19 | |||
20 | ONBUILD COPY . /tmp | ||
21 | ONBUILD 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 | |||
21 | if [ -z "$REQUIREMENTS" ]; then | ||
22 | REQUIREMENTS=requirements.yml | ||
23 | fi | ||
24 | |||
25 | if [ -f "$REQUIREMENTS" ]; then | ||
26 | ansible-galaxy install -r $REQUIREMENTS | ||
27 | fi | ||
28 | |||
29 | |||
30 | # | ||
31 | # execute playbook | ||
32 | # | ||
33 | |||
34 | if [ -z "$PLAYBOOK" ]; then | ||
35 | PLAYBOOK=playbook.yml | ||
36 | fi | ||
37 | |||
38 | |||
39 | if [ -z "$INVENTORY" ]; then | ||
40 | exec ansible-playbook \ | ||
41 | $PLAYBOOK \ | ||
42 | --connection=local \ | ||
43 | "$@" | ||
44 | else | ||
45 | exec ansible-playbook \ | ||
46 | -i $INVENTORY $PLAYBOOK \ | ||
47 | --connection=local \ | ||
48 | "$@" | ||
49 | fi | ||
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 | ||
8 | openssl ca-certificates | ||
9 | |||
10 | # python-runtime | ||
11 | python py-pip | ||
12 | |||
13 | # build-dependencies | ||
14 | python-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 | |||
7 | echo "===> Adding prerequisites..." | ||
8 | |||
9 | cat ___APK_INSTALL_LIST | \ | ||
10 | while read ITEM; do | ||
11 | apk --update add $ITEM | ||
12 | done | ||
13 | |||
14 | cat ___PIP_INSTALL_LIST | \ | ||
15 | while read ITEM; do | ||
16 | pip install --upgrade $ITEM | ||
17 | done | ||
18 | |||
19 | |||
20 | echo "===> Installing Ansible..." | ||
21 | pip install ansible | ||
22 | |||
23 | |||
24 | echo "===> Adding hosts for convenience..." && \ | ||
25 | mkdir -p /etc/ansible && \ | ||
26 | echo '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 | ||
8 | pip | ||
9 | |||
10 | # for ansible | ||
11 | cffi | ||
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 | |||
11 | echo "===> Preparing APK package list..." | ||
12 | |||
13 | if [ -z "$APK_LIST" ]; then | ||
14 | APK_LIST=apk-list | ||
15 | fi | ||
16 | |||
17 | if [ -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 | |||
36 | fi | ||
37 | #cat ___APK_INSTALL_LIST | ||
38 | #cat ___APK_UNINSTALL_LIST | ||
39 | |||
40 | |||
41 | echo "===> Preparing PIP package list..." | ||
42 | |||
43 | if [ -z "$PIP_LIST" ]; then | ||
44 | PIP_LIST=pip-list | ||
45 | fi | ||
46 | |||
47 | if [ -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 | |||
66 | fi | ||
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 | |||
7 | echo "===> Removing Ansible..." | ||
8 | pip uninstall -y ansible | ||
9 | |||
10 | echo "===> Removing PIP packages..." | ||
11 | cat ___PIP_UNINSTALL_LIST | \ | ||
12 | while read ITEM; do | ||
13 | pip uninstall -y $ITEM | ||
14 | done | ||
15 | |||
16 | echo "===> Removing APK packages..." | ||
17 | cat ___APK_UNINSTALL_LIST | \ | ||
18 | while read ITEM; do | ||
19 | apk del $ITEM | ||
20 | done | ||
21 | |||
22 | |||
23 | echo "===> Cleaning up package list..." | ||
24 | rm -rf /var/lib/python2.7 /usr/lib/python2.7 | ||
25 | rm -rf /etc/ansible /root/.ansible /root/.cache /root/.ash_history | ||
26 | rm -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 | ||
6 | FROM ansible_mini_apline3 | ||
7 | |||
8 | MAINTAINER William Yeh <william.pjyeh@gmail.com> | ||
9 | |||
10 | #ENV APK_LIST apk-list | ||
11 | #ENV PIP_LIST pip-list | ||
12 | |||
13 | ENTRYPOINT ["/usr/sbin/nginx"] | ||
14 | #CMD ["-g", "daemon off;"] | ||
15 | CMD ["-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 | ||