Skip to content

Commit 2dedd46

Browse files
committed
Add support for reading and writing lockfiles
First, add `manifest-lock.json` to the list of magical files in the source config which we check for. Then, teach `fetch` and `build` to respect the lockfile by default, but add an `--update-lockfile` option to the former allow bumping the lockfile. Finally, always generate an output lockfile from the compose and put in the build dir as `manifest-lock.generated.json`. This is the first step towards actually being able to make use of lockfiles in the FCOS pipeline.
1 parent 3c22629 commit 2dedd46

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

src/cmd-build

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,23 @@ EOF
151151

152152
prepare_git_artifacts "${configdir_gitrepo}" "${PWD}/coreos-assembler-config.tar.gz" "${PWD}/coreos-assembler-config-git.json"
153153

154+
lock_arg=
155+
if [ -f "${manifest_lock}" ]; then
156+
lock_arg="--ex-lockfile=${manifest_lock}"
157+
echo "Building from lockfile ${manifest_lock}"
158+
sleep 1
159+
fi
160+
154161
# These need to be absolute paths right now for rpm-ostree
155162
composejson=${PWD}/tmp/compose.json
163+
# Put this under tmprepo so it gets automatically chown'ed if needed
164+
lockfile_out=${tmprepo}/tmp/manifest-lock.generated.json
156165
# --cache-only is here since `fetch` is a separate verb.
166+
# shellcheck disable=SC2086
157167
runcompose --cache-only ${FORCE} --add-metadata-from-json "${commitmeta_input_json}" \
158-
--write-composejson-to "${composejson}"
168+
--write-composejson-to "${composejson}" \
169+
--ex-write-lockfile-to "${lockfile_out}" \
170+
${lock_arg}
159171
# Very special handling for --write-composejson-to as rpm-ostree doesn't
160172
# write it if the commit didn't change.
161173
if [ -f "${changed_stamp}" ]; then
@@ -306,6 +318,9 @@ if [ -n "${ref_is_temp}" ]; then
306318
mv meta.json{.new,}
307319
fi
308320

321+
# Move lockfile into build dir
322+
mv "${lockfile_out}" .
323+
309324
# And add the commit metadata itself, which includes notably the rpmdb pkglist
310325
# in a format that'd be easy to generate diffs out of for higher level tools
311326
"${dn}"/commitmeta_to_json "${tmprepo}" "${commit}" > commitmeta.json

src/cmd-fetch

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ dn=$(dirname "$0")
88
print_help() {
99
cat 1>&2 <<'EOF'
1010
Usage: coreos-assembler fetch --help
11-
coreos-assembler fetch
11+
coreos-assembler fetch [--update-lockfile]
1212
1313
Fetch and import the latest packages.
1414
EOF
1515
}
1616

17+
UPDATE_LOCKFILE=
1718
rc=0
18-
options=$(getopt --options h --longoptions help -- "$@") || rc=$?
19+
options=$(getopt --options h --longoptions help,update-lockfile -- "$@") || rc=$?
1920
[ $rc -eq 0 ] || {
2021
print_help
2122
exit 1
@@ -27,6 +28,9 @@ while true; do
2728
print_help
2829
exit 0
2930
;;
31+
--update-lockfile)
32+
UPDATE_LOCKFILE=1
33+
;;
3034
--)
3135
shift
3236
break
@@ -46,4 +50,21 @@ if [ $# -ne 0 ]; then
4650
fi
4751

4852
prepare_build
49-
runcompose --download-only
53+
54+
lock_arg=
55+
if [ -n "${UPDATE_LOCKFILE}" ]; then
56+
# Put this under tmprepo so it gets automatically chown'ed if needed
57+
lock_arg="--ex-write-lockfile-to=${tmprepo}/tmp/manifest-lock.json"
58+
elif [ -f "${manifest_lock}" ]; then
59+
lock_arg="--ex-lockfile=${manifest_lock}"
60+
echo "Fetching RPMs from lockfile ${manifest_lock}"
61+
sleep 1
62+
fi
63+
64+
# shellcheck disable=SC2086
65+
runcompose --download-only ${lock_arg}
66+
67+
if [ -n "${UPDATE_LOCKFILE}" ]; then
68+
mv "${tmprepo}/tmp/manifest-lock.json" "${manifest_lock}"
69+
echo "Updated lockfile ${manifest_lock}"
70+
fi

src/cmdlib.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ prepare_build() {
166166
workdir="$(pwd)"
167167
configdir=${workdir}/src/config
168168
manifest=${configdir}/manifest.yaml
169-
export workdir configdir manifest
169+
manifest_lock=${configdir}/manifest-lock.json
170+
export workdir configdir manifest manifest_lock
170171

171172
if ! [ -f "${manifest}" ]; then
172173
fatal "Failed to find ${manifest}"

0 commit comments

Comments
 (0)