Skip to content

Commit

Permalink
Merge pull request #708 from AkihiroSuda/test-upgrade
Browse files Browse the repository at this point in the history
CI: add upgrade test
  • Loading branch information
AkihiroSuda authored Mar 10, 2022
2 parents d6c2258 + 3125937 commit e231af1
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 37 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,35 @@ jobs:
# GHA macOS is slow and flaky, so we only test a few YAMLS here.
# Other yamls are tested on Linux instances of Cirrus.

upgrade:
name: "Upgrade test"
runs-on: macos-11
timeout-minutes: 120
strategy:
matrix:
oldver: ["v0.8.0"]
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.17.x
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install test dependencies
run: brew install qemu bash coreutils
- name: Cache ~/Library/Caches/lima/download
uses: actions/cache@v2
with:
path: ~/Library/Caches/lima/download
key: ${{ runner.os }}-upgrade-${{ matrix.oldver }}
- name: Test
uses: nick-invision/retry@v2
with:
timeout_minutes: 30
retry_on: error
max_attempts: 3
command: ./hack/test-upgrade.sh ${{ matrix.oldver }} ${{ github.sha }}

artifacts-darwin:
name: Artifacts Darwin
runs-on: macos-11
Expand Down
1 change: 1 addition & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source-path=SCRIPTDIR
24 changes: 24 additions & 0 deletions hack/common.inc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# shellcheck shell=bash
cleanup_cmd=""
trap 'eval ${cleanup_cmd}' EXIT
function defer {
[ -n "${cleanup_cmd}" ] && cleanup_cmd="${cleanup_cmd}; "
cleanup_cmd="${cleanup_cmd}$1"
}

function INFO() {
echo "TEST| [INFO] $*"
}

function WARNING() {
echo >&2 "TEST| [WARNING] $*"
}

function ERROR() {
echo >&2 "TEST| [ERROR] $*"
}

if [[ ${BASH_VERSINFO:-0} -lt 4 ]]; then
ERROR "Bash version is too old: ${BASH_VERSION}"
exit 1
fi
40 changes: 3 additions & 37 deletions hack/test-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,8 @@
set -eu -o pipefail

scriptdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

cleanup_cmd=""
trap 'eval ${cleanup_cmd}' EXIT
function defer {
[ -n "${cleanup_cmd}" ] && cleanup_cmd="${cleanup_cmd}; "
cleanup_cmd="${cleanup_cmd}$1"
}

function INFO() {
echo "TEST| [INFO] $*"
}

function WARNING() {
echo >&2 "TEST| [WARNING] $*"
}

function ERROR() {
echo >&2 "TEST| [ERROR] $*"
}

if [[ ${BASH_VERSINFO:-0} -lt 4 ]]; then
ERROR "Bash version is too old: ${BASH_VERSION}"
exit 1
fi
# shellcheck source=common.inc.sh
source "${scriptdir}/common.inc.sh"

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

if [[ -n ${CHECKS["mount-home"]} ]]; then
hometmp="$HOME/lima-test-tmp"
INFO "Testing home access (\"$hometmp\")"
rm -rf "$hometmp"
mkdir -p "$hometmp"
defer "rm -rf \"$hometmp\""
echo "random-content-${RANDOM}" >"$hometmp/random"
expected="$(cat "$hometmp/random")"
got="$(limactl shell "$NAME" cat "$hometmp/random")"
INFO "$hometmp/random: expected=${expected}, got=${got}"
if [ "$got" != "$expected" ]; then
ERROR "Home directory is not shared?"
exit 1
fi
"${scriptdir}"/test-mount-home.sh "$NAME"
fi

# Use GHCR to avoid hitting Docker Hub rate limit
Expand Down
26 changes: 26 additions & 0 deletions hack/test-mount-home.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -eu -o pipefail

scriptdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=common.inc.sh
source "${scriptdir}/common.inc.sh"

if [ "$#" -ne 1 ]; then
ERROR "Usage: $0 NAME"
exit 1
fi

NAME="$1"
hometmp="$HOME/lima-test-tmp"
INFO "Testing home access (\"$hometmp\")"
rm -rf "$hometmp"
mkdir -p "$hometmp"
defer "rm -rf \"$hometmp\""
echo "random-content-${RANDOM}" >"$hometmp/random"
expected="$(cat "$hometmp/random")"
got="$(limactl shell "$NAME" cat "$hometmp/random")"
INFO "$hometmp/random: expected=${expected}, got=${got}"
if [ "$got" != "$expected" ]; then
ERROR "Home directory is not shared?"
exit 1
fi
83 changes: 83 additions & 0 deletions hack/test-upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env bash
set -eu -o pipefail

scriptdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=common.inc.sh
source "${scriptdir}/common.inc.sh"
cd "${scriptdir}/.."

if [ "$#" -ne 2 ]; then
ERROR "Usage: $0 OLDVER NEWVER"
exit 1
fi

OLDVER="$1"
NEWVER="$2"

PREFIX="/usr/local"
function install_lima() {
ver="$1"
git checkout "${ver}"
make clean
make
if [ -w "${PREFIX}/bin" ] && [ -w "${PREFIX}/share" ]; then
make install
else
sudo make install
fi
}

function uninstall_lima() {
files="${PREFIX}/bin/lima ${PREFIX}/bin/limactl ${PREFIX}/share/lima ${PREFIX}/share/doc/lima"
if [ -w "${PREFIX}/bin" ] && [ -w "${PREFIX}/share" ]; then
# shellcheck disable=SC2086
rm -rf $files
else
# shellcheck disable=SC2086
sudo rm -rf $files
fi
}

INFO "Uninstalling lima"
uninstall_lima

INFO "Installing the old Lima ${OLDVER}"
install_lima "${OLDVER}"

export LIMA_INSTANCE="test-upgrade"

INFO "Creating an instance \"${LIMA_INSTANCE}\" with the old Lima"
defer "limactl delete -f \"${LIMA_INSTANCE}\""
limactl start --tty=false "${LIMA_INSTANCE}"
lima nerdctl info

image_name="lima-test-upgrade-containerd-${RANDOM}"
image_context="${HOME}/${image_name}"
INFO "Building containerd image \"${image_name}\" from \"${image_context}\""
defer "rm -rf \"${image_context}\""
mkdir -p "${image_context}"
cat <<EOF >"${image_context}"/Dockerfile
# Use GHCR to avoid hitting Docker Hub rate limit
FROM ghcr.io/containerd/alpine:3.14.0
CMD ["echo", "Built with Lima ${OLDVER}"]
EOF
lima nerdctl build -t "${image_name}" "${image_context}"
lima nerdctl run --rm "${image_name}"

INFO "Stopping the instance"
limactl stop "${LIMA_INSTANCE}"

INFO "=============================================================================="

INFO "Installing the new Lima ${NEWVER}"
install_lima "${NEWVER}"

INFO "Restarting the instance"
limactl start --tty=false "${LIMA_INSTANCE}"
lima nerdctl info

INFO "Confirming that the host filesystem is still mounted"
"${scriptdir}"/test-mount-home.sh "${LIMA_INSTANCE}"

INFO "Confirming that the image \"${image_name}\" still exists"
lima nerdctl run --rm "${image_name}"

0 comments on commit e231af1

Please sign in to comment.