]> git.immae.eu Git - github/fretlink/docker-ansible.git/commitdiff
Add: new `mini` series for building minimal images from playbooks.
authorWilliam Yeh <william.pjyeh@gmail.com>
Mon, 30 May 2016 03:46:11 +0000 (11:46 +0800)
committerWilliam Yeh <william.pjyeh@gmail.com>
Mon, 30 May 2016 03:46:11 +0000 (11:46 +0800)
12 files changed:
.travis.yml
README.md
circle.yml
mini-alpine3/Dockerfile [new file with mode: 0644]
mini-alpine3/ansible-playbook-wrapper [new file with mode: 0755]
mini-alpine3/apk-list [new file with mode: 0644]
mini-alpine3/install-ansible.sh [new file with mode: 0755]
mini-alpine3/pip-list [new file with mode: 0644]
mini-alpine3/prepare-pkg-list.sh [new file with mode: 0755]
mini-alpine3/uninstall-ansible.sh [new file with mode: 0755]
mini-test/Dockerfile.alpine3 [new file with mode: 0644]
mini-test/playbook.yml [new file with mode: 0644]

index 4e5dfcb4bc2eaef7e92bd858b4b4c1bf1877cf63..ea6cc78064639efdb6cf530d2d1f42a96087d797 100644 (file)
@@ -58,6 +58,11 @@ before_install:
     - docker build  -t ansible_master_centos7_onbuild  master-centos7-onbuild
     - docker build  -t ansible_master_centos6_onbuild  master-centos6-onbuild
 
+
+    - docker build  -t ansible_mini_apline3    mini-alpine3
+    - docker build  -t nginx_apline3   -f mini-test/Dockerfile.alpine3   mini-test
+
+
 script:
     - docker run -i ansible_xenial           > result-ubuntu16.04
     - docker run -i ansible_trusty           > result-ubuntu14.04
@@ -109,6 +114,8 @@ script:
     - docker run -i ansible_master_centos6_onbuild  > result-master-centos6-onbuild
 
 
+    - docker run -i nginx_apline3  2> result-nginx-alpine3
+
 
     - echo "==> Validating the test results..."
     - sh -c "[ -s result-ubuntu16.04         ]"
@@ -157,3 +164,5 @@ script:
     - sh -c "[ -s result-master-debian7-onbuild     ]"
     - sh -c "[ -s result-master-centos7-onbuild     ]"
     - sh -c "[ -s result-master-centos6-onbuild     ]"
+
+    - sh -c "[ -s result-nginx-alpine3     ]"
index f0baebb74bae66a400e6977e20a1c7d84f04a7e3..8abe0cc03cf80ffc03f94fcf77275a57ab92eeb8 100644 (file)
--- a/README.md
+++ b/README.md
@@ -18,11 +18,12 @@ These are Docker images for [Ansible](https://github.com/ansible/ansible) softwa
 
 - OS: Debian (jessie, wheezy), Ubuntu (xenial, trusty, precise), CentOS (7, 6), Alpine (3).
 
-- Ansible: three version series -
+- Ansible: four series -
 
   1. the most recent *stable* version;
   2. old 1.9 version;
-  3. the *experimental* version.
+  3. the *experimental* version;
+  4. for building *minimal* images from playbooks; i.e., the Ansible body will be removed when mission completed.
 
 
 ## Images and tags
@@ -96,6 +97,13 @@ These are Docker images for [Ansible](https://github.com/ansible/ansible) softwa
   - `williamyeh/ansible:master-centos6-onbuild`
 
 
+### Minimal series (the Ansible body will be removed when mission completed):
+
+- Onbuild series:
+
+  - `williamyeh/ansible:mini-alpine3`
+
+
 
 ## For the impatient
 
index 60cbe2880c140586363993863d915439f6b7726b..9fc121f3dc736f054a627ff45b12dc9f9335b187 100644 (file)
@@ -59,6 +59,11 @@ dependencies:
     - docker build  -t ansible_master_centos7_onbuild  master-centos7-onbuild
     - docker build  -t ansible_master_centos6_onbuild  master-centos6-onbuild
 
+
+    - docker build  -t ansible_mini_apline3    mini-alpine3
+    - docker build  -t nginx_apline3   -f mini-test/Dockerfile.alpine3   mini-test
+
+
 test:
   override:
     - docker run -i ansible_xenial           > result-ubuntu16.04
@@ -111,6 +116,8 @@ test:
     - docker run -i ansible_master_centos6_onbuild  > result-master-centos6-onbuild
 
 
+    - docker run -i nginx_apline3  2> result-nginx-alpine3
+
 
     - echo "==> Validating the test results..."
     - sh -c "[ -s result-ubuntu16.04         ]"
@@ -159,3 +166,5 @@ test:
     - sh -c "[ -s result-master-debian7-onbuild     ]"
     - sh -c "[ -s result-master-centos7-onbuild     ]"
     - sh -c "[ -s result-master-centos6-onbuild     ]"
+
+    - sh -c "[ -s result-nginx-alpine3     ]"
diff --git a/mini-alpine3/Dockerfile b/mini-alpine3/Dockerfile
new file mode 100644 (file)
index 0000000..2287deb
--- /dev/null
@@ -0,0 +1,28 @@
+# Dockerfile for building Alpine-based image, via Ansible playbooks.
+#
+# @see https://github.com/gliderlabs/docker-alpine/blob/master/docs/usage.md
+#
+# Version  1.0
+#
+
+
+# pull base image
+FROM alpine:3.3
+
+MAINTAINER William Yeh <william.pjyeh@gmail.com>
+
+#ENV APK_LIST  apk-list
+#ENV PIP_LIST  pip-list
+
+
+COPY  .  /tmp
+
+ONBUILD COPY . /tmp
+ONBUILD RUN \
+    cd /tmp                     && \
+    ./prepare-pkg-list.sh       && \
+    ./install-ansible.sh        && \
+    ./ansible-playbook-wrapper  && \
+    ./uninstall-ansible.sh      && \
+    cd /                        && \
+    rm -rf /tmp/*
diff --git a/mini-alpine3/ansible-playbook-wrapper b/mini-alpine3/ansible-playbook-wrapper
new file mode 100755 (executable)
index 0000000..0ba45e6
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/sh
+#
+# Simple wrapper for executing ansible-galaxy and ansible-playbook
+# with local connection.
+#
+# USAGE:
+#    ansible-playbook-wrapper  [other ansible-playbook arguments]
+#
+# ENVIRONMENT VARIABLES:
+#
+#    - REQUIREMENTS: requirements filename; default = "requirements.yml"
+#    - PLAYBOOK:     playbook filename;     default = "playbook.yml"
+#    - INVENTORY:    inventory filename;    default = "/etc/ansible/hosts"
+#
+
+
+#
+# install Galaxy roles, if any
+#
+
+if [ -z "$REQUIREMENTS" ]; then
+    REQUIREMENTS=requirements.yml
+fi
+
+if [ -f "$REQUIREMENTS" ]; then
+    ansible-galaxy install -r $REQUIREMENTS
+fi
+
+
+#
+# execute playbook
+#
+
+if [ -z "$PLAYBOOK" ]; then
+    PLAYBOOK=playbook.yml
+fi
+
+
+if [ -z "$INVENTORY" ]; then
+    exec ansible-playbook        \
+       $PLAYBOOK                 \
+       --connection=local        \
+       "$@"
+else
+    exec ansible-playbook        \
+       -i $INVENTORY  $PLAYBOOK  \
+       --connection=local        \
+       "$@"
+fi
diff --git a/mini-alpine3/apk-list b/mini-alpine3/apk-list
new file mode 100644 (file)
index 0000000..eec27a4
--- /dev/null
@@ -0,0 +1,14 @@
+#
+# packages to be installed via APK;
+# lines beginning with "! " (an exclamation mark, followed by a space) will *not* be *uninstalled* afterwards.
+#
+
+
+# ssl
+openssl ca-certificates
+
+# python-runtime
+python py-pip
+
+# build-dependencies
+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 (executable)
index 0000000..98dede0
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# Simple wrapper for installing ansible
+#
+
+
+echo "===> Adding prerequisites..."
+
+cat ___APK_INSTALL_LIST  | \
+    while read ITEM; do
+        apk --update add $ITEM
+    done
+
+cat ___PIP_INSTALL_LIST  | \
+    while read ITEM; do
+        pip install --upgrade $ITEM
+    done
+
+
+echo "===> Installing Ansible..."
+pip install ansible
+
+
+echo "===> Adding hosts for convenience..."  && \
+mkdir -p /etc/ansible                        && \
+echo 'localhost' > /etc/ansible/hosts
diff --git a/mini-alpine3/pip-list b/mini-alpine3/pip-list
new file mode 100644 (file)
index 0000000..0df21dd
--- /dev/null
@@ -0,0 +1,11 @@
+#
+# packages to be installed via PIP;
+# lines beginning with "! " (an exclamation mark, followed by a space) will *not* be *uninstalled* afterwards.
+#
+
+
+# pip itself
+pip
+
+# for ansible
+cffi
diff --git a/mini-alpine3/prepare-pkg-list.sh b/mini-alpine3/prepare-pkg-list.sh
new file mode 100755 (executable)
index 0000000..67c720d
--- /dev/null
@@ -0,0 +1,68 @@
+#!/bin/sh
+#
+# Prepare the list of packages to be installed/uninstalled.
+#
+# ENVIRONMENT VARIABLES:
+#
+#    - APK_LIST: APK package list;  default = "apk-list"
+#    - PIP_LIST: PIP package list;  default = "pip-list"
+#
+
+echo "===> Preparing APK package list..."
+
+if [ -z "$APK_LIST" ]; then
+    APK_LIST=apk-list
+fi
+
+if [ -f "$APK_LIST" ]; then
+
+    awk '/^#/ {next}                                 \
+         { split($0,arrayA);                         \
+           for (i in arrayA) {                       \
+              if (arrayA[i] == "!") { continue; }    \
+              print arrayA[i]                        \
+           }                                         \
+         }'                                          \
+        $APK_LIST > ___APK_INSTALL_LIST
+
+    awk '/^(#|!)/ {next}                                          \
+         { split($0,arrayA); for (i in arrayA) print arrayA[i] }' \
+        $APK_LIST  |
+        awk '{ L[n++] = $0 }          \
+                END { while(n--)      \
+                      print L[n] }'   \
+            > ___APK_UNINSTALL_LIST
+
+fi
+#cat ___APK_INSTALL_LIST
+#cat ___APK_UNINSTALL_LIST
+
+
+echo "===> Preparing PIP package list..."
+
+if [ -z "$PIP_LIST" ]; then
+    PIP_LIST=pip-list
+fi
+
+if [ -f "$PIP_LIST" ]; then
+
+    awk '/^#/ {next}                                 \
+         { split($0,arrayA);                         \
+           for (i in arrayA) {                       \
+              if (arrayA[i] == "!") { continue; }    \
+              print arrayA[i]                        \
+           }                                         \
+         }'                                          \
+        $PIP_LIST > ___PIP_INSTALL_LIST
+
+    awk '/^(#|!)/ {next}                                          \
+         { split($0,arrayA); for (i in arrayA) print arrayA[i] }' \
+        $PIP_LIST  |
+        awk '{ L[n++] = $0 }          \
+                END { while(n--)      \
+                      print L[n] }'   \
+            > ___PIP_UNINSTALL_LIST
+
+fi
+#cat ___PIP_INSTALL_LIST
+#cat ___PIP_UNINSTALL_LIST
diff --git a/mini-alpine3/uninstall-ansible.sh b/mini-alpine3/uninstall-ansible.sh
new file mode 100755 (executable)
index 0000000..173c51d
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# Simple wrapper for uninstall ansible and related stuff.
+#
+
+
+echo "===> Removing Ansible..."
+pip uninstall -y ansible
+
+echo "===> Removing PIP packages..."
+cat ___PIP_UNINSTALL_LIST  | \
+    while read ITEM; do
+        pip uninstall -y $ITEM
+    done
+
+echo "===> Removing APK packages..."
+cat ___APK_UNINSTALL_LIST  | \
+    while read ITEM; do
+        apk del $ITEM
+    done
+
+
+echo "===> Cleaning up package list..."
+rm -rf /var/lib/python2.7  /usr/lib/python2.7
+rm -rf /etc/ansible  /root/.ansible  /root/.cache  /root/.ash_history
+rm -rf /var/cache/apk
diff --git a/mini-test/Dockerfile.alpine3 b/mini-test/Dockerfile.alpine3
new file mode 100644 (file)
index 0000000..78e7521
--- /dev/null
@@ -0,0 +1,15 @@
+# Dockerfile for building (near-)minimal nginx
+#
+
+
+# pull base image
+FROM ansible_mini_apline3
+
+MAINTAINER William Yeh <william.pjyeh@gmail.com>
+
+#ENV APK_LIST  apk-list
+#ENV PIP_LIST  pip-list
+
+ENTRYPOINT ["/usr/sbin/nginx"]
+#CMD ["-g", "daemon off;"]
+CMD ["-v"]
diff --git a/mini-test/playbook.yml b/mini-test/playbook.yml
new file mode 100644 (file)
index 0000000..898dfc5
--- /dev/null
@@ -0,0 +1,5 @@
+- hosts: all
+  become: True
+  tasks:
+    - name: install nginx
+      apk: name=nginx  state=present