diff --git a/.gitea/workflows/test-deploy.yml b/.gitea/workflows/test-deploy.yml new file mode 100644 index 00000000..a3e8d20e --- /dev/null +++ b/.gitea/workflows/test-deploy.yml @@ -0,0 +1,39 @@ +name: Deploy Test + +on: + pull_request: + branches: '*' + push: + branches: + - main + - ci-test + +# Needed until we can incorporate docker startup into the executor container +env: + DOCKER_HOST: unix:///var/run/dind.sock + +jobs: + test: + name: "Run deploy test suite" + runs-on: ubuntu-latest + steps: + - name: "Clone project repository" + uses: actions/checkout@v3 + - name: "Install Python" + uses: cerc-io/setup-python@v4 + with: + python-version: '3.8' + - name: "Print Python version" + run: python3 --version + - name: "Install shiv" + run: pip install shiv + - name: "Generate build version file" + run: ./scripts/create_build_tag_file.sh + - name: "Build local shiv package" + run: ./scripts/build_shiv_package.sh + - name: Start dockerd # Also needed until we can incorporate into the executor + run: | + dockerd -H $DOCKER_HOST --userland-proxy=false & + sleep 5 + - name: "Run smoke tests" + run: ./tests/deploy-test/run-smoke-test.sh diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml new file mode 100644 index 00000000..71a764d4 --- /dev/null +++ b/.github/workflows/test-deploy.yml @@ -0,0 +1,29 @@ +name: Deploy Test + +on: + pull_request: + branches: '*' + push: + branches: '*' + +jobs: + test: + name: "Run deploy test suite" + runs-on: ubuntu-latest + steps: + - name: "Clone project repository" + uses: actions/checkout@v3 + - name: "Install Python" + uses: actions/setup-python@v4 + with: + python-version: '3.8' + - name: "Print Python version" + run: python3 --version + - name: "Install shiv" + run: pip install shiv + - name: "Generate build version file" + run: ./scripts/create_build_tag_file.sh + - name: "Build local shiv package" + run: ./scripts/build_shiv_package.sh + - name: "Run smoke tests" + run: ./tests/deploy-test/run-smoke-test.sh diff --git a/app/data/container-build/cerc-fixturenet-eth-geth/Dockerfile b/app/data/container-build/cerc-fixturenet-eth-geth/Dockerfile index 666f9117..63c3c0a7 100644 --- a/app/data/container-build/cerc-fixturenet-eth-geth/Dockerfile +++ b/app/data/container-build/cerc-fixturenet-eth-geth/Dockerfile @@ -6,7 +6,7 @@ RUN go install github.com/go-delve/delve/cmd/dlv@latest FROM cerc/go-ethereum:local as geth -FROM alpine:3.17 +FROM alpine:latest RUN apk add --no-cache python3 python3-dev py3-pip curl wget jq build-base gettext libintl openssl bash bind-tools postgresql-client COPY --from=delve /go/bin/dlv /usr/local/bin/ diff --git a/app/deploy_system.py b/app/deploy_system.py index 5b1341c4..d4dcc36f 100644 --- a/app/deploy_system.py +++ b/app/deploy_system.py @@ -75,7 +75,7 @@ def up(ctx, extra_args): @command.command() -@click.option("--delete-volumes", default=False, help="delete data volumes") +@click.option("--delete-volumes/--preserve-volumes", default=False, help="delete data volumes") @click.argument('extra_args', nargs=-1) # help: command: down @click.pass_context def down(ctx, delete_volumes, extra_args): @@ -88,7 +88,7 @@ def down(ctx, delete_volumes, extra_args): if extra_args_list: timeout_arg = extra_args_list[0] # Specify shutdown timeout (default 10s) to give services enough time to shutdown gracefully - ctx.obj.docker.compose.down(timeout=timeout_arg) + ctx.obj.docker.compose.down(timeout=timeout_arg, volumes=delete_volumes) @command.command() diff --git a/tests/deploy/run-deploy-test.sh b/tests/deploy/run-deploy-test.sh new file mode 100755 index 00000000..291799a4 --- /dev/null +++ b/tests/deploy/run-deploy-test.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +set -e +if [ -n "$CERC_SCRIPT_DEBUG" ]; then + set -x +fi +# Dump environment variables for debugging +echo "Environment variables:" +env +# Test basic stack-orchestrator deploy +echo "Running stack-orchestrator deploy test" +# Bit of a hack, test the most recent package +TEST_TARGET_SO=$( ls -t1 ./package/laconic-so* | head -1 ) +# Set a non-default repo dir +export CERC_REPO_BASE_DIR=~/stack-orchestrator-test/repo-base-dir +echo "Testing this package: $TEST_TARGET_SO" +echo "Test version command" +reported_version_string=$( $TEST_TARGET_SO version ) +echo "Version reported is: ${reported_version_string}" +echo "Cloning repositories into: $CERC_REPO_BASE_DIR" +rm -rf $CERC_REPO_BASE_DIR +mkdir -p $CERC_REPO_BASE_DIR +# Test bringing the test container up and down +# with and without volume removal +$TEST_TARGET_SO --stack test setup-repositories +$TEST_TARGET_SO --stack test build-containers +$TEST_TARGET_SO --stack test deploy up +$TEST_TARGET_SO --stack test deploy down +# The next time we bring the container up the volume will be old (from the previous run above) +$TEST_TARGET_SO --stack test deploy up +log_output_1=$( $TEST_TARGET_SO --stack test deploy logs ) +if [[ "$log_output_1" == *"Filesystem is old"* ]]; then + echo "Retain volumes test: passed" +else + echo "Retain volumes test: FAILED" + exit 1 +fi +$TEST_TARGET_SO --stack test deploy down --delete-volumes +# Now when we bring the container up the volume will be new again +$TEST_TARGET_SO --stack test deploy up +log_output_2=$( $TEST_TARGET_SO --stack test deploy logs ) +if [[ "$log_output_2" == *"Filesystem is fresh"* ]]; then + echo "Delete volumes test: passed" +else + echo "Delete volumes test: FAILED" + exit 1 +fi +$TEST_TARGET_SO --stack test deploy down --delete-volumes +echo "Test passed"