github.com/hms58/moby@v1.13.1/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] [-c additional repository]\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 $MAINREPO/$ARCH/APKINDEX.tar.gz | tar -Oxz | 23 grep --text '^P:apk-tools-static$' -A1 | tail -n1 | cut -d: -f2 24 } 25 26 getapk() { 27 curl -sSL $MAINREPO/$ARCH/apk-tools-static-$(apkv).apk | 28 tar -xz -C $TMP sbin/apk.static 29 } 30 31 mkbase() { 32 $TMP/sbin/apk.static --repository $MAINREPO --update-cache --allow-untrusted \ 33 --root $ROOTFS --initdb add alpine-base 34 } 35 36 conf() { 37 printf '%s\n' $MAINREPO > $ROOTFS/etc/apk/repositories 38 printf '%s\n' $ADDITIONALREPO >> $ROOTFS/etc/apk/repositories 39 } 40 41 pack() { 42 local id 43 id=$(tar --numeric-owner -C $ROOTFS -c . | docker import - alpine:$REL) 44 45 docker tag $id alpine:latest 46 docker run -i -t --rm alpine printf 'alpine:%s with id=%s created!\n' $REL $id 47 } 48 49 save() { 50 [ $SAVE -eq 1 ] || return 51 52 tar --numeric-owner -C $ROOTFS -c . | xz > rootfs.tar.xz 53 } 54 55 while getopts "hr:m:s" opt; do 56 case $opt in 57 r) 58 REL=$OPTARG 59 ;; 60 m) 61 MIRROR=$OPTARG 62 ;; 63 s) 64 SAVE=1 65 ;; 66 c) 67 ADDITIONALREPO=community 68 ;; 69 *) 70 usage 71 ;; 72 esac 73 done 74 75 REL=${REL:-edge} 76 MIRROR=${MIRROR:-http://nl.alpinelinux.org/alpine} 77 SAVE=${SAVE:-0} 78 MAINREPO=$MIRROR/$REL/main 79 ADDITIONALREPO=$MIRROR/$REL/community 80 ARCH=${ARCH:-$(uname -m)} 81 82 tmp 83 getapk 84 mkbase 85 conf 86 pack 87 save