From 8d33f29880bfb2089bf2ec94396d0f4622d310df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Wed, 2 Dec 2015 15:58:18 +0000 Subject: [PATCH] new feature: bootstrap-to-docker.sh --- scripts/bootstrap-to-docker.sh | 59 ++++++++++++++++++++++++++++++++++ scripts/makefile.am | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100755 scripts/bootstrap-to-docker.sh diff --git a/scripts/bootstrap-to-docker.sh b/scripts/bootstrap-to-docker.sh new file mode 100755 index 0000000..b2085ff --- /dev/null +++ b/scripts/bootstrap-to-docker.sh @@ -0,0 +1,59 @@ +#!/bin/bash -e + +# pass your docker hub login name as $1, defaults to your user name +# you should have a repositories named ubuntu and debian +# if you have your own repository, you can also prepend it: +# my.repo.url:5000/myname the script will then append ubuntu or debian +# e.g. to my.repo.url:5000/myname/ubuntu:trusty-amd64 +# please login to docker before you start this script +docker_user=${1:-${docker_user:-$(id -un)}} + +if test -f /etc/setup-debootstrap.conf; then + . /etc/setup-debootstrap.conf +fi + +archs=${archs:-"i386 amd64"} + +ubuntu=${ubuntu:-"wily vivid trusty precise"} +debian=${debian:-"jessie wheezy squeeze sid"} +distros="${ubuntu} ${debian}" +tmpdir=${tmpdir:-"/var/tmp"} +packages=(${packages:-"python-software-properties|software-properties-common" "apt-transport-https dpkg-dev lsb-release"}) + +for arch in ${archs}; do + for distro in ${distros}; do + if test "${ubuntu//${distro}/}" != "${ubuntu}"; then + type="ubuntu" + else + type="debian" + fi + echo "******** process $type $distro $arch ********" 1>&2 + if test -d "${tmpdir}/${distro}-${arch}"; then + echo " ++++ already exists ${tmpdir}/${distro}-${arch}" 1>&2 + else + echo " ---- install ${tmpdir}/${distro}-${arch}" 1>&2 + sudo debootstrap --arch="$arch" "$distro" "${tmpdir}/${distro}-${arch}" + fi + echo " ---- upgrade ${tmpdir}/${distro}-${arch}" 1>&2 + sudo chroot "${tmpdir}/${distro}-${arch}" apt-get update + sudo chroot "${tmpdir}/${distro}-${arch}" apt-get -y upgrade + sudo chroot "${tmpdir}/${distro}-${arch}" apt-get -y dist-upgrade + for package in "${packages[@]}"; do + echo " ---- install ${package//|/ or } to ${tmpdir}/${distro}-${arch}" 1>&2 + IFS='|' read -r -a pkgs <<< "$package" + success=0 + for pkg in "${pkgs[@]}"; do + if sudo chroot "${tmpdir}/${distro}-${arch}" apt-get install -y ${pkg}; then + success=1; + break; + fi + done + test $success -eq 1 + done + echo " ---- import ${tmpdir}/${distro}-${arch} to ${docker_user}/${type}:${distro}-${arch}" 1>&2 + cd "${tmpdir}/${distro}-${arch}" + sudo tar c . | docker import - "${docker_user}/${type}:${distro}-${arch}" + echo " ---- push ${tmpdir}/${distro}-${arch} to ${docker_user}/${type}:${distro}-${arch}" 1>&2 + docker push "${docker_user}/${type}:${distro}-${arch}" + done +done diff --git a/scripts/makefile.am b/scripts/makefile.am index 970b788..fae68d7 100644 --- a/scripts/makefile.am +++ b/scripts/makefile.am @@ -3,7 +3,7 @@ ## 1 2 3 4 5 6 7 8 ## 45678901234567890123456789012345678901234567890123456789012345678901234567890 -dist_bin_SCRIPTS = setup-debootstrap.sh +dist_bin_SCRIPTS = setup-debootstrap.sh bootstrap-to-docker.sh MAINTAINERCLEANFILES = makefile.in