🔄 fix: simplify Docker cache approach and integrate properly
Some checks failed
CI/CD Pipeline / CI Pipeline (push) Has been cancelled
CI/CD Pipeline / Build Docker Cache (push) Has started running

This commit is contained in:
2026-04-07 08:36:18 +02:00
parent 816e1b7bc8
commit 36823ac112
2 changed files with 51 additions and 13 deletions

View File

@@ -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
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)

View File

@@ -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
# 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