From 36823ac1126d5db88dded1888d31aa514a7ab30b Mon Sep 17 00:00:00 2001 From: Gabriel Radureau Date: Tue, 7 Apr 2026 08:36:18 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=84=20fix:=20simplify=20Docker=20cache?= =?UTF-8?q?=20approach=20and=20integrate=20properly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci-cd.yaml | 47 ++++++++++++++++++++++++++++++------- Dockerfile.build | 17 ++++++++++---- 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/.gitea/workflows/ci-cd.yaml b/.gitea/workflows/ci-cd.yaml index 8bf5f8d..24dbd6a 100644 --- a/.gitea/workflows/ci-cd.yaml +++ b/.gitea/workflows/ci-cd.yaml @@ -137,11 +137,19 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.PACKAGES_TOKEN }} - - name: Pull Docker build cache + - 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 "Using build cache image: $IMAGE_NAME" - docker pull "$IMAGE_NAME" || echo "Cache pull failed, will use regular setup" + echo "Build cache image: $IMAGE_NAME" + + # Try to use Docker cache if available + if docker pull "$IMAGE_NAME" >/dev/null 2>&1; then + echo "✅ Using Docker build cache" + echo "CACHE_AVAILABLE=true" >> $GITHUB_ENV + else + echo "⚠️ Building without cache (first run or new dependencies)" + echo "CACHE_AVAILABLE=false" >> $GITHUB_ENV + fi - name: Set up Go uses: actions/setup-go@v4 @@ -157,16 +165,39 @@ jobs: run: go install github.com/swaggo/swag/cmd/swag@latest - name: Generate Swagger Docs - run: cd pkg/server && go generate + run: | + if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then + echo "Running in Docker cache..." + docker run --rm -v "$(pwd):/workspace" -w /workspace dance-lessons-coach-build-cache:latest sh -c "cd pkg/server && go generate" + else + echo "Running natively..." + cd pkg/server && go generate + fi - name: Build all packages - run: go build ./... + run: | + if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then + echo "Running in Docker cache..." + docker run --rm -v "$(pwd):/workspace" -w /workspace dance-lessons-coach-build-cache:latest sh -c "go build ./..." + else + echo "Running natively..." + go build ./... + fi - name: Run tests with coverage run: | - # Run tests with coverage - go test ./... -coverprofile=coverage.out -v - go tool cover -func=coverage.out > coverage.txt + if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then + echo "Running in Docker cache..." + docker run --rm \ + -v "$(pwd):/workspace" \ + -w /workspace \ + dance-lessons-coach-build-cache:latest \ + sh -c "go test ./... -coverprofile=coverage.out -v && go tool cover -func=coverage.out > coverage.txt" + else + echo "Running natively..." + go test ./... -coverprofile=coverage.out -v + go tool cover -func=coverage.out > coverage.txt + fi # Extract coverage percentage COVERAGE=$(grep "total:" coverage.txt | grep -oP '\d+\.\d+' | head -1) diff --git a/Dockerfile.build b/Dockerfile.build index 09781ea..75628a7 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -31,9 +31,16 @@ RUN go install github.com/swaggo/swag/cmd/swag@latest && \ COPY go.mod go.sum ./ RUN go mod download && go mod verify -# Copy the rest of the source (this happens in CI) -# COPY . . +# Simple build environment - source code is mounted at runtime +WORKDIR /workspace -# Build command (will be run in CI) -# RUN go build -o /out/server ./cmd/server && \ -# go build -o /out/greet ./cmd/greet \ No newline at end of file +# Install basic CI tools +RUN apk add --no-cache \ + git \ + bash \ + make \ + gcc \ + musl-dev + +# Pre-download common Go tools +RUN go install github.com/swaggo/swag/cmd/swag@latest \ No newline at end of file