Skip to content

Commit 8363525

Browse files
committed
Makefile: add lock-images to lock Clear Linux version
Signed-off-by: Mikko Ylinen <mikko.ylinen@intel.com>
1 parent d06f986 commit 8363525

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,8 @@ $(demos):
6060

6161
demos: $(demos)
6262

63+
lock-images:
64+
@scripts/update-clear-linux-base.sh clearlinux/golang:latest $(shell ls build/docker/*.Dockerfile)
65+
@scripts/update-clear-linux-base.sh clearlinux:latest $(shell find demo -name Dockerfile)
6366

64-
.PHONY: all format vet cyclomatic-check test lint build images $(cmds) $(images)
67+
.PHONY: all format vet cyclomatic-check test lint build images $(cmds) $(images) lock-images

scripts/update-clear-linux-base.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/sh
2+
#
3+
# Copyright 2019 Intel Corporation.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
# Invoke this script on a system that has Docker installed
8+
# such that it can be used by the current user. Then the script
9+
# will bump up the CLEAR_LINUX_BASE and CLEAR_LINUX_VERSION
10+
# parameters in the Dockerfiles such that they pick the
11+
# current version of Clear Linux.
12+
#
13+
# The script is adapted from https://github.com/intel/pmem-csi/
14+
15+
die () {
16+
echo "ERROR: $@"
17+
exit 1
18+
}
19+
20+
IMG=$1
21+
shift
22+
DOCKERFILES=$@
23+
24+
docker image pull $IMG || die "pulling $IMG failed"
25+
base=$(docker inspect --format='{{index .RepoDigests 0}}' $IMG) || die "failed to inspect $IMG"
26+
echo "Base image: $base"
27+
28+
# We rely on swupd to determine what this particular image can be
29+
# updated to with "swupd update --version". This might not be the very latest
30+
# Clear Linux, for example when there has been a format bump and the
31+
# base image is still using the older format.
32+
output=$(docker run $base swupd check-update) # will return non-zero exit code if there is nothing to update
33+
# The expected output on failure is one of:
34+
# Current OS version: 30450
35+
# Latest server version: 30450
36+
# There are no updates available
37+
# or:
38+
# Current OS version: 29940
39+
# Latest server version: 29970
40+
# There is a new OS version available: 29970
41+
version=$(echo "$output" | grep "Latest server version" | tail -n 1 | sed -e 's/.*: *//')
42+
if [ ! "$version" ]; then
43+
die "failed to obtain information about available updates"
44+
fi
45+
echo "Update version: $version"
46+
47+
# Do a trial-run with these parameters.
48+
docker run "$base" swupd update --version=$version || die "failed to update"
49+
50+
# Now update the Dockerfile(s).
51+
sed -i -e 's;^\(ARG CLEAR_LINUX_BASE=\).*;\1'"$base"';' -e 's;^\(ARG CLEAR_LINUX_VERSION=\).*;\1"--version='"$version"'";' $DOCKERFILES || die "failed to patch Dockerfiles"
52+
53+
echo "Done."

0 commit comments

Comments
 (0)