From f966242805e67f91bffdc5f9eb02096bb5e1f856 Mon Sep 17 00:00:00 2001 From: William Yeh Date: Mon, 30 May 2016 11:46:11 +0800 Subject: Add: new `mini` series for building minimal images from playbooks. --- mini-alpine3/Dockerfile | 28 +++++++++++++++ mini-alpine3/ansible-playbook-wrapper | 49 +++++++++++++++++++++++++ mini-alpine3/apk-list | 14 ++++++++ mini-alpine3/install-ansible.sh | 26 ++++++++++++++ mini-alpine3/pip-list | 11 ++++++ mini-alpine3/prepare-pkg-list.sh | 68 +++++++++++++++++++++++++++++++++++ mini-alpine3/uninstall-ansible.sh | 26 ++++++++++++++ 7 files changed, 222 insertions(+) create mode 100644 mini-alpine3/Dockerfile create mode 100755 mini-alpine3/ansible-playbook-wrapper create mode 100644 mini-alpine3/apk-list create mode 100755 mini-alpine3/install-ansible.sh create mode 100644 mini-alpine3/pip-list create mode 100755 mini-alpine3/prepare-pkg-list.sh create mode 100755 mini-alpine3/uninstall-ansible.sh (limited to 'mini-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 @@ +# 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 + +#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 index 0000000..0ba45e6 --- /dev/null +++ b/mini-alpine3/ansible-playbook-wrapper @@ -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 index 0000000..eec27a4 --- /dev/null +++ b/mini-alpine3/apk-list @@ -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 index 0000000..98dede0 --- /dev/null +++ b/mini-alpine3/install-ansible.sh @@ -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 index 0000000..0df21dd --- /dev/null +++ b/mini-alpine3/pip-list @@ -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 index 0000000..67c720d --- /dev/null +++ b/mini-alpine3/prepare-pkg-list.sh @@ -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 index 0000000..173c51d --- /dev/null +++ b/mini-alpine3/uninstall-ansible.sh @@ -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 -- cgit v1.2.3