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. --- .travis.yml | 10 ++++--- README.md | 1 + circle.yml | 10 ++++--- 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 +++++++++++++++ mini-test/Dockerfile.alpine3 | 2 +- mini-test/Dockerfile.debian8 | 14 ++++++++++ mini-test/playbook.yml | 19 +++++++++++--- 12 files changed, 229 insertions(+), 10 deletions(-) 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 create mode 100644 mini-test/Dockerfile.debian8 diff --git a/.travis.yml b/.travis.yml index ea6cc78..ac9983b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -59,8 +59,10 @@ before_install: - 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 + - docker build -t ansible_mini_alpine3 mini-alpine3 + - docker build -t ansible_mini_debian8 mini-debian8 + - docker build -t nginx_alpine3 -f mini-test/Dockerfile.alpine3 mini-test + - docker build -t nginx_debian8 -f mini-test/Dockerfile.debian8 mini-test script: @@ -114,7 +116,8 @@ script: - docker run -i ansible_master_centos6_onbuild > result-master-centos6-onbuild - - docker run -i nginx_apline3 2> result-nginx-alpine3 + - docker run -i nginx_alpine3 2> result-nginx-alpine3 + - docker run -i nginx_debian8 2> result-nginx-debian8 - echo "==> Validating the test results..." @@ -166,3 +169,4 @@ script: - sh -c "[ -s result-master-centos6-onbuild ]" - sh -c "[ -s result-nginx-alpine3 ]" + - sh -c "[ -s result-nginx-debian8 ]" diff --git a/README.md b/README.md index 8abe0cc..d982543 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ These are Docker images for [Ansible](https://github.com/ansible/ansible) softwa - Onbuild series: - `williamyeh/ansible:mini-alpine3` + - `williamyeh/ansible:mini-debian8` diff --git a/circle.yml b/circle.yml index 9fc121f..18e5253 100644 --- a/circle.yml +++ b/circle.yml @@ -60,8 +60,10 @@ dependencies: - 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 + - docker build -t ansible_mini_alpine3 mini-alpine3 + - docker build -t ansible_mini_debian8 mini-debian8 + - docker build -t nginx_alpine3 -f mini-test/Dockerfile.alpine3 mini-test + - docker build -t nginx_debian8 -f mini-test/Dockerfile.debian8 mini-test test: @@ -116,7 +118,8 @@ test: - docker run -i ansible_master_centos6_onbuild > result-master-centos6-onbuild - - docker run -i nginx_apline3 2> result-nginx-alpine3 + - docker run -i nginx_alpine3 2> result-nginx-alpine3 + - docker run -i nginx_debian8 2> result-nginx-debian8 - echo "==> Validating the test results..." @@ -168,3 +171,4 @@ test: - sh -c "[ -s result-master-centos6-onbuild ]" - sh -c "[ -s result-nginx-alpine3 ]" + - sh -c "[ -s result-nginx-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/* diff --git a/mini-test/Dockerfile.alpine3 b/mini-test/Dockerfile.alpine3 index 78e7521..a42fa33 100644 --- a/mini-test/Dockerfile.alpine3 +++ b/mini-test/Dockerfile.alpine3 @@ -3,7 +3,7 @@ # pull base image -FROM ansible_mini_apline3 +FROM ansible_mini_alpine3 MAINTAINER William Yeh diff --git a/mini-test/Dockerfile.debian8 b/mini-test/Dockerfile.debian8 new file mode 100644 index 0000000..f41cbbb --- /dev/null +++ b/mini-test/Dockerfile.debian8 @@ -0,0 +1,14 @@ +# Dockerfile for building (near-)minimal nginx under Debian8 +# + + +# pull base image +FROM ansible_mini_debian8 + +MAINTAINER William Yeh + +#ENV APK_LIST apk-list + +ENTRYPOINT ["/usr/sbin/nginx"] +#CMD ["-g", "daemon off;"] +CMD ["-v"] diff --git a/mini-test/playbook.yml b/mini-test/playbook.yml index 898dfc5..b8cccda 100644 --- a/mini-test/playbook.yml +++ b/mini-test/playbook.yml @@ -1,5 +1,18 @@ - hosts: all - become: True + become: true tasks: - - name: install nginx - apk: name=nginx state=present + - name: DEBUG + command: echo hello + + - name: install nginx for Alpine + apk: name=nginx state=present + when: ansible_distribution == "Alpine" + + - name: install nginx for Debian/Ubuntu + apt: name=nginx state=present + when: ansible_os_family == "Debian" + + +# Debian: +#rm -rf /etc/fonts /usr/share/fonts /usr/local/share/fonts /usr/share/X11 /usr/share/fontconfig /usr/share/doc +#rm -rf /etc/perl /usr/lib/x86_64-linux-gnu/perl -- cgit v1.2.3