Use arguments with Dockerfiles
Some checks are pending
CI/CD Pipeline (Fully Isolated DinD) / Run Tests (DinD) (push) Waiting to run
CI/CD Pipeline (Fully Isolated DinD) / Build and Push Docker Images (DinD) (push) Blocked by required conditions
CI/CD Pipeline (Fully Isolated DinD) / Deploy to Production (push) Blocked by required conditions

This commit is contained in:
continuist 2025-07-12 14:51:52 -04:00
parent 9d37a795a0
commit ab1d377b2d
6 changed files with 77 additions and 5 deletions

View file

@ -78,11 +78,68 @@ jobs:
docker exec ci-dind rm -rf /workspace/* /workspace/.* 2>/dev/null || true
docker cp /tmp/ci-workspace/. ci-dind:/workspace/
- name: Check and prepare Harbor base images
run: |
# Set environment variables
export CI_HOST="${{ secrets.CI_HOST }}"
export APP_NAME="${{ secrets.APP_NAME || 'sharenet' }}"
export HARBOR_CI_USER="${{ secrets.HARBOR_CI_USER }}"
export HARBOR_CI_PASSWORD="${{ secrets.HARBOR_CI_PASSWORD }}"
# Login to Harbor
echo "Logging into Harbor registry..."
echo "$HARBOR_CI_PASSWORD" | docker exec -i ci-dind docker login "$CI_HOST:443" -u "$HARBOR_CI_USER" --password-stdin
# Check if base images exist in Harbor, pull from Docker Hub if not
BASE_IMAGES=("rust:1.75-slim" "node:20-slim" "postgres:15-alpine")
for image in "${BASE_IMAGES[@]}"; do
image_name=$(echo "$image" | cut -d: -f1)
image_tag=$(echo "$image" | cut -d: -f2)
harbor_image="$CI_HOST:443/$APP_NAME/$image_name:$image_tag"
echo "Checking if $harbor_image exists in Harbor..."
# Try to pull from Harbor first
if docker exec ci-dind docker pull "$harbor_image" 2>/dev/null; then
echo "✓ Found $harbor_image in Harbor"
else
echo "✗ $harbor_image not found in Harbor, pulling from Docker Hub..."
# Pull from Docker Hub
if docker exec ci-dind docker pull "$image"; then
echo "✓ Successfully pulled $image from Docker Hub"
# Tag for Harbor
docker exec ci-dind docker tag "$image" "$harbor_image"
# Push to Harbor
if docker exec ci-dind docker push "$harbor_image"; then
echo "✓ Successfully pushed $harbor_image to Harbor"
else
echo "✗ Failed to push $harbor_image to Harbor"
exit 1
fi
else
echo "✗ Failed to pull $image from Docker Hub"
exit 1
fi
fi
done
echo "All base images are ready in Harbor!"
- name: Start testing environment
run: |
# Start testing environment using dedicated compose file inside DinD
echo "Starting testing environment..."
docker exec ci-dind docker compose -f /workspace/docker-compose.test.yml up -d --build
# Set environment variables for docker-compose
export CI_HOST="${{ secrets.CI_HOST }}"
export APP_NAME="${{ secrets.APP_NAME || 'sharenet' }}"
# Start the testing environment with build args
docker exec ci-dind sh -c "export CI_HOST='$CI_HOST' && export APP_NAME='$APP_NAME' && docker compose -f /workspace/docker-compose.test.yml up -d --build"
# Wait for all services to be ready with better error handling
echo "Waiting for testing environment to be ready..."

View file

@ -1741,7 +1741,7 @@ 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.
**Note**: This setup uses custom Dockerfiles for testing environments with base images stored in Harbor registry. The CI pipeline automatically checks if base images exist in Harbor and pulls them from Docker Hub only when needed, eliminating rate limiting issues and providing better control over the testing environment.
### Step 18: Test Complete Pipeline

View file

@ -1,5 +1,7 @@
# PostgreSQL testing environment for CI/CD
FROM postgres:15-alpine
ARG CI_HOST=localhost
ARG APP_NAME=sharenet
FROM ${CI_HOST}:443/${APP_NAME}/postgres:15-alpine
# Install additional tools if needed
RUN apk add --no-cache curl

View file

@ -1,5 +1,7 @@
# Rust testing environment for CI/CD
FROM rust:1.75-slim
ARG CI_HOST=localhost
ARG APP_NAME=sharenet
FROM ${CI_HOST}:443/${APP_NAME}/rust:1.75-slim
# Install additional tools needed for testing
RUN apt-get update && apt-get install -y \

View file

@ -6,6 +6,9 @@ services:
build:
context: ./backend
dockerfile: Dockerfile.test-postgres
args:
CI_HOST: ${CI_HOST:-localhost}
APP_NAME: ${APP_NAME:-sharenet}
container_name: ci-cd-test-postgres
restart: unless-stopped
environment:
@ -27,6 +30,9 @@ services:
build:
context: ./backend
dockerfile: Dockerfile.test-rust
args:
CI_HOST: ${CI_HOST:-localhost}
APP_NAME: ${APP_NAME:-sharenet}
container_name: ci-cd-test-rust
restart: unless-stopped
volumes:
@ -44,6 +50,9 @@ services:
build:
context: ./frontend
dockerfile: Dockerfile.test-node
args:
CI_HOST: ${CI_HOST:-localhost}
APP_NAME: ${APP_NAME:-sharenet}
container_name: ci-cd-test-node
restart: unless-stopped
volumes:

View file

@ -1,5 +1,7 @@
# Node.js testing environment for CI/CD
FROM node:20-slim
ARG CI_HOST=localhost
ARG APP_NAME=sharenet
FROM ${CI_HOST}:443/${APP_NAME}/node:20-slim
# Install additional tools needed for testing
RUN apt-get update && apt-get install -y \