-
Notifications
You must be signed in to change notification settings - Fork 2
/
update.sh
executable file
·122 lines (108 loc) · 3.71 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash -xe
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
while getopts "a:v:q:u:d:t:" 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
;;
esac
done
mysha256sum=sha256sum
if which gsha256sum &> /dev/null; then
mysha256sum=gsha256sum
fi
wget_common_opts="-t 3 -w 1 --retry-connrefused --no-dns-cache --retry-on-http-error=403"
wget_opts="${wget_common_opts} -N"
wget_spider_opts="${wget_common_opts} --spider"
function wget_and_sleep() {
wget ${@}
return_code=${?}
sleep 1
return ${return_code}
}
(
rootTar="Fedora-Container-Root-${VERSION}.${ARCH}.tar"
# Use a real server dl.fedoraproject.org
# instead of a balancing server download.fedoraproject.org
# to avoid redirected to an invalid mirror server that causes http status 404.
# baseUrl="https://download.fedoraproject.org/pub"
baseUrl="https://dl.fedoraproject.org/pub"
archiveBaseUrl="https://archives.fedoraproject.org/pub/archive"
if wget_and_sleep ${wget_spider_opts} "$baseUrl/fedora-secondary/releases/${VERSION}/Container/${ARCH}/images"; then
baseUrl+="/fedora-secondary/releases/${VERSION}/Container/${ARCH}/images"
elif wget_and_sleep ${wget_spider_opts} "$baseUrl/fedora/linux/releases/${VERSION}/Container/${ARCH}/images"; then
baseUrl+="/fedora/linux/releases/${VERSION}/Container/${ARCH}/images"
elif wget_and_sleep ${wget_spider_opts} "$archiveBaseUrl/fedora/linux/releases/${VERSION}/Container/${ARCH}/images"; then
baseUrl="${archiveBaseUrl}/fedora/linux/releases/${VERSION}/Container/${ARCH}/images"
else
echo >&2 "error: Unable to find correct base url"
exit 1
fi
for update in {0..15}; do
# 30-s390x only has the Minimal-Base image.
for base in Base Minimal-Base; do
if wget_and_sleep ${wget_spider_opts} "$baseUrl/Fedora-Container-${base}-${VERSION}-1.$update.${ARCH}.tar.xz"; then
fullTar="Fedora-Container-${base}-${VERSION}-1.$update.${ARCH}.tar.xz"
checksum="Fedora-Container-${VERSION}-1.$update-${ARCH}-CHECKSUM"
break 2
fi
done
done
if [ -z "$fullTar" ]; then
echo >&2 "error: Unable to find correct update"
exit 1
fi
mkdir -p ../.temp/$fullTar.temp
pushd ../.temp
wget_and_sleep ${wget_opts} "$baseUrl/$checksum" || true
wget_and_sleep ${wget_opts} "$baseUrl/$fullTar"
if [ -f $checksum ]; then
# Set ignore-missing to Ignore Fedora-Container-Minimal-Base-*.tar.gz
# in the checksum file.
if ! $mysha256sum --status -c --ignore-missing $checksum; then
echo >&2 "error: '$fullTar' has invalid SHA256"
exit 1
fi
fi
popd
tar -C ../.temp/$fullTar.temp -xf "../.temp/$fullTar"
mv -f ../.temp/$fullTar.temp/*/layer.tar $rootTar
rm -rf ../.temp/$fullTar.temp
cat > Dockerfile <<EOF
FROM scratch
ADD $rootTar /
ENV ARCH=${ARCH} FEDORA_SUITE=${VERSION} DOCKER_REPO=${DOCKER_REPO}
EOF
if [ -n "${QEMU_ARCH}" ]; then
if [ ! -f x86_64_qemu-${QEMU_ARCH}-static.tar.gz ]; then
wget_and_sleep ${wget_opts} https://github.com/multiarch/qemu-user-static/releases/download/${QEMU_VER}/x86_64_qemu-${QEMU_ARCH}-static.tar.gz
fi
cat >> Dockerfile <<EOF
# Add qemu-user-static binary for amd64 builders
ADD x86_64_qemu-${QEMU_ARCH}-static.tar.gz /usr/bin
EOF
fi
cat >> Dockerfile <<EOF
# overwrite this with 'CMD []' in a dependent Dockerfile
CMD ["/bin/bash"]
EOF
)
docker build -t "${DOCKER_REPO}:${VERSION}-${TAG_ARCH}" .
docker run --rm "${DOCKER_REPO}:${VERSION}-${TAG_ARCH}" /bin/bash -ec "
uname -a
echo
cat /etc/os-release 2>/dev/null
echo
cat /etc/redhat-release 2>/dev/null
true
"