-
Notifications
You must be signed in to change notification settings - Fork 22
/
update.sh
executable file
·92 lines (74 loc) · 2.42 KB
/
update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash -e
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
while getopts "a:v:q:u:d:t:l:" opt; do
case "$opt" in
a) ARCH=$OPTARG
;;
v) VERSION=$OPTARG
;;
q) QEMU_ARCH=$OPTARG
;;
u) QEMU_VER=$OPTARG
;;
d) DOCKER_REPO=$OPTARG
;;
t) TAG_ARCH=$OPTARG
;;
l) LATEST_VERSION=$OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
MIRROR=${MIRROR:-http://dl-cdn.alpinelinux.org/alpine}
REPO=$MIRROR/$VERSION/main
COMMUNITYREPO=$MIRROR/$VERSION/community
TMP=tmp
ROOTFS=rootfs
mkdir -p $TMP $ROOTFS/usr/bin
# download apk.static
if [ ! -f $TMP/sbin/apk.static ]; then
apkv=$(curl -sSL $REPO/$ARCH/APKINDEX.tar.gz | tar -Oxz | strings |
grep '^P:apk-tools-static$' -A1 | tail -n1 | cut -d: -f2)
curl -sSL $REPO/$ARCH/apk-tools-static-${apkv}.apk | tar -xz -C $TMP sbin/apk.static
fi
# FIXME: register binfmt
# install qemu-user-static
if [ -n "${QEMU_ARCH}" ]; then
if [ ! -f x86_64_qemu-${QEMU_ARCH}-static.tar.gz ]; then
wget -N https://github.com/multiarch/qemu-user-static/releases/download/${QEMU_VER}/x86_64_qemu-${QEMU_ARCH}-static.tar.gz
fi
tar -xvf x86_64_qemu-${QEMU_ARCH}-static.tar.gz -C $ROOTFS/usr/bin/
fi
# create rootfs
$TMP/sbin/apk.static --repository $REPO --update-cache --allow-untrusted \
--root $ROOTFS --initdb add alpine-base --verbose
# alter rootfs
printf '%s\n' $REPO > $ROOTFS/etc/apk/repositories
printf '%s\n' $COMMUNITYREPO >> $ROOTFS/etc/apk/repositories
# create tarball of rootfs
if [ ! -f rootfs.tar.xz ]; then
tar --numeric-owner -C $ROOTFS -c . | xz > rootfs.tar.xz
fi
# clean rootfs
rm -f $ROOTFS/usr/bin/qemu-*-static
# create Dockerfile
cat > Dockerfile <<EOF
FROM scratch
ADD rootfs.tar.xz /
ENV ARCH=${ARCH} ALPINE_REL=${VERSION} DOCKER_REPO=${DOCKER_REPO} ALPINE_MIRROR=${MIRROR}
EOF
# add qemu-user-static binary
if [ -n "${QEMU_ARCH}" ]; then
cat >> Dockerfile <<EOF
# Add qemu-user-static binary for amd64 builders
ADD x86_64_qemu-${QEMU_ARCH}-static.tar.gz /usr/bin/
EOF
fi
# build
docker build -t ${DOCKER_REPO}:${TAG_ARCH}-${VERSION} .
if [ "$VERSION" == "$LATEST_VERSION" ]; then
docker tag ${DOCKER_REPO}:${TAG_ARCH}-${VERSION} ${DOCKER_REPO}:${TAG_ARCH}-latest-stable
fi
docker run --rm ${DOCKER_REPO}:${TAG_ARCH}-${VERSION} /bin/sh -ec "echo Hello from Alpine !; set -x; uname -a; cat /etc/alpine-release"