feat: migrate to Docker Compose for build cache management

- Replace docker run commands with docker compose
- Use separate docker-compose.build.yml for build cache
- Maintain PostgreSQL service with Docker Compose
- Ensure consistent container networking

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-04-07 23:15:26 +02:00
parent 4848becbdc
commit 02674dfb50
2 changed files with 65 additions and 34 deletions

View File

@@ -124,29 +124,38 @@ jobs:
runs-on: ubuntu-latest-ca
if: "!contains(github.event.head_commit.message, '[skip ci]') && github.actor != 'ci-bot'"
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: dance_lessons_coach_bdd_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Docker Compose
run: sudo apt-get update && sudo apt-get install -y docker-compose-plugin
- name: Start PostgreSQL with Docker Compose
run: docker compose -f docker-compose.yml up -d postgres
- name: Wait for PostgreSQL to be ready
run: |
echo "Waiting for PostgreSQL to be ready..."
for i in {1..30}; do
if docker exec dance-lessons-coach-postgres pg_isready -U postgres; then
echo "✅ PostgreSQL is ready!"
break
fi
echo "Waiting for PostgreSQL... ($i/30)"
sleep 2
done
# Verify PostgreSQL is accessible
if ! docker exec dance-lessons-coach-postgres pg_isready -U postgres; then
echo "❌ PostgreSQL failed to start"
exit 1
fi
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install PostgreSQL client
run: sudo apt-get update && sudo apt-get install -y postgresql-client
- name: Login to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.CI_REGISTRY }}
@@ -168,21 +177,29 @@ jobs:
echo "CACHE_AVAILABLE=false" >> $GITHUB_ENV
fi
- name: Generate Swagger Docs using Docker cache
- name: Start build cache container with Docker Compose
run: |
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
echo "Running in Docker cache..."
docker run --rm -v "$(pwd):/workspace" -w /workspace/pkg/server ${{ env.CACHE_IMAGE }} sh -c "go generate"
echo "Starting build cache container..."
export DEPS_HASH="${{ needs.build-cache.outputs.deps_hash }}"
docker compose -f docker-compose.build.yml up -d build-cache
fi
- name: Generate Swagger Docs using Docker Compose
run: |
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
echo "Running in Docker Compose container..."
docker compose -f docker-compose.build.yml exec -w /workspace/pkg/server build-cache sh -c "go generate"
else
echo "Running natively..."
cd pkg/server && go generate
fi
- name: Build all packages using Docker cache
- name: Build all packages using Docker Compose
run: |
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
echo "Running in Docker cache..."
docker run --rm -v "$(pwd):/workspace" -w /workspace ${{ env.CACHE_IMAGE }} sh -c "go build ./..."
echo "Running in Docker Compose container..."
docker compose -f docker-compose.build.yml exec -w /workspace build-cache sh -c "go build ./..."
else
echo "Running natively..."
go build ./...
@@ -206,24 +223,22 @@ jobs:
exit 1
fi
- name: Run tests with coverage using Docker cache
- name: Run tests with coverage using Docker Compose
run: |
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
echo "Running in Docker cache with PostgreSQL support..."
docker run --rm \
--network host \
-v "$(pwd):/workspace" \
-w /workspace \
-e PGHOST=localhost \
echo "Running in Docker Compose container with PostgreSQL..."
docker compose -f docker-compose.build.yml exec \
-e PGHOST=dance-lessons-coach-postgres \
-e PGPORT=5432 \
-e PGUSER=postgres \
-e PGPASSWORD=postgres \
-e PGDATABASE=dance_lessons_coach_bdd_test \
${{ env.CACHE_IMAGE }} \
-w /workspace \
build-cache \
sh -c "go test ./... -coverprofile=coverage.out -v && go tool cover -func=coverage.out > coverage.txt"
else
echo "Running natively with PostgreSQL..."
export PGHOST=localhost
echo "Running natively with Docker Compose PostgreSQL..."
export PGHOST=dance-lessons-coach-postgres
export PGPORT=5432
export PGUSER=postgres
export PGPASSWORD=postgres

16
docker-compose.build.yml Normal file
View File

@@ -0,0 +1,16 @@
services:
build-cache:
image: gitea.arcodange.lab/arcodange/dance-lessons-coach-build-cache:${DEPS_HASH}
build:
context: .
dockerfile: docker/Dockerfile.build
args:
DEPS_HASH: ${DEPS_HASH}
container_name: dance-lessons-coach-build-cache
volumes:
- .:/workspace
working_dir: /workspace
environment:
- GOPATH=/go
- PATH=/go/bin:/usr/local/go/bin:/usr/local/bin:/usr/bin:/bin
restart: unless-stopped