Skip to content

Commit e231af1

Browse files
authored
Merge pull request #708 from AkihiroSuda/test-upgrade
CI: add upgrade test
2 parents d6c2258 + 3125937 commit e231af1

File tree

6 files changed

+166
-37
lines changed

6 files changed

+166
-37
lines changed

.github/workflows/test.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,35 @@ jobs:
140140
# GHA macOS is slow and flaky, so we only test a few YAMLS here.
141141
# Other yamls are tested on Linux instances of Cirrus.
142142

143+
upgrade:
144+
name: "Upgrade test"
145+
runs-on: macos-11
146+
timeout-minutes: 120
147+
strategy:
148+
matrix:
149+
oldver: ["v0.8.0"]
150+
steps:
151+
- uses: actions/setup-go@v2
152+
with:
153+
go-version: 1.17.x
154+
- uses: actions/checkout@v3
155+
with:
156+
fetch-depth: 0
157+
- name: Install test dependencies
158+
run: brew install qemu bash coreutils
159+
- name: Cache ~/Library/Caches/lima/download
160+
uses: actions/cache@v2
161+
with:
162+
path: ~/Library/Caches/lima/download
163+
key: ${{ runner.os }}-upgrade-${{ matrix.oldver }}
164+
- name: Test
165+
uses: nick-invision/retry@v2
166+
with:
167+
timeout_minutes: 30
168+
retry_on: error
169+
max_attempts: 3
170+
command: ./hack/test-upgrade.sh ${{ matrix.oldver }} ${{ github.sha }}
171+
143172
artifacts-darwin:
144173
name: Artifacts Darwin
145174
runs-on: macos-11

.shellcheckrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source-path=SCRIPTDIR

hack/common.inc.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# shellcheck shell=bash
2+
cleanup_cmd=""
3+
trap 'eval ${cleanup_cmd}' EXIT
4+
function defer {
5+
[ -n "${cleanup_cmd}" ] && cleanup_cmd="${cleanup_cmd}; "
6+
cleanup_cmd="${cleanup_cmd}$1"
7+
}
8+
9+
function INFO() {
10+
echo "TEST| [INFO] $*"
11+
}
12+
13+
function WARNING() {
14+
echo >&2 "TEST| [WARNING] $*"
15+
}
16+
17+
function ERROR() {
18+
echo >&2 "TEST| [ERROR] $*"
19+
}
20+
21+
if [[ ${BASH_VERSINFO:-0} -lt 4 ]]; then
22+
ERROR "Bash version is too old: ${BASH_VERSION}"
23+
exit 1
24+
fi

hack/test-example.sh

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,8 @@
22
set -eu -o pipefail
33

44
scriptdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5-
6-
cleanup_cmd=""
7-
trap 'eval ${cleanup_cmd}' EXIT
8-
function defer {
9-
[ -n "${cleanup_cmd}" ] && cleanup_cmd="${cleanup_cmd}; "
10-
cleanup_cmd="${cleanup_cmd}$1"
11-
}
12-
13-
function INFO() {
14-
echo "TEST| [INFO] $*"
15-
}
16-
17-
function WARNING() {
18-
echo >&2 "TEST| [WARNING] $*"
19-
}
20-
21-
function ERROR() {
22-
echo >&2 "TEST| [ERROR] $*"
23-
}
24-
25-
if [[ ${BASH_VERSINFO:-0} -lt 4 ]]; then
26-
ERROR "Bash version is too old: ${BASH_VERSION}"
27-
exit 1
28-
fi
5+
# shellcheck source=common.inc.sh
6+
source "${scriptdir}/common.inc.sh"
297

308
if [ "$#" -ne 1 ]; then
319
ERROR "Usage: $0 FILE.yaml"
@@ -153,19 +131,7 @@ if [[ -n ${CHECKS["systemd"]} ]]; then
153131
fi
154132

155133
if [[ -n ${CHECKS["mount-home"]} ]]; then
156-
hometmp="$HOME/lima-test-tmp"
157-
INFO "Testing home access (\"$hometmp\")"
158-
rm -rf "$hometmp"
159-
mkdir -p "$hometmp"
160-
defer "rm -rf \"$hometmp\""
161-
echo "random-content-${RANDOM}" >"$hometmp/random"
162-
expected="$(cat "$hometmp/random")"
163-
got="$(limactl shell "$NAME" cat "$hometmp/random")"
164-
INFO "$hometmp/random: expected=${expected}, got=${got}"
165-
if [ "$got" != "$expected" ]; then
166-
ERROR "Home directory is not shared?"
167-
exit 1
168-
fi
134+
"${scriptdir}"/test-mount-home.sh "$NAME"
169135
fi
170136

171137
# Use GHCR to avoid hitting Docker Hub rate limit

hack/test-mount-home.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
set -eu -o pipefail
3+
4+
scriptdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
# shellcheck source=common.inc.sh
6+
source "${scriptdir}/common.inc.sh"
7+
8+
if [ "$#" -ne 1 ]; then
9+
ERROR "Usage: $0 NAME"
10+
exit 1
11+
fi
12+
13+
NAME="$1"
14+
hometmp="$HOME/lima-test-tmp"
15+
INFO "Testing home access (\"$hometmp\")"
16+
rm -rf "$hometmp"
17+
mkdir -p "$hometmp"
18+
defer "rm -rf \"$hometmp\""
19+
echo "random-content-${RANDOM}" >"$hometmp/random"
20+
expected="$(cat "$hometmp/random")"
21+
got="$(limactl shell "$NAME" cat "$hometmp/random")"
22+
INFO "$hometmp/random: expected=${expected}, got=${got}"
23+
if [ "$got" != "$expected" ]; then
24+
ERROR "Home directory is not shared?"
25+
exit 1
26+
fi

hack/test-upgrade.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env bash
2+
set -eu -o pipefail
3+
4+
scriptdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
# shellcheck source=common.inc.sh
6+
source "${scriptdir}/common.inc.sh"
7+
cd "${scriptdir}/.."
8+
9+
if [ "$#" -ne 2 ]; then
10+
ERROR "Usage: $0 OLDVER NEWVER"
11+
exit 1
12+
fi
13+
14+
OLDVER="$1"
15+
NEWVER="$2"
16+
17+
PREFIX="/usr/local"
18+
function install_lima() {
19+
ver="$1"
20+
git checkout "${ver}"
21+
make clean
22+
make
23+
if [ -w "${PREFIX}/bin" ] && [ -w "${PREFIX}/share" ]; then
24+
make install
25+
else
26+
sudo make install
27+
fi
28+
}
29+
30+
function uninstall_lima() {
31+
files="${PREFIX}/bin/lima ${PREFIX}/bin/limactl ${PREFIX}/share/lima ${PREFIX}/share/doc/lima"
32+
if [ -w "${PREFIX}/bin" ] && [ -w "${PREFIX}/share" ]; then
33+
# shellcheck disable=SC2086
34+
rm -rf $files
35+
else
36+
# shellcheck disable=SC2086
37+
sudo rm -rf $files
38+
fi
39+
}
40+
41+
INFO "Uninstalling lima"
42+
uninstall_lima
43+
44+
INFO "Installing the old Lima ${OLDVER}"
45+
install_lima "${OLDVER}"
46+
47+
export LIMA_INSTANCE="test-upgrade"
48+
49+
INFO "Creating an instance \"${LIMA_INSTANCE}\" with the old Lima"
50+
defer "limactl delete -f \"${LIMA_INSTANCE}\""
51+
limactl start --tty=false "${LIMA_INSTANCE}"
52+
lima nerdctl info
53+
54+
image_name="lima-test-upgrade-containerd-${RANDOM}"
55+
image_context="${HOME}/${image_name}"
56+
INFO "Building containerd image \"${image_name}\" from \"${image_context}\""
57+
defer "rm -rf \"${image_context}\""
58+
mkdir -p "${image_context}"
59+
cat <<EOF >"${image_context}"/Dockerfile
60+
# Use GHCR to avoid hitting Docker Hub rate limit
61+
FROM ghcr.io/containerd/alpine:3.14.0
62+
CMD ["echo", "Built with Lima ${OLDVER}"]
63+
EOF
64+
lima nerdctl build -t "${image_name}" "${image_context}"
65+
lima nerdctl run --rm "${image_name}"
66+
67+
INFO "Stopping the instance"
68+
limactl stop "${LIMA_INSTANCE}"
69+
70+
INFO "=============================================================================="
71+
72+
INFO "Installing the new Lima ${NEWVER}"
73+
install_lima "${NEWVER}"
74+
75+
INFO "Restarting the instance"
76+
limactl start --tty=false "${LIMA_INSTANCE}"
77+
lima nerdctl info
78+
79+
INFO "Confirming that the host filesystem is still mounted"
80+
"${scriptdir}"/test-mount-home.sh "${LIMA_INSTANCE}"
81+
82+
INFO "Confirming that the image \"${image_name}\" still exists"
83+
lima nerdctl run --rm "${image_name}"

0 commit comments

Comments
 (0)