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 /mini-alpine3 | |
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.
Diffstat (limited to 'mini-alpine3')
-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 |
7 files changed, 222 insertions, 0 deletions
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 | ||