|
| 1 | +# Dockerfile for cardano-node-tests |
| 2 | +# Ready-to-use environment for running tests directly |
| 3 | + |
| 4 | +FROM nixos/nix:2.25.5 |
| 5 | + |
| 6 | +# Set labels |
| 7 | +LABEL maintainer="cardano-node-tests team" |
| 8 | +LABEL description="Functional tests for cardano-node - ready-to-use environment" |
| 9 | + |
| 10 | +# Install system dependencies |
| 11 | +RUN nix-channel --update && \ |
| 12 | + nix-env -iA nixpkgs.bash \ |
| 13 | + nixpkgs.coreutils \ |
| 14 | + nixpkgs.curl \ |
| 15 | + nixpkgs.git \ |
| 16 | + nixpkgs.gnugrep \ |
| 17 | + nixpkgs.gnutar \ |
| 18 | + nixpkgs.jq \ |
| 19 | + nixpkgs.xz \ |
| 20 | + nixpkgs.procps \ |
| 21 | + nixpkgs.findutils \ |
| 22 | + nixpkgs.which \ |
| 23 | + nixpkgs.gnused |
| 24 | + |
| 25 | +# Configure Nix to use IOG cache |
| 26 | +RUN mkdir -p /etc/nix && \ |
| 27 | + echo "extra-substituters = https://cache.iog.io" >> /etc/nix/nix.conf && \ |
| 28 | + echo "extra-trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" >> /etc/nix/nix.conf && \ |
| 29 | + echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf && \ |
| 30 | + echo "accept-flake-config = true" >> /etc/nix/nix.conf && \ |
| 31 | + echo "allow-import-from-derivation = true" >> /etc/nix/nix.conf |
| 32 | + |
| 33 | +# Set working directory |
| 34 | +WORKDIR /work |
| 35 | + |
| 36 | +# Copy project files |
| 37 | +COPY . /work/ |
| 38 | + |
| 39 | +# Set environment variables |
| 40 | +ENV WORKDIR=/work/run_workdir \ |
| 41 | + TMPDIR=/work/run_workdir/tmp \ |
| 42 | + ARTIFACTS_DIR=/work/.artifacts \ |
| 43 | + SCHEDULING_LOG=/work/scheduling.log \ |
| 44 | + PATH_PREPEND=/work/.bin \ |
| 45 | + CARDANO_NODE_SOCKET_PATH=/work/run_workdir/state-cluster0/bft1.socket \ |
| 46 | + CARDANO_NODE_SOCKET_PATH_CI=/work/run_workdir/state-cluster0/bft1.socket |
| 47 | + |
| 48 | +# Pre-build Nix environments to cache dependencies |
| 49 | +RUN nix develop --accept-flake-config .#base --command bash -c 'echo "Base environment ready"' && \ |
| 50 | + nix develop --accept-flake-config .#testenv --command bash -c 'echo "Test environment ready"' |
| 51 | + |
| 52 | +# Create required directories |
| 53 | +RUN mkdir -p "$WORKDIR" "$TMPDIR" "$ARTIFACTS_DIR" /work/.bin && \ |
| 54 | + touch "$SCHEDULING_LOG" |
| 55 | + |
| 56 | +# Set up Python virtual environment with dependencies |
| 57 | +RUN nix develop --accept-flake-config .#testenv --command bash -c '\ |
| 58 | + export WORKDIR=/work/run_workdir && \ |
| 59 | + mkdir -p "$WORKDIR/.venv" && \ |
| 60 | + python3 -m venv "$WORKDIR/.venv" --prompt tests-venv && \ |
| 61 | + . "$WORKDIR/.venv/bin/activate" && \ |
| 62 | + uv sync --active --no-dev \ |
| 63 | + ' |
| 64 | + |
| 65 | +# Build cardano-node binaries and make them available |
| 66 | +RUN nix develop --accept-flake-config .#base --command bash -c '\ |
| 67 | + export WORKDIR=/work/run_workdir && \ |
| 68 | + export PATH_PREPEND=/work/.bin && \ |
| 69 | + . scripts/common.sh && \ |
| 70 | + . .github/source_cardano_node.sh && \ |
| 71 | + cardano_bins_build_all "${NODE_REV:-master}" "" && \ |
| 72 | + cardano_bins_print_path_prepend "" > /work/.path_prepend \ |
| 73 | + ' |
| 74 | + |
| 75 | +# Create entrypoint script that sets up the environment |
| 76 | +RUN cat > /work/entrypoint.sh <<'EOF' |
| 77 | +#!/usr/bin/env bash |
| 78 | +set -e |
| 79 | + |
| 80 | +# Activate Python virtual environment |
| 81 | +source /work/run_workdir/.venv/bin/activate |
| 82 | + |
| 83 | +# Set up PATH with cardano binaries |
| 84 | +if [ -f /work/.path_prepend ]; then |
| 85 | + export PATH="$(cat /work/.path_prepend):${PATH_PREPEND}:${PATH}" |
| 86 | +fi |
| 87 | + |
| 88 | +# Display environment info |
| 89 | +echo "==========================================" |
| 90 | +echo "Cardano Node Tests - Ready Environment" |
| 91 | +echo "==========================================" |
| 92 | +echo "" |
| 93 | +echo "Python virtual environment: ACTIVATED" |
| 94 | +echo "Cardano binaries: AVAILABLE" |
| 95 | +echo "" |
| 96 | +echo "Quick start:" |
| 97 | +echo " pytest cardano_node_tests/tests/ # Run all tests" |
| 98 | +echo " pytest cardano_node_tests/tests/ -m smoke # Run smoke tests" |
| 99 | +echo " ./.github/run_tests.sh testpr # Run PR tests" |
| 100 | +echo "" |
| 101 | +echo "Current directory: $(pwd)" |
| 102 | +echo "==========================================" |
| 103 | +echo "" |
| 104 | + |
| 105 | +# Execute command or start bash |
| 106 | +exec "$@" |
| 107 | +EOF |
| 108 | + |
| 109 | +RUN chmod +x /work/entrypoint.sh |
| 110 | + |
| 111 | +# Set the entrypoint to activate environment |
| 112 | +ENTRYPOINT ["/work/entrypoint.sh"] |
| 113 | + |
| 114 | +# Default command: start bash shell |
| 115 | +CMD ["bash"] |
0 commit comments