From 9e506593bf08462796c776d046113312be4244c0 Mon Sep 17 00:00:00 2001 From: Prasad Chandrasekaran Date: Sat, 18 Mar 2023 12:08:49 +0530 Subject: [PATCH] scripts: Add testing of etcd in local image in release workflow. Signed-off-by: Prasad Chandrasekaran --- .github/workflows/release.yaml | 8 +++- scripts/test_images.sh | 84 ++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100755 scripts/test_images.sh diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index cb6d0923943..d396aa6993f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -8,7 +8,10 @@ jobs: - uses: actions/setup-go@v2 with: go-version: "1.19.7" - - run: | + - name: release + run: | + set -euo pipefail + git config --global user.email "github-action@etcd.io" git config --global user.name "Github Action" gpg --batch --gen-key </dev/null; then + log_error "cannot find docker" + exit 1 +fi + +# You can't run darwin binaries in linux containers +if [[ $(go env GOOS) == "darwin" ]]; then + echo "Please use linux machine for release builds." + exit 1 +fi + +# Pick defaults based on release workflow +ARCH=$(go env GOARCH) +REPOSITARY=${REPOSITARY:-"gcr.io/etcd-development/etcd"} +if [ -n "$VERSION" ]; then + # Expected Format: v3.6.99-amd64 + TAG=v"${VERSION}"-"${ARCH}" +else + echo "Terminating test, VERSION not supplied" + exit 1 +fi +IMAGE=${IMAGE:-"${REPOSITARY}:${TAG}"} + +# ETCD related values +RUN_NAME="test_etcd" +KEY="foo" +VALUE="bar" + +if [[ "$(docker images -q "${IMAGE}" 2> /dev/null)" == "" ]]; then + echo "${IMAGE} not present locally" + exit 1 +fi + +# Version check +runVersionCheck "/usr/local/bin/etcd" "--version" +runVersionCheck "/usr/local/bin/etcdctl" "version" +runVersionCheck "/usr/local/bin/etcdutl" "version" + +startContainer +# stop container +trap 'docker stop "${RUN_NAME}"' EXIT + + +# Put/Get check +PUT=$(docker exec "${RUN_NAME}" /usr/local/bin/etcdctl put "${KEY}" "${VALUE}") +if [ "${PUT}" != "OK" ]; then + echo "Problem with Putting in etcd" + exit 1 +fi + +GET=$(docker exec "${RUN_NAME}" /usr/local/bin/etcdctl get "$KEY" --print-value-only) +if [ "${GET}" != "${VALUE}" ]; then + echo "Problem with getting foo bar in etcd. Got ${GET}" + exit 1 +fi + +echo "Succesfully tested etcd local image ${TAG}" +