✨ 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:
@@ -124,29 +124,38 @@ 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'"
|
||||||
|
|
||||||
services:
|
steps:
|
||||||
postgres:
|
- name: Checkout code
|
||||||
image: postgres:15
|
uses: actions/checkout@v4
|
||||||
env:
|
|
||||||
POSTGRES_USER: postgres
|
- name: Install Docker Compose
|
||||||
POSTGRES_PASSWORD: postgres
|
run: sudo apt-get update && sudo apt-get install -y docker-compose-plugin
|
||||||
POSTGRES_DB: dance_lessons_coach_bdd_test
|
|
||||||
ports:
|
- name: Start PostgreSQL with Docker Compose
|
||||||
- 5432:5432
|
run: docker compose -f docker-compose.yml up -d postgres
|
||||||
options: >-
|
|
||||||
--health-cmd pg_isready
|
- name: Wait for PostgreSQL to be ready
|
||||||
--health-interval 10s
|
run: |
|
||||||
--health-timeout 5s
|
echo "Waiting for PostgreSQL to be ready..."
|
||||||
--health-retries 5
|
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:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
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
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.CI_REGISTRY }}
|
registry: ${{ env.CI_REGISTRY }}
|
||||||
@@ -168,21 +177,29 @@ jobs:
|
|||||||
echo "CACHE_AVAILABLE=false" >> $GITHUB_ENV
|
echo "CACHE_AVAILABLE=false" >> $GITHUB_ENV
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Generate Swagger Docs using Docker cache
|
- name: Start build cache container with Docker Compose
|
||||||
run: |
|
run: |
|
||||||
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
||||||
echo "Running in Docker cache..."
|
echo "Starting build cache container..."
|
||||||
docker run --rm -v "$(pwd):/workspace" -w /workspace/pkg/server ${{ env.CACHE_IMAGE }} sh -c "go generate"
|
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
|
else
|
||||||
echo "Running natively..."
|
echo "Running natively..."
|
||||||
cd pkg/server && go generate
|
cd pkg/server && go generate
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Build all packages using Docker cache
|
- name: Build all packages using Docker Compose
|
||||||
run: |
|
run: |
|
||||||
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
||||||
echo "Running in Docker cache..."
|
echo "Running in Docker Compose container..."
|
||||||
docker run --rm -v "$(pwd):/workspace" -w /workspace ${{ env.CACHE_IMAGE }} sh -c "go build ./..."
|
docker compose -f docker-compose.build.yml exec -w /workspace build-cache sh -c "go build ./..."
|
||||||
else
|
else
|
||||||
echo "Running natively..."
|
echo "Running natively..."
|
||||||
go build ./...
|
go build ./...
|
||||||
@@ -206,24 +223,22 @@ jobs:
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Run tests with coverage using Docker cache
|
- name: Run tests with coverage using Docker Compose
|
||||||
run: |
|
run: |
|
||||||
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
||||||
echo "Running in Docker cache with PostgreSQL support..."
|
echo "Running in Docker Compose container with PostgreSQL..."
|
||||||
docker run --rm \
|
docker compose -f docker-compose.build.yml exec \
|
||||||
--network host \
|
-e PGHOST=dance-lessons-coach-postgres \
|
||||||
-v "$(pwd):/workspace" \
|
|
||||||
-w /workspace \
|
|
||||||
-e PGHOST=localhost \
|
|
||||||
-e PGPORT=5432 \
|
-e PGPORT=5432 \
|
||||||
-e PGUSER=postgres \
|
-e PGUSER=postgres \
|
||||||
-e PGPASSWORD=postgres \
|
-e PGPASSWORD=postgres \
|
||||||
-e PGDATABASE=dance_lessons_coach_bdd_test \
|
-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"
|
sh -c "go test ./... -coverprofile=coverage.out -v && go tool cover -func=coverage.out > coverage.txt"
|
||||||
else
|
else
|
||||||
echo "Running natively with PostgreSQL..."
|
echo "Running natively with Docker Compose PostgreSQL..."
|
||||||
export PGHOST=localhost
|
export PGHOST=dance-lessons-coach-postgres
|
||||||
export PGPORT=5432
|
export PGPORT=5432
|
||||||
export PGUSER=postgres
|
export PGUSER=postgres
|
||||||
export PGPASSWORD=postgres
|
export PGPASSWORD=postgres
|
||||||
|
|||||||
16
docker-compose.build.yml
Normal file
16
docker-compose.build.yml
Normal 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
|
||||||
Reference in New Issue
Block a user