forked from cgwalters/sync-fedora-ostree-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encap.sh
executable file
·65 lines (56 loc) · 1.7 KB
/
encap.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
#!/bin/bash
set -euo pipefail
ostreeref=$1
shift
image=$1
shift
runv () {
( set -x ; $@ )
}
cd $(mktemp -d -p /var/tmp)
if ! runv skopeo inspect -n docker://${image} > inspect.json; then
echo "Failed to invoke skopeo, assuming container does not exist"
fi
container_commit=
if test -s inspect.json; then
container_commit=$(jq -r '.Labels["ostree.commit"]' inspect.json)
fi
mkdir repo
ostree --repo=repo init --mode=bare-user
cat /etc/ostree/remotes.d/fedora.conf >> repo/config
runv ostree --repo=repo pull --commit-metadata-only fedora:$ostreeref
current_commit=$(ostree --repo=repo rev-parse fedora:$ostreeref)
echo "current ostree repo: $current_commit"
echo "current container image: $container_commit"
if test "$current_commit" == "$container_commit"; then
echo "Generated container image is up to date at commit $current_commit"
exit 0
fi
# If we have a previous build, re-initialize from the container to avoid
# lots of small object fetches
if test -s inspect.json; then
ostree container unencapsulate --repo=repo ostree-unverified-registry:${image}
fi
# Fedora infra (or cloudfront?) is giving us 503s, add some retries
for n in {0..3} max; do
if runv ostree --repo=repo pull fedora:$ostreeref; then
break
else
if test $n == max; then
exit 1
fi
fi
done
runv rpm-ostree compose container-encapsulate --format-version 1 \
--repo repo $current_commit oci:tmp
# Retry since github actions networking flakes sometimes
# TODO: add retries into skopeo, docker seems to do it
for n in {0..2} max; do
if runv skopeo copy oci:tmp docker://$image; then
break
else
if test $n == max; then
exit 1
fi
fi
done