Skip to content

Commit 49741e8

Browse files
fix(ci): Add Rust environment variables to Docker test workflows (ZcashFoundation#9318)
* feat(ci): Add Rust environment variables to Docker test workflows Enhance test workflows by adding Rust-specific environment variables: - Include RUST_LOG for logging configuration - Add RUST_BACKTRACE and RUST_LIB_BACKTRACE for improved error tracing - Include COLORBT_SHOW_HIDDEN for detailed backtraces - Add CARGO_INCREMENTAL for build performance optimization These changes improve debugging capabilities and provide more flexibility in test environments across dockerized CI jobs. * feat(ci): Add CARGO_INCREMENTAL build argument to Docker workflow Enable configurable Rust incremental compilation in Docker builds by: - Adding CARGO_INCREMENTAL as a build argument in GitHub Actions workflow - Setting a default value of 0 in Dockerfile to control build performance - Integrating with existing Rust environment variable configuration This change provides more granular control over Rust compilation strategies in containerized builds. * fix(docker): resolve user creation issues in Dockerfile - Move WORKDIR after user creation to prevent home directory ownership issues - Properly set environment variables for UID, GID, HOME, and USER in each stage - Reorganize Dockerfile to ensure home directory is created after user setup - Fix interactive prompts during adduser by ensuring proper directory ownership * fix(docs): Apply suggestions from code review Co-authored-by: Marek <[email protected]> --------- Co-authored-by: Marek <[email protected]>
1 parent f873aa1 commit 49741e8

File tree

4 files changed

+67
-24
lines changed

4 files changed

+67
-24
lines changed

Diff for: .github/workflows/sub-build-docker-image.yml

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ jobs:
166166
build-args: |
167167
SHORT_SHA=${{ env.GITHUB_SHA_SHORT }}
168168
RUST_LOG=${{ env.RUST_LOG }}
169+
CARGO_INCREMENTAL=${{ env.CARGO_INCREMENTAL }}
169170
FEATURES=${{ env.FEATURES }}
170171
push: true
171172
# It's recommended to build images with max-level provenance attestations

Diff for: .github/workflows/sub-ci-unit-tests-docker.yml

+37-6
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,15 @@ jobs:
5353
- name: Run all tests
5454
run: |
5555
docker pull ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ inputs.image_digest }}
56-
docker run -t \
56+
docker run --tty \
5757
-e RUN_ALL_TESTS=1 \
5858
-e FEATURES="journald prometheus filter-reload" \
5959
-e NETWORK="${{ inputs.network || vars.ZCASH_NETWORK }}" \
60+
-e RUST_LOG=${{ env.RUST_LOG }} \
61+
-e RUST_BACKTRACE=${{ env.RUST_BACKTRACE }} \
62+
-e RUST_LIB_BACKTRACE=${{ env.RUST_LIB_BACKTRACE }} \
63+
-e COLORBT_SHOW_HIDDEN=${{ env.COLORBT_SHOW_HIDDEN }} \
64+
-e CARGO_INCREMENTAL=${{ env.CARGO_INCREMENTAL }} \
6065
${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ inputs.image_digest }}
6166
6267
# Run state tests with fake activation heights.
@@ -85,9 +90,14 @@ jobs:
8590
NETWORK: ${{ inputs.network || vars.ZCASH_NETWORK }}
8691
run: |
8792
docker pull ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ inputs.image_digest }}
88-
docker run -t \
93+
docker run --tty \
8994
-e TEST_FAKE_ACTIVATION_HEIGHTS=1 \
9095
-e NETWORK="${{ inputs.network || vars.ZCASH_NETWORK }}" \
96+
-e RUST_LOG=${{ env.RUST_LOG }} \
97+
-e RUST_BACKTRACE=${{ env.RUST_BACKTRACE }} \
98+
-e RUST_LIB_BACKTRACE=${{ env.RUST_LIB_BACKTRACE }} \
99+
-e COLORBT_SHOW_HIDDEN=${{ env.COLORBT_SHOW_HIDDEN }} \
100+
-e CARGO_INCREMENTAL=${{ env.CARGO_INCREMENTAL }} \
91101
${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ inputs.image_digest }}
92102
93103
# Test that Zebra syncs and checkpoints a few thousand blocks from an empty state.
@@ -108,7 +118,15 @@ jobs:
108118
NETWORK: ${{ inputs.network || vars.ZCASH_NETWORK }}
109119
run: |
110120
docker pull ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ inputs.image_digest }}
111-
docker run --tty -e TEST_ZEBRA_EMPTY_SYNC=1 ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ inputs.image_digest }}
121+
docker run --tty \
122+
-e TEST_ZEBRA_EMPTY_SYNC=1 \
123+
-e NETWORK="${{ inputs.network || vars.ZCASH_NETWORK }}" \
124+
-e RUST_LOG=${{ env.RUST_LOG }} \
125+
-e RUST_BACKTRACE=${{ env.RUST_BACKTRACE }} \
126+
-e RUST_LIB_BACKTRACE=${{ env.RUST_LIB_BACKTRACE }} \
127+
-e COLORBT_SHOW_HIDDEN=${{ env.COLORBT_SHOW_HIDDEN }} \
128+
-e CARGO_INCREMENTAL=${{ env.CARGO_INCREMENTAL }} \
129+
${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ inputs.image_digest }}
112130
113131
# Test launching lightwalletd with an empty lightwalletd and Zebra state.
114132
test-lightwalletd-integration:
@@ -128,7 +146,13 @@ jobs:
128146
NETWORK: ${{ inputs.network || vars.ZCASH_NETWORK }}
129147
run: |
130148
docker pull ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ inputs.image_digest }}
131-
docker run --tty -e ZEBRA_TEST_LIGHTWALLETD=1 -e TEST_LWD_INTEGRATION=1 ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ inputs.image_digest }}
149+
docker run --tty \
150+
-e ZEBRA_TEST_LIGHTWALLETD=1 \
151+
-e TEST_LWD_INTEGRATION=1 \
152+
-e NETWORK="${{ inputs.network || vars.ZCASH_NETWORK }}" \
153+
-e RUST_LOG=${{ env.RUST_LOG }} \
154+
-e RUST_BACKTRACE=${{ env.RUST_BACKTRACE }} \
155+
${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ inputs.image_digest }}
132156
133157
# Test that Zebra works using the default config with the latest Zebra version.
134158
test-configuration-file:
@@ -147,8 +171,8 @@ jobs:
147171
with:
148172
test_id: "testnet-conf"
149173
docker_image: ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ inputs.image_digest }}
150-
grep_patterns: '-e "net.*=.*Test.*estimated progress to chain tip.*Genesis" -e "net.*=.*Test.*estimated progress to chain tip.*BeforeOverwinter"'
151174
test_variables: "-e NETWORK=Testnet"
175+
grep_patterns: '-e "net.*=.*Test.*estimated progress to chain tip.*Genesis" -e "net.*=.*Test.*estimated progress to chain tip.*BeforeOverwinter"'
152176

153177
# Test that Zebra works using $ZEBRA_CONF_PATH config
154178
test-zebra-conf-path:
@@ -198,4 +222,11 @@ jobs:
198222
- name: Run check_no_git_refs_in_cargo_lock
199223
run: |
200224
docker pull ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ inputs.image_digest }}
201-
docker run --tty -e RUN_CHECK_NO_GIT_REFS=1 ${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ inputs.image_digest }}
225+
docker run --tty \
226+
-e RUN_CHECK_NO_GIT_REFS=1 \
227+
-e NETWORK="${{ inputs.network || vars.ZCASH_NETWORK }}" \
228+
-e RUST_LOG=${{ env.RUST_LOG }} \
229+
-e RUST_BACKTRACE=${{ env.RUST_BACKTRACE }} \
230+
-e RUST_LIB_BACKTRACE=${{ env.RUST_LIB_BACKTRACE }} \
231+
-e COLORBT_SHOW_HIDDEN=${{ env.COLORBT_SHOW_HIDDEN }} \
232+
${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}@${{ inputs.image_digest }}

Diff for: .github/workflows/sub-deploy-integration-tests-gcp.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ on:
8585
description: 'Application name, used to work out when a job is an update job'
8686

8787
env:
88+
RUST_LOG: ${{ vars.RUST_LOG }}
89+
RUST_BACKTRACE: ${{ vars.RUST_BACKTRACE }}
90+
RUST_LIB_BACKTRACE: ${{ vars.RUST_LIB_BACKTRACE }}
91+
COLORBT_SHOW_HIDDEN: ${{ vars.COLORBT_SHOW_HIDDEN }}
92+
CARGO_INCREMENTAL: ${{ vars.CARGO_INCREMENTAL }}
8893
# How many previous log lines we show at the start of each new log job.
8994
# Increase this number if some log lines are skipped between jobs
9095
#
@@ -95,7 +100,6 @@ env:
95100
# How many blocks to wait before creating an updated cached state image.
96101
# 1 day is approximately 1152 blocks.
97102
CACHED_STATE_UPDATE_LIMIT: 576
98-
99103
jobs:
100104
# Find a cached state disk for ${{ inputs.test_id }}, matching all of:
101105
# - disk cached state prefix -> zebrad-cache or lwd-cache
@@ -279,6 +283,11 @@ jobs:
279283
--tty \
280284
--detach \
281285
${{ inputs.test_variables }} \
286+
-e RUST_LOG=${{ env.RUST_LOG }} \
287+
-e RUST_BACKTRACE=${{ env.RUST_BACKTRACE }} \
288+
-e RUST_LIB_BACKTRACE=${{ env.RUST_LIB_BACKTRACE }} \
289+
-e COLORBT_SHOW_HIDDEN=${{ env.COLORBT_SHOW_HIDDEN }} \
290+
-e CARGO_INCREMENTAL=${{ env.CARGO_INCREMENTAL }} \
282291
${MOUNT_FLAGS} \
283292
${{ vars.GAR_BASE }}/${{ vars.CI_IMAGE_NAME }}:sha-${{ env.GITHUB_SHA_SHORT }} \
284293
'

Diff for: docker/Dockerfile

+19-17
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,14 @@ ENV RUST_LIB_BACKTRACE=${RUST_LIB_BACKTRACE:-1}
5252
ARG COLORBT_SHOW_HIDDEN
5353
ENV COLORBT_SHOW_HIDDEN=${COLORBT_SHOW_HIDDEN:-1}
5454

55+
ARG CARGO_INCREMENTAL
56+
ENV CARGO_INCREMENTAL=${CARGO_INCREMENTAL:-0}
57+
5558
ARG SHORT_SHA
5659
# If this is not set, it must be an empty string, so Zebra can try an alternative git commit source:
5760
# https://github.com/ZcashFoundation/zebra/blob/9ebd56092bcdfc1a09062e15a0574c94af37f389/zebrad/src/application.rs#L179-L182
5861
ENV SHORT_SHA=${SHORT_SHA:-}
5962

60-
# Set the working directory for the build.
61-
ARG HOME
62-
WORKDIR ${HOME}
63-
ENV HOME=${HOME}
64-
ENV CARGO_HOME="${HOME}/.cargo/"
65-
66-
ENV USER=${USER}
67-
6863
# This stage builds tests without running them.
6964
#
7065
# We also download needed dependencies for tests to work, from other images.
@@ -81,15 +76,22 @@ ENV ZEBRA_SKIP_IPV6_TESTS=${ZEBRA_SKIP_IPV6_TESTS:-1}
8176
# This environment setup is almost identical to the `runtime` target so that the
8277
# `tests` target differs minimally. In fact, a subset of this setup is used for
8378
# the `runtime` target.
84-
8579
ARG UID
80+
ENV UID=${UID}
8681
ARG GID
82+
ENV GID=${GID}
8783
ARG HOME
84+
ENV HOME=${HOME}
8885
ARG USER
86+
ENV USER=${USER}
8987

9088
RUN addgroup --gid ${GID} ${USER} && \
9189
adduser --gid ${GID} --uid ${UID} --home ${HOME} ${USER}
9290

91+
# Set the working directory for the build.
92+
WORKDIR ${HOME}
93+
ENV CARGO_HOME="${HOME}/.cargo/"
94+
9395
# Build Zebra test binaries, but don't run them
9496

9597
# Leverage a cache mount to /usr/local/cargo/registry/
@@ -189,14 +191,8 @@ FROM debian:bookworm-slim AS runtime
189191
ARG FEATURES
190192
ENV FEATURES=${FEATURES}
191193

192-
# Create a non-privileged system user for running `zebrad`.
193-
ARG USER
194-
ENV USER=${USER}
195-
196-
# System users have no home dirs, but we set one for users' convenience.
197-
ARG HOME
198-
WORKDIR ${HOME}
199-
194+
# Create a non-privileged user for running `zebrad`.
195+
#
200196
# We use a high UID/GID (10001) to avoid overlap with host system users.
201197
# This reduces the risk of container user namespace conflicts with host accounts,
202198
# which could potentially lead to privilege escalation if a container escape occurs.
@@ -213,10 +209,16 @@ ARG UID
213209
ENV UID=${UID}
214210
ARG GID
215211
ENV GID=${GID}
212+
ARG HOME
213+
ENV HOME=${HOME}
214+
ARG USER
215+
ENV USER=${USER}
216216

217217
RUN addgroup --gid ${GID} ${USER} && \
218218
adduser --gid ${GID} --uid ${UID} --home ${HOME} ${USER}
219219

220+
WORKDIR ${HOME}
221+
220222
# We set the default locations of the conf and cache dirs according to the XDG
221223
# spec: https://specifications.freedesktop.org/basedir-spec/latest/
222224

0 commit comments

Comments
 (0)