ref(docker): Consolidate all tests in the `entrypoint.sh` script (#8175)

* ref(docker): Consolidate all tests in the `entrypoint.sh` script

* fix(ci): missing docker argument

* fix(ci): do not blank `ENTRYPOINT_FEATURES` vairable

* fix(docker): do not add `shielded-scan` as part of `TEST_FEATURES`

* chore: remove misleading comment

* Update docker/Dockerfile

Co-authored-by: Arya <aryasolhi@gmail.com>

---------

Co-authored-by: Arya <aryasolhi@gmail.com>
This commit is contained in:
Gustavo Valverde 2024-01-30 17:47:05 +00:00 committed by GitHub
parent c9401ad754
commit 184c30e0fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 33 deletions

View File

@ -82,9 +82,6 @@ on:
- '.github/workflows/sub-build-docker-image.yml'
env:
# We need to combine the features manually because some tests don't use the Docker entrypoint
TEST_FEATURES: ${{ format('{0} {1}', vars.RUST_PROD_FEATURES, vars.RUST_TEST_FEATURES) }}
EXPERIMENTAL_FEATURES: ${{ format('{0} {1} {2}', vars.RUST_PROD_FEATURES, vars.RUST_TEST_FEATURES, vars.RUST_EXPERIMENTAL_FEATURES) }}
RUST_LOG: ${{ vars.RUST_LOG }}
RUST_BACKTRACE: ${{ vars.RUST_BACKTRACE }}
RUST_LIB_BACKTRACE: ${{ vars.RUST_LIB_BACKTRACE }}
@ -135,27 +132,21 @@ jobs:
#
# If some tests hang, add "-- --nocapture" for just that test, or for all the tests.
#
# TODO: move this test command into entrypoint.sh
- name: Run zebrad tests
env:
NETWORK: ${{ inputs.network || vars.ZCASH_NETWORK }}
run: |
docker pull ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ needs.build.outputs.image_digest }}
docker run -e NETWORK --name zebrad-tests --tty ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ needs.build.outputs.image_digest }} cargo test --locked --release --features "${{ env.TEST_FEATURES }}" --workspace -- --include-ignored
docker run --tty -e NETWORK -e RUN_ALL_TESTS=1 ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ needs.build.outputs.image_digest }}
# Run unit, basic acceptance tests, and ignored tests with experimental features.
#
# TODO: move this test command into entrypoint.sh
- name: Run zebrad tests with experimental features
env:
NETWORK: ${{ inputs.network || vars.ZCASH_NETWORK }}
run: |
# GitHub doesn't allow empty variables
if [[ -n "${{ vars.RUST_EXPERIMENTAL_FEATURES }}" && "${{ vars.RUST_EXPERIMENTAL_FEATURES }}" != " " ]]; then
docker run -e NETWORK --name zebrad-tests-experimental --tty ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ needs.build.outputs.image_digest }} cargo test --locked --release --features "${{ env.EXPERIMENTAL_FEATURES }} " --workspace -- --include-ignored
else
echo "Experimental builds are disabled, set RUST_EXPERIMENTAL_FEATURES in GitHub actions variables to enable them"
fi
docker pull ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ needs.build.outputs.image_digest }}
docker run --tty -e NETWORK -e RUN_ALL_EXPERIMENTAL_TESTS=1 ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ needs.build.outputs.image_digest }}
# Run state tests with fake activation heights.
#
@ -179,15 +170,12 @@ jobs:
with:
short-length: 7
# TODO: move this test command into entrypoint.sh
# make sure that at least one test runs, and that it doesn't skip itself due to the environmental variable
- name: Run tests with fake activation heights
env:
NETWORK: ${{ inputs.network || vars.ZCASH_NETWORK }}
run: |
docker pull ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ needs.build.outputs.image_digest }}
docker run -e NETWORK -e TEST_FAKE_ACTIVATION_HEIGHTS --name zebrad-tests -t ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ needs.build.outputs.image_digest }} cargo test --locked --release --features "zebra-test" --package zebra-state --lib -- --nocapture --include-ignored with_fake_activation_heights
env:
TEST_FAKE_ACTIVATION_HEIGHTS: '1'
NETWORK: ${{ inputs.network || vars.ZCASH_NETWORK }}
docker run --tty -e NETWORK -e TEST_FAKE_ACTIVATION_HEIGHTS=1 ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ needs.build.outputs.image_digest }}
# Test that Zebra syncs and checkpoints a few thousand blocks from an empty state.
test-empty-sync:
@ -203,13 +191,12 @@ jobs:
with:
short-length: 7
# TODO: move this test command into entrypoint.sh
- name: Run zebrad large sync tests
run: |
docker pull ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ needs.build.outputs.image_digest }}
docker run -e NETWORK --name zebrad-tests -t ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ needs.build.outputs.image_digest }} cargo test --locked --release --features "${{ env.TEST_FEATURES }}" --package zebrad --test acceptance -- --nocapture --include-ignored sync_large_checkpoints_
env:
NETWORK: ${{ inputs.network || vars.ZCASH_NETWORK }}
run: |
docker pull ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ needs.build.outputs.image_digest }}
docker run --tty -e NETWORK -e TEST_ZEBRA_EMPTY_SYNC=1 ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ needs.build.outputs.image_digest }}
# Test launching lightwalletd with an empty lightwalletd and Zebra state.
test-lightwalletd-integration:
@ -225,14 +212,12 @@ jobs:
with:
short-length: 7
# TODO: move this test command into entrypoint.sh
- name: Run tests with empty lightwalletd launch
env:
NETWORK: ${{ inputs.network || vars.ZCASH_NETWORK }}
run: |
docker pull ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ needs.build.outputs.image_digest }}
docker run -e NETWORK -e ZEBRA_TEST_LIGHTWALLETD --name lightwalletd-tests -t ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ needs.build.outputs.image_digest }} cargo test --locked --release --features "${{ env.TEST_FEATURES }}" --package zebrad --test acceptance -- --nocapture --include-ignored lightwalletd_integration
env:
ZEBRA_TEST_LIGHTWALLETD: '1'
NETWORK: ${{ inputs.network || vars.ZCASH_NETWORK }}
docker run --tty -e NETWORK -e ZEBRA_TEST_LIGHTWALLETD=1 ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ needs.build.outputs.image_digest }}
# Test that Zebra works using the default config with the latest Zebra version.
test-configuration-file:

View File

@ -17,6 +17,7 @@
# https://github.com/ZcashFoundation/zebra/settings/variables/actions
ARG FEATURES="default-release-binaries"
ARG TEST_FEATURES="lightwalletd-grpc-tests zebra-checkpoints"
ARG EXPERIMENTAL_FEATURES=""
# This stage implements cargo-chef for docker layer caching
FROM rust:bullseye as chef
@ -111,6 +112,8 @@ ENV ZEBRA_SKIP_IPV6_TESTS=${ZEBRA_SKIP_IPV6_TESTS:-1}
# separately from the test and production image builds.
ARG FEATURES
ARG TEST_FEATURES
ARG EXPERIMENTAL_FEATURES
# TODO: add empty $EXPERIMENTAL_FEATURES when we can avoid adding an extra space to the end of the string
ARG ENTRYPOINT_FEATURES="${FEATURES} ${TEST_FEATURES}"
# Re-hydrate the minimum project skeleton identified by `cargo chef prepare` in the planner stage,
@ -122,7 +125,6 @@ ARG ENTRYPOINT_FEATURES="${FEATURES} ${TEST_FEATURES}"
#
# TODO: add --locked when cargo-chef supports it
RUN cargo chef cook --tests --release --features "${ENTRYPOINT_FEATURES}" --workspace --recipe-path recipe.json
# Undo the source file changes made by cargo-chef.
# rsync invalidates the cargo cache for the changed files only, by updating their timestamps.
# This makes sure the fake empty binaries created by cargo-chef are rebuilt.
@ -140,6 +142,9 @@ RUN chmod u+x /entrypoint.sh
# Entrypoint environment variables
ENV ENTRYPOINT_FEATURES=${ENTRYPOINT_FEATURES}
# We repeat the ARGs here, so they are available in the entrypoint.sh script for $RUN_ALL_EXPERIMENTAL_TESTS
ARG EXPERIMENTAL_FEATURES="shielded-scan journald prometheus filter-reload"
ENV ENTRYPOINT_FEATURES_EXPERIMENTAL="${ENTRYPOINT_FEATURES} ${EXPERIMENTAL_FEATURES}"
# By default, runs the entrypoint tests specified by the environmental variables (if any are set)
ENTRYPOINT [ "/entrypoint.sh" ]

View File

@ -58,6 +58,9 @@ fi
####
: "${RUN_ALL_TESTS:=}"
: "${RUN_ALL_EXPERIMENTAL_TESTS:=}"
: "${TEST_FAKE_ACTIVATION_HEIGHTS:=}"
: "${TEST_ZEBRA_EMPTY_SYNC:=}"
: "${ZEBRA_TEST_LIGHTWALLETD:=}"
: "${FULL_SYNC_MAINNET_TIMEOUT_MINUTES:=}"
: "${FULL_SYNC_TESTNET_TIMEOUT_MINUTES:=}"
@ -221,12 +224,27 @@ case "$1" in
# For these tests, we activate the test features to avoid recompiling `zebrad`,
# but we don't actually run any gRPC tests.
if [[ "${RUN_ALL_TESTS}" -eq "1" ]]; then
# Run all the available tests for the current environment.
# If the lightwalletd environmental variables are set, we will also run those tests.
exec cargo test --locked --release --features "${ENTRYPOINT_FEATURES}" --workspace -- --nocapture --include-ignored
# Run unit, basic acceptance tests, and ignored tests, only showing command output if the test fails.
# If the lightwalletd environmental variables are set, we will also run those tests.
exec cargo test --locked --release --features "${ENTRYPOINT_FEATURES}" --workspace -- --nocapture --include-ignored
elif [[ "${RUN_ALL_EXPERIMENTAL_TESTS}" -eq "1" ]]; then
# Run unit, basic acceptance tests, and ignored tests with experimental features.
# If the lightwalletd environmental variables are set, we will also run those tests.
exec cargo test --locked --release --features "${ENTRYPOINT_FEATURES_EXPERIMENTAL}" --workspace -- --nocapture --include-ignored
elif [[ "${TEST_FAKE_ACTIVATION_HEIGHTS}" -eq "1" ]]; then
# Run state tests with fake activation heights.
exec cargo test --locked --release --features "zebra-test" --package zebra-state --lib -- --nocapture --include-ignored with_fake_activation_heights
elif [[ "${TEST_ZEBRA_EMPTY_SYNC}" -eq "1" ]]; then
# Test that Zebra syncs and checkpoints a few thousand blocks from an empty state.
run_cargo_test "${ENTRYPOINT_FEATURES}" "sync_large_checkpoints_"
elif [[ "${ZEBRA_TEST_LIGHTWALLETD}" -eq "1" ]]; then
# Test launching lightwalletd with an empty lightwalletd and Zebra state.
run_cargo_test "${ENTRYPOINT_FEATURES}" "lightwalletd_integration"
# For these tests, we activate the gRPC feature to avoid recompiling `zebrad`,
# but we don't actually run any gRPC tests.
elif [[ -n "${FULL_SYNC_MAINNET_TIMEOUT_MINUTES}" ]]; then
# Run a Zebra full sync test on mainnet.
run_cargo_test "${ENTRYPOINT_FEATURES}" "full_sync_mainnet"