Use Dockerfiles to perform tests
Some checks failed
CI/CD Pipeline (Fully Isolated DinD) / Run Tests (DinD) (push) Failing after 35s
CI/CD Pipeline (Fully Isolated DinD) / Build and Push Docker Images (DinD) (push) Has been skipped
CI/CD Pipeline (Fully Isolated DinD) / Deploy to Production (push) Has been skipped

This commit is contained in:
continuist 2025-07-05 13:15:02 -04:00
parent 62e3f370b8
commit 9d37a795a0
6 changed files with 91 additions and 7 deletions

View file

@ -77,15 +77,48 @@ jobs:
# Copy workspace to DinD container # Copy workspace to DinD container
docker exec ci-dind rm -rf /workspace/* /workspace/.* 2>/dev/null || true docker exec ci-dind rm -rf /workspace/* /workspace/.* 2>/dev/null || true
docker cp /tmp/ci-workspace/. ci-dind:/workspace/ docker cp /tmp/ci-workspace/. ci-dind:/workspace/
- name: Start testing environment
run: |
# Start testing environment using dedicated compose file inside DinD # Start testing environment using dedicated compose file inside DinD
docker exec ci-dind docker compose -f /workspace/docker-compose.test.yml up -d echo "Starting testing environment..."
docker exec ci-dind docker compose -f /workspace/docker-compose.test.yml up -d --build
# Wait for all services to be ready # Wait for all services to be ready with better error handling
echo "Waiting for testing environment to be ready..." echo "Waiting for testing environment to be ready..."
timeout 120 bash -c 'until docker exec ci-dind docker compose -f /workspace/docker-compose.test.yml ps | grep -q "healthy" && docker exec ci-dind docker compose -f /workspace/docker-compose.test.yml ps | grep -q "Up"; do sleep 2; done' MAX_WAIT=180
WAIT_COUNT=0
while [ $WAIT_COUNT -lt $MAX_WAIT ]; do
# Check if all containers are running
RUNNING_CONTAINERS=$(docker exec ci-dind docker compose -f /workspace/docker-compose.test.yml ps -q | wc -l)
EXPECTED_CONTAINERS=3 # postgres, rust-toolchain, node-toolchain
if [ "$RUNNING_CONTAINERS" -eq "$EXPECTED_CONTAINERS" ]; then
echo "All containers are running"
break
else
echo "Waiting for containers to start... ($RUNNING_CONTAINERS/$EXPECTED_CONTAINERS running)"
sleep 2
WAIT_COUNT=$((WAIT_COUNT + 2))
fi
done
if [ $WAIT_COUNT -ge $MAX_WAIT ]; then
echo "ERROR: Timeout waiting for containers to start"
echo "Container status:"
docker exec ci-dind docker compose -f /workspace/docker-compose.test.yml ps
echo "Container logs:"
docker exec ci-dind docker compose -f /workspace/docker-compose.test.yml logs
exit 1
fi
# Additional wait for PostgreSQL to be healthy
echo "Waiting for PostgreSQL to be healthy..."
timeout 60 bash -c 'until docker exec ci-dind docker exec ci-cd-test-postgres pg_isready -h localhost -p 5432 -U postgres; do sleep 1; done'
# Verify all containers are running # Verify all containers are running
echo "Final container status:"
docker exec ci-dind docker compose -f /workspace/docker-compose.test.yml ps docker exec ci-dind docker compose -f /workspace/docker-compose.test.yml ps
- name: Install SQLx CLI in Rust container - name: Install SQLx CLI in Rust container

View file

@ -1741,6 +1741,8 @@ Go to your Forgejo repository and add these secrets in **Settings → Secrets an
- `DOMAIN`: Your domain name (e.g., `example.com`) - `DOMAIN`: Your domain name (e.g., `example.com`)
- `EMAIL`: Your email for SSL certificate notifications - `EMAIL`: Your email for SSL certificate notifications
**Note**: This setup uses custom Dockerfiles for testing environments instead of pulling from external registries, eliminating Docker Hub rate limiting issues and providing better control over the testing environment.
### Step 18: Test Complete Pipeline ### Step 18: Test Complete Pipeline
#### 18.1 Trigger a Test Build #### 18.1 Trigger a Test Build

View file

@ -0,0 +1,16 @@
# PostgreSQL testing environment for CI/CD
FROM postgres:15-alpine
# Install additional tools if needed
RUN apk add --no-cache curl
# Copy any custom configuration if needed
# COPY postgresql.conf /etc/postgresql/postgresql.conf
# Keep the default PostgreSQL configuration
# The image will use the default postgresql.conf
# Expose the default PostgreSQL port
EXPOSE 5432
# Use the default PostgreSQL entrypoint and command

View file

@ -0,0 +1,14 @@
# Rust testing environment for CI/CD
FROM rust:1.75-slim
# Install additional tools needed for testing
RUN apt-get update && apt-get install -y \
postgresql-client \
curl \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /workspace/backend
# Keep container running for testing
CMD ["sleep", "infinity"]

View file

@ -3,7 +3,9 @@ version: '3.8'
services: services:
# PostgreSQL for testing # PostgreSQL for testing
postgres: postgres:
image: postgres:15-alpine build:
context: ./backend
dockerfile: Dockerfile.test-postgres
container_name: ci-cd-test-postgres container_name: ci-cd-test-postgres
restart: unless-stopped restart: unless-stopped
environment: environment:
@ -22,7 +24,9 @@ services:
# Rust toolchain container for backend testing # Rust toolchain container for backend testing
rust-toolchain: rust-toolchain:
image: rust:1.75-slim build:
context: ./backend
dockerfile: Dockerfile.test-rust
container_name: ci-cd-test-rust container_name: ci-cd-test-rust
restart: unless-stopped restart: unless-stopped
volumes: volumes:
@ -37,7 +41,9 @@ services:
# Node.js toolchain container for frontend testing # Node.js toolchain container for frontend testing
node-toolchain: node-toolchain:
image: node:20-slim build:
context: ./frontend
dockerfile: Dockerfile.test-node
container_name: ci-cd-test-node container_name: ci-cd-test-node
restart: unless-stopped restart: unless-stopped
volumes: volumes:

View file

@ -0,0 +1,13 @@
# Node.js testing environment for CI/CD
FROM node:20-slim
# Install additional tools needed for testing
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /workspace/frontend
# Keep container running for testing
CMD ["sleep", "infinity"]