🐛 fix: use simple docker run with CACHE_IMAGE variable

This commit is contained in:
2026-04-08 10:43:05 +02:00
parent dc2662e960
commit ac87850ea3

View File

@@ -124,60 +124,42 @@ jobs:
runs-on: ubuntu-latest-ca runs-on: ubuntu-latest-ca
if: "!contains(github.event.head_commit.message, '[skip ci]') && github.actor != 'ci-bot'" 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: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 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 - name: Set up build environment
run: | run: |
IMAGE_NAME="${{ env.CI_REGISTRY }}/${{ env.GITEA_ORG }}/${{ env.GITEA_REPO }}-build-cache:${{ needs.build-cache.outputs.deps_hash }}" echo "Build cache image: ${{ 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 "DEPS_HASH=${{ needs.build-cache.outputs.deps_hash }}" >> $GITHUB_ENV echo "DEPS_HASH=${{ needs.build-cache.outputs.deps_hash }}" >> $GITHUB_ENV
# Cache is guaranteed to be available since build-cache job succeeded # Cache is guaranteed to be available since build-cache job succeeded
echo "✅ Using Docker build cache (guaranteed by build-cache job)" echo "✅ Using Docker build cache (guaranteed by build-cache job)"
echo "CACHE_AVAILABLE=true" >> $GITHUB_ENV echo "CACHE_AVAILABLE=true" >> $GITHUB_ENV
- name: Export DEPS_HASH for Docker Compose - name: Generate Swagger Docs
run: echo "DEPS_HASH=${{ needs.build-cache.outputs.deps_hash }}" >> $GITHUB_ENV run: cd /workspace/pkg/server && go generate
- name: Generate Swagger Docs using Docker - name: Build all packages
run: docker run --rm -v "./:/workspace" -w /workspace $CACHE_IMAGE sh -c "cd /workspace/pkg/server && go generate" run: go build ./...
- 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: Wait for PostgreSQL to be ready - name: Wait for PostgreSQL to be ready
run: | run: |
echo "Waiting for PostgreSQL to be ready..." echo "Waiting for PostgreSQL to be ready..."
for i in {1..30}; do 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!" echo "✅ PostgreSQL is ready!"
break break
fi fi
@@ -186,23 +168,15 @@ jobs:
done done
# Verify PostgreSQL is accessible # 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" echo "❌ PostgreSQL failed to start"
exit 1 exit 1
fi fi
- name: Run tests with coverage using Docker Compose - name: Run tests with coverage
run: | run: |
echo "Running in Docker Compose container with PostgreSQL..." echo "Running tests with PostgreSQL service..."
docker compose -f docker-compose.build.yml exec \ go test ./... -coverprofile=coverage.out -v && go tool cover -func=coverage.out > coverage.txt
-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"
# Extract coverage percentage # Extract coverage percentage
COVERAGE=$(grep "total:" coverage.txt | grep -oP '\d+\.\d+' | head -1) COVERAGE=$(grep "total:" coverage.txt | grep -oP '\d+\.\d+' | head -1)
@@ -220,7 +194,7 @@ jobs:
run: swag fmt run: swag fmt
- name: Build binaries - 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 # NOTE: Artifact upload disabled - actions/upload-artifact@v4 not available on Gitea
# TODO: Replace with Gitea-specific upload action when available # TODO: Replace with Gitea-specific upload action when available