From ac87850ea341ed7cc8071792c2cc7a891a007980 Mon Sep 17 00:00:00 2001 From: Gabriel Radureau Date: Wed, 8 Apr 2026 10:43:05 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20use=20simple=20docker=20r?= =?UTF-8?q?un=20with=20CACHE=5FIMAGE=20variable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci-cd.yaml | 70 ++++++++++++------------------------- 1 file changed, 22 insertions(+), 48 deletions(-) diff --git a/.gitea/workflows/ci-cd.yaml b/.gitea/workflows/ci-cd.yaml index b1f2984..7cd230c 100644 --- a/.gitea/workflows/ci-cd.yaml +++ b/.gitea/workflows/ci-cd.yaml @@ -124,60 +124,42 @@ jobs: runs-on: ubuntu-latest-ca if: "!contains(github.event.head_commit.message, '[skip ci]') && github.actor != 'ci-bot'" + container: + image: ${{ env.CI_REGISTRY }}/${{ env.GITEA_ORG }}/${{ env.GITEA_REPO }}-build-cache:${{ needs.build-cache.outputs.deps_hash }} + + services: + postgres: + image: postgres:15 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: dance_lessons_coach_bdd_test + 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 - - name: Set up build environment run: | - IMAGE_NAME="${{ env.CI_REGISTRY }}/${{ env.GITEA_ORG }}/${{ env.GITEA_REPO }}-build-cache:${{ needs.build-cache.outputs.deps_hash }}" - echo "Build cache image: $IMAGE_NAME" - echo "CACHE_IMAGE=$IMAGE_NAME" >> $GITHUB_ENV + echo "Build cache image: ${{ env.CI_REGISTRY }}/${{ env.GITEA_ORG }}/${{ env.GITEA_REPO }}-build-cache:${{ needs.build-cache.outputs.deps_hash }}" echo "DEPS_HASH=${{ needs.build-cache.outputs.deps_hash }}" >> $GITHUB_ENV # Cache is guaranteed to be available since build-cache job succeeded echo "✅ Using Docker build cache (guaranteed by build-cache job)" echo "CACHE_AVAILABLE=true" >> $GITHUB_ENV - - - name: Export DEPS_HASH for Docker Compose - run: echo "DEPS_HASH=${{ needs.build-cache.outputs.deps_hash }}" >> $GITHUB_ENV - - name: Generate Swagger Docs using Docker - run: docker run --rm -v "./:/workspace" -w /workspace $CACHE_IMAGE sh -c "cd /workspace/pkg/server && go generate" + - name: Generate Swagger Docs + run: cd /workspace/pkg/server && go generate - - name: Build all packages using Docker Compose - run: cd /workspace/arcodange/dance-lessons-coach && docker compose -f docker-compose.build.yml run --rm build-cache sh -c "go build ./..." + - name: Build all packages + run: go build ./... - name: Wait for PostgreSQL to be ready run: | echo "Waiting for PostgreSQL to be ready..." for i in {1..30}; do - if pg_isready -h localhost -p 5432 -U postgres -d dance_lessons_coach_bdd_test; then + if pg_isready -h postgres -p 5432 -U postgres -d dance_lessons_coach_bdd_test; then echo "✅ PostgreSQL is ready!" break fi @@ -186,23 +168,15 @@ jobs: done # Verify PostgreSQL is accessible - if ! pg_isready -h localhost -p 5432 -U postgres -d dance_lessons_coach_bdd_test; then + if ! pg_isready -h postgres -p 5432 -U postgres -d dance_lessons_coach_bdd_test; then echo "❌ PostgreSQL failed to start" exit 1 fi - - name: Run tests with coverage using Docker Compose + - name: Run tests with coverage run: | - 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 \ - -w /workspace \ - build-cache \ - sh -c "go test ./... -coverprofile=coverage.out -v && go tool cover -func=coverage.out > coverage.txt" + echo "Running tests with PostgreSQL service..." + go test ./... -coverprofile=coverage.out -v && go tool cover -func=coverage.out > coverage.txt # Extract coverage percentage COVERAGE=$(grep "total:" coverage.txt | grep -oP '\d+\.\d+' | head -1) @@ -220,7 +194,7 @@ jobs: run: swag fmt - name: Build binaries - run: docker compose -f docker-compose.build.yml exec -w /workspace build-cache sh -c "./scripts/build.sh" + run: ./scripts/build.sh # NOTE: Artifact upload disabled - actions/upload-artifact@v4 not available on Gitea # TODO: Replace with Gitea-specific upload action when available