diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index 6b80982..22b2a32 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -77,15 +77,48 @@ jobs: # Copy workspace to DinD container docker exec ci-dind rm -rf /workspace/* /workspace/.* 2>/dev/null || true docker cp /tmp/ci-workspace/. ci-dind:/workspace/ - + + - name: Start testing environment + run: | # 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..." - 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 + echo "Final container status:" docker exec ci-dind docker compose -f /workspace/docker-compose.test.yml ps - name: Install SQLx CLI in Rust container diff --git a/CI_CD_PIPELINE_SETUP_GUIDE.md b/CI_CD_PIPELINE_SETUP_GUIDE.md index 84e6d66..7642698 100644 --- a/CI_CD_PIPELINE_SETUP_GUIDE.md +++ b/CI_CD_PIPELINE_SETUP_GUIDE.md @@ -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`) - `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 #### 18.1 Trigger a Test Build diff --git a/backend/Dockerfile.test-postgres b/backend/Dockerfile.test-postgres new file mode 100644 index 0000000..bdfde94 --- /dev/null +++ b/backend/Dockerfile.test-postgres @@ -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 \ No newline at end of file diff --git a/backend/Dockerfile.test-rust b/backend/Dockerfile.test-rust new file mode 100644 index 0000000..fb0746b --- /dev/null +++ b/backend/Dockerfile.test-rust @@ -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"] \ No newline at end of file diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 7500175..77df40c 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -3,7 +3,9 @@ version: '3.8' services: # PostgreSQL for testing postgres: - image: postgres:15-alpine + build: + context: ./backend + dockerfile: Dockerfile.test-postgres container_name: ci-cd-test-postgres restart: unless-stopped environment: @@ -22,7 +24,9 @@ services: # Rust toolchain container for backend testing rust-toolchain: - image: rust:1.75-slim + build: + context: ./backend + dockerfile: Dockerfile.test-rust container_name: ci-cd-test-rust restart: unless-stopped volumes: @@ -37,7 +41,9 @@ services: # Node.js toolchain container for frontend testing node-toolchain: - image: node:20-slim + build: + context: ./frontend + dockerfile: Dockerfile.test-node container_name: ci-cd-test-node restart: unless-stopped volumes: diff --git a/frontend/Dockerfile.test-node b/frontend/Dockerfile.test-node new file mode 100644 index 0000000..3e4675c --- /dev/null +++ b/frontend/Dockerfile.test-node @@ -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"] \ No newline at end of file