Skip to content

Commit 469ffde

Browse files
committed
Add docker environment for containerized tests
1 parent 06efe7e commit 469ffde

5 files changed

Lines changed: 694 additions & 0 deletions

File tree

docker/.dockerignore

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Ignore unnecessary files during Docker build
2+
3+
# Git
4+
.git/
5+
.gitignore
6+
.github/
7+
8+
# Python
9+
__pycache__/
10+
*.py[cod]
11+
*$py.class
12+
*.so
13+
.Python
14+
*.egg-info/
15+
dist/
16+
build/
17+
*.egg
18+
19+
# Virtual environments
20+
.venv/
21+
venv/
22+
ENV/
23+
env/
24+
25+
# Testing artifacts
26+
run_workdir/
27+
.artifacts/
28+
.cli_coverage/
29+
.reports/
30+
allure-results/
31+
allure-results.tar.xz
32+
testrun-report.*
33+
*.log
34+
*.json.log
35+
36+
# IDE
37+
.idea/
38+
.vscode/
39+
*.swp
40+
*.swo
41+
*~
42+
43+
# Nix
44+
result
45+
result-*
46+
47+
# Documentation
48+
docs/_build/
49+
*.md
50+
51+
# Temporary files
52+
*.tmp
53+
*.bak
54+
.DS_Store
55+
56+
# Scripts output
57+
scripts/destination/
58+
scripts/destination_working/
59+
60+
# Coverage
61+
.coverage
62+
htmlcov/
63+
cli_coverage.json
64+
requirements_coverage.json
65+
66+
# CI specific
67+
.bin/

docker/Dockerfile

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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

Comments
 (0)