-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path3_chunk.sh
executable file
·147 lines (129 loc) · 3.6 KB
/
3_chunk.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env bash
if [ $(id -u) -ne 0 ]; then
echo "Run as superuser"
exit 1
fi
if [ -z "$OUT_NAME" ]; then
echo "OUT_NAME is empty"
exit 1
fi
if [ -z "$OUT_REF" ]; then
echo "OUT_REF is empty"
exit 1
fi
set -e
# This file creates a container based on the ostree repository
# with tag $OUT_TAG
# MAX_LAYERS=${MAX_LAYERS:=40}
OUT_TAG=${OUT_TAG:=master}
CONTENT_META=${CONTENT_META:="$OUT_NAME.contentmeta.json"}
REPO=${REPO:=./repo}
PREV_NAME=${PREV_NAME:=previous}
PREV_MANIFEST=${PREV_MANIFEST:=./${PREV_NAME}.manifest.json}
if [ -n "$PREV_REF" ]; then
echo "PREV_REF is set, downloading manifest"
for i in $(seq 1 5); do
skopeo inspect docker://${PREV_REF} > $PREV_MANIFEST && break
echo "Failed to download previous manifest, retrying in 3 seconds"
sleep 3
done
if [ ! -f "$PREV_MANIFEST" ]; then
echo "############################################"
echo "ERROR: Failed to download previous manifest"
if [ -n "$PREV_REF_FAIL" ]; then
echo "Failing build due to PREV_REF_FAIL being set."
exit 1
else
echo "Continuing build without previous manifest"
fi
fi
fi
# Try to use venv if it exists for
# debug builds
if [[ -f venv/bin/rechunk ]]; then
RECHUNK=${RECHUNK:=venv/bin/rechunk}
else
RECHUNK=rechunk
fi
PREV_ARG=()
if [ -f "$PREV_MANIFEST" ]; then
PREV_ARG+=("--previous-manifest" "$PREV_MANIFEST")
fi
if [ -n "$MAX_LAYERS" ]; then
PREV_ARG+=("--max-layers" "$MAX_LAYERS")
fi
if [ -n "$PREFILL_RATIO" ]; then
PREV_ARG+=("--prefill-ratio" "$PREFILL_RATIO")
fi
if [ -n "$VERSION" ]; then
PREV_ARG+=("--version" "$VERSION")
fi
if [ -n "$VERSION_FN" ]; then
PREV_ARG+=("--version-fn" "$VERSION_FN")
fi
if [ -n "$PRETTY" ]; then
PREV_ARG+=("--pretty" "$PRETTY")
fi
if [ -n "$CHANGELOG" ]; then
PREV_ARG+=("--changelog" "$CHANGELOG")
fi
if [ -n "$GIT_DIR" ]; then
PREV_ARG+=("--git-dir" "$GIT_DIR")
fi
if [ -n "$REVISION" ]; then
PREV_ARG+=("--revision" "$REVISION")
fi
if [ -n "$CLEAR_PLAN" ]; then
PREV_ARG+=("--clear-plan")
fi
if [ -f "/workspace/_meta_in.yml" ]; then
PREV_ARG+=("--meta" "/workspace/_meta_in.yml")
fi
ARG_ARR=()
if [ -n "$LABELS" ]; then
IFS=$'\n'
for label in $LABELS; do
if [ -z "$label" ]; then
continue
fi
ARG_ARR+=("--label" "$label")
done
unset IFS
fi
if [ -n "$FORMATTERS" ]; then
IFS=$'\n'
for form in $FORMATTERS; do
if [ -z "$form" ]; then
continue
fi
ARG_ARR+=("--formatter" "$form")
done
unset IFS
fi
if [ -n "$DESCRIPTION" ]; then
echo "Writing description to 'org.opencontainers.image.description'"
ARG_ARR+=("--label" "org.opencontainers.image.description=$DESCRIPTION")
fi
echo Executing command:
echo $RECHUNK -r "$REPO" -b "$OUT_TAG" -c "$CONTENT_META" \
--changelog-fn "${OUT_NAME}.changelog.txt" \
"${PREV_ARG[@]}" "${ARG_ARR[@]}"
$RECHUNK -r "$REPO" -b "$OUT_TAG" -c "$CONTENT_META" \
--changelog-fn "${OUT_NAME}.changelog.txt" \
"${PREV_ARG[@]}" "${ARG_ARR[@]}"
PREV_ARG=""
if [ -n "$SKIP_COMPRESSION" ]; then
echo Warning! Skipping compression
PREV_ARG="$PREV_ARG --compression-fast"
fi
echo Creating archive with ref ${OUT_REF}
ostree-ext-cli \
container encapsulate \
--repo "${REPO}" "${OUT_TAG}" \
--contentmeta "${CONTENT_META}" \
${PREV_ARG} "${OUT_REF}"
echo Created archive with ref ${OUT_REF}
echo Writing manifest to ./$OUT_NAME.manifest.json
skopeo inspect ${OUT_REF} > ${OUT_NAME}.manifest.json
# Reset perms to make the files usable
chmod 666 -R ${OUT_NAME}*