github.com/fcwu/docker@v1.4.2-0.20150115145920-2a69ca89f0df/contrib/mkimage-alpine.sh (about) 1 #!/bin/sh 2 3 set -e 4 5 [ $(id -u) -eq 0 ] || { 6 printf >&2 '%s requires root\n' "$0" 7 exit 1 8 } 9 10 usage() { 11 printf >&2 '%s: [-r release] [-m mirror] [-s]\n' "$0" 12 exit 1 13 } 14 15 tmp() { 16 TMP=$(mktemp -d ${TMPDIR:-/var/tmp}/alpine-docker-XXXXXXXXXX) 17 ROOTFS=$(mktemp -d ${TMPDIR:-/var/tmp}/alpine-docker-rootfs-XXXXXXXXXX) 18 trap "rm -rf $TMP $ROOTFS" EXIT TERM INT 19 } 20 21 apkv() { 22 curl -sSL $REPO/$ARCH/APKINDEX.tar.gz | tar -Oxz | 23 grep '^P:apk-tools-static$' -A1 | tail -n1 | cut -d: -f2 24 } 25 26 getapk() { 27 curl -sSL $REPO/$ARCH/apk-tools-static-$(apkv).apk | 28 tar -xz -C $TMP sbin/apk.static 29 } 30 31 mkbase() { 32 $TMP/sbin/apk.static --repository $REPO --update-cache --allow-untrusted \ 33 --root $ROOTFS --initdb add alpine-base 34 } 35 36 conf() { 37 printf '%s\n' $REPO > $ROOTFS/etc/apk/repositories 38 } 39 40 pack() { 41 local id 42 id=$(tar --numeric-owner -C $ROOTFS -c . | docker import - alpine:$REL) 43 44 docker tag $id alpine:latest 45 docker run -i -t alpine printf 'alpine:%s with id=%s created!\n' $REL $id 46 } 47 48 save() { 49 [ $SAVE -eq 1 ] || return 50 51 tar --numeric-owner -C $ROOTFS -c . | xz > rootfs.tar.xz 52 } 53 54 while getopts "hr:m:s" opt; do 55 case $opt in 56 r) 57 REL=$OPTARG 58 ;; 59 m) 60 MIRROR=$OPTARG 61 ;; 62 s) 63 SAVE=1 64 ;; 65 *) 66 usage 67 ;; 68 esac 69 done 70 71 REL=${REL:-edge} 72 MIRROR=${MIRROR:-http://nl.alpinelinux.org/alpine} 73 SAVE=${SAVE:-0} 74 REPO=$MIRROR/$REL/main 75 ARCH=$(uname -m) 76 77 tmp 78 getapk 79 mkbase 80 conf 81 pack 82 save