From 042ddec8383b0755e60bb01dc93ae3378374b637 Mon Sep 17 00:00:00 2001 From: William Yeh Date: Thu, 2 Jun 2016 16:07:46 +0800 Subject: Add: `mini-debian8` tag. --- mini-debian8/Dockerfile | 27 +++++++++++++++++++ mini-debian8/ansible-playbook-wrapper | 49 +++++++++++++++++++++++++++++++++++ mini-debian8/apt-list | 18 +++++++++++++ mini-debian8/install-ansible.sh | 31 ++++++++++++++++++++++ mini-debian8/prepare-pkg-list.sh | 37 ++++++++++++++++++++++++++ mini-debian8/uninstall-ansible.sh | 21 +++++++++++++++ 6 files changed, 183 insertions(+) create mode 100644 mini-debian8/Dockerfile create mode 100755 mini-debian8/ansible-playbook-wrapper create mode 100644 mini-debian8/apt-list create mode 100755 mini-debian8/install-ansible.sh create mode 100755 mini-debian8/prepare-pkg-list.sh create mode 100755 mini-debian8/uninstall-ansible.sh (limited to 'mini-debian8') diff --git a/mini-debian8/Dockerfile b/mini-debian8/Dockerfile new file mode 100644 index 0000000..d45d4e6 --- /dev/null +++ b/mini-debian8/Dockerfile @@ -0,0 +1,27 @@ +# Dockerfile for building Debian-based image, via Ansible playbooks. +# +# @see http://docs.ansible.com/ansible/intro_installation.html#running-from-source +# +# Version 1.0 +# + + +# pull base image +FROM debian:8 + +MAINTAINER William Yeh + +#ENV APT_LIST apt-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/* \ No newline at end of file diff --git a/mini-debian8/ansible-playbook-wrapper b/mini-debian8/ansible-playbook-wrapper new file mode 100755 index 0000000..0ba45e6 --- /dev/null +++ b/mini-debian8/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-debian8/apt-list b/mini-debian8/apt-list new file mode 100644 index 0000000..635e7d5 --- /dev/null +++ b/mini-debian8/apt-list @@ -0,0 +1,18 @@ +# +# packages to be installed via APT; +# lines beginning with "! " (an exclamation mark, followed by a space) will *not* be *uninstalled* afterwards. +# + + +# common +#####sudo curl gcc + +# ssl +#####openssl ca-certificates + +# python-runtime +python +#####python-pip python-yaml + +# build-dependencies +#####python-dev libffi-dev libssl-dev \ No newline at end of file diff --git a/mini-debian8/install-ansible.sh b/mini-debian8/install-ansible.sh new file mode 100755 index 0000000..6ddf0cb --- /dev/null +++ b/mini-debian8/install-ansible.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# +# Simple wrapper for installing ansible +# + + +echo "===> Adding backports..." + +mkdir -p /etc/apt/sources.list.d/ +echo "deb http://ftp.debian.org/debian jessie-backports main" | tee -a /etc/apt/sources.list.d/jessie-backports.list + + + +echo "===> Adding prerequisites..." + +apt-get update -y +cat ___APT_INSTALL_LIST | \ + while read ITEM; do + apt-get install -y $ITEM + done + + + +echo "===> Installing Ansible..." +apt-get -t jessie-backports install -y ansible + + + +echo "===> Adding hosts for convenience..." && \ +mkdir -p /etc/ansible && \ +echo 'localhost' > /etc/ansible/hosts diff --git a/mini-debian8/prepare-pkg-list.sh b/mini-debian8/prepare-pkg-list.sh new file mode 100755 index 0000000..ce2195d --- /dev/null +++ b/mini-debian8/prepare-pkg-list.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# +# Prepare the list of packages to be installed/uninstalled. +# +# ENVIRONMENT VARIABLES: +# +# - APT_LIST: APT package list; default = "apt-list" +# + +echo "===> Preparing APT package list..." + +if [ -z "$APT_LIST" ]; then + APT_LIST=apt-list +fi + +if [ -f "$APT_LIST" ]; then + + awk '/^#/ {next} \ + { split($0,arrayA); \ + for (i in arrayA) { \ + if (arrayA[i] == "!") { continue; } \ + print arrayA[i] \ + } \ + }' \ + $APT_LIST > ___APT_INSTALL_LIST + + awk '/^(#|!)/ {next} \ + { split($0,arrayA); for (i in arrayA) print arrayA[i] }' \ + $APT_LIST | + awk '{ L[n++] = $0 } \ + END { while(n--) \ + print L[n] }' \ + > ___APT_UNINSTALL_LIST + +fi +#cat ___APT_INSTALL_LIST +#cat ___APT_UNINSTALL_LIST diff --git a/mini-debian8/uninstall-ansible.sh b/mini-debian8/uninstall-ansible.sh new file mode 100755 index 0000000..3573413 --- /dev/null +++ b/mini-debian8/uninstall-ansible.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# +# Simple wrapper for uninstall ansible and related stuff. +# + + +echo "===> Removing Ansible..." +apt-get -f -y --auto-remove remove ansible + +echo "===> Removing APT packages..." +cat ___APT_UNINSTALL_LIST | \ + while read ITEM; do + apt-get -f -y --auto-remove remove $ITEM + done +apt-get clean + + +echo "===> Cleaning up package list..." +rm -rf /etc/python /etc/python2.7 +rm -rf /etc/ansible /root/.ansible /root/.cache +rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d /var/cache/* /var/log/* -- cgit v1.2.3