🔧 chore: align local CI/CD script with Gitea workflow
- Add dependency hash calculation matching CI workflow - Add Docker cache detection and usage - Add PostgreSQL service with Docker Compose - Execute commands in Docker Compose containers when cache available - Update test summary to reflect new workflow matching Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -21,48 +21,139 @@ if ! command -v docker >/dev/null 2>&1; then
|
|||||||
HAS_DOCKER=false
|
HAS_DOCKER=false
|
||||||
else
|
else
|
||||||
HAS_DOCKER=true
|
HAS_DOCKER=true
|
||||||
|
|
||||||
|
# Check for docker compose plugin
|
||||||
|
if ! docker compose version >/dev/null 2>&1; then
|
||||||
|
echo "⚠️ Docker Compose plugin not found. Installing..."
|
||||||
|
sudo apt-get update && sudo apt-get install -y docker-compose-plugin
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "✅ Environment ready"
|
echo "✅ Environment ready"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# 2. Install dependencies
|
# 2. Calculate dependency hash (match CI workflow)
|
||||||
echo "2. Installing dependencies..."
|
echo "2. Calculating dependency hash..."
|
||||||
go mod tidy
|
DEPS_HASH=$(sha256sum go.mod go.sum | sha256sum | cut -d' ' -f1 | head -c 12)
|
||||||
echo "✅ Dependencies installed"
|
echo "Dependency hash: $DEPS_HASH"
|
||||||
|
echo "✅ Dependency hash calculated"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# 3. Install swag and generate docs
|
# 3. Check for Docker cache
|
||||||
echo "3. Generating Swagger documentation..."
|
echo "3. Checking for Docker build cache..."
|
||||||
if [ ! -f pkg/server/docs/swagger.json ]; then
|
if [ "$HAS_DOCKER" = true ]; then
|
||||||
echo "📝 Generating Swagger docs..."
|
IMAGE_NAME="gitea.arcodange.lab/arcodange/dance-lessons-coach-build-cache:$DEPS_HASH"
|
||||||
go install github.com/swaggo/swag/cmd/swag@latest
|
|
||||||
cd pkg/server && go generate
|
# Try to pull the cache image
|
||||||
cd ../..
|
if docker pull "$IMAGE_NAME" >/dev/null 2>&1; then
|
||||||
echo "✅ Swagger documentation generated"
|
echo "✅ Cache hit - using existing build cache"
|
||||||
|
USE_DOCKER_CACHE=true
|
||||||
else
|
else
|
||||||
echo "✅ Swagger documentation already exists"
|
echo "⚠️ Cache miss - will build without cache"
|
||||||
|
USE_DOCKER_CACHE=false
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "⚠️ Docker not available - running natively"
|
||||||
|
USE_DOCKER_CACHE=false
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# 4. Build and test
|
# 4. Start PostgreSQL with Docker Compose
|
||||||
echo "4. Building and testing..."
|
echo "4. Starting PostgreSQL..."
|
||||||
|
if [ "$HAS_DOCKER" = true ]; then
|
||||||
|
docker compose -f docker-compose.yml up -d postgres
|
||||||
|
|
||||||
|
# Wait for PostgreSQL to be ready
|
||||||
|
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
|
||||||
|
|
||||||
|
# Set PostgreSQL environment variables
|
||||||
|
export PGHOST="dance-lessons-coach-postgres"
|
||||||
|
export PGPORT=5432
|
||||||
|
export PGUSER=postgres
|
||||||
|
export PGPASSWORD=postgres
|
||||||
|
export PGDATABASE=dance_lessons_coach_bdd_test
|
||||||
|
else
|
||||||
|
echo "⚠️ Docker not available - PostgreSQL tests will be skipped"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# 5. Install dependencies
|
||||||
|
echo "5. Installing dependencies..."
|
||||||
|
if [ "$USE_DOCKER_CACHE" = true ]; then
|
||||||
|
echo "Running in Docker Compose container..."
|
||||||
|
docker compose -f docker-compose.build.yml exec -w /workspace build-cache sh -c "go mod tidy"
|
||||||
|
else
|
||||||
|
echo "Running natively..."
|
||||||
|
go mod tidy
|
||||||
|
fi
|
||||||
|
echo "✅ Dependencies installed"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# 6. Generate Swagger Docs
|
||||||
|
echo "6. Generating Swagger documentation..."
|
||||||
|
if [ "$USE_DOCKER_CACHE" = 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
|
||||||
|
echo "Running natively..."
|
||||||
|
cd pkg/server && go generate
|
||||||
|
cd ../..
|
||||||
|
fi
|
||||||
|
echo "✅ Swagger documentation generated"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# 7. Build and test
|
||||||
|
echo "7. Building and testing..."
|
||||||
|
if [ "$USE_DOCKER_CACHE" = true ]; then
|
||||||
|
echo "Running in Docker Compose container..."
|
||||||
|
docker compose -f docker-compose.build.yml exec -w /workspace build-cache sh -c "go build ./..."
|
||||||
|
else
|
||||||
|
echo "Running natively..."
|
||||||
go build ./...
|
go build ./...
|
||||||
|
fi
|
||||||
echo "✅ Code compiled successfully"
|
echo "✅ Code compiled successfully"
|
||||||
|
|
||||||
|
if [ "$USE_DOCKER_CACHE" = true ]; then
|
||||||
|
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"
|
||||||
|
else
|
||||||
|
echo "Running natively..."
|
||||||
go test ./... -cover -v
|
go test ./... -cover -v
|
||||||
|
fi
|
||||||
echo "✅ Tests passed"
|
echo "✅ Tests passed"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# 5. Build binaries
|
# 8. Build binaries
|
||||||
echo "5. Building binaries..."
|
echo "8. Building binaries..."
|
||||||
|
if [ "$USE_DOCKER_CACHE" = true ]; then
|
||||||
|
echo "Running in Docker Compose container..."
|
||||||
|
docker compose -f docker-compose.build.yml exec -w /workspace build-cache sh -c "./scripts/build.sh"
|
||||||
|
else
|
||||||
|
echo "Running natively..."
|
||||||
./scripts/build.sh
|
./scripts/build.sh
|
||||||
|
fi
|
||||||
echo "✅ Binaries built"
|
echo "✅ Binaries built"
|
||||||
ls -la bin/
|
ls -la bin/
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# 6. Version bump simulation
|
# 9. Version bump simulation
|
||||||
echo "6. Version bump simulation..."
|
echo "9. Version bump simulation..."
|
||||||
LAST_COMMIT=$(git log -1 --pretty=%B | head -1)
|
LAST_COMMIT=$(git log -1 --pretty=%B | head -1)
|
||||||
echo "Last commit: $LAST_COMMIT"
|
echo "Last commit: $LAST_COMMIT"
|
||||||
|
|
||||||
@@ -260,6 +351,9 @@ echo "✅ LOCAL CI/CD TEST COMPLETE"
|
|||||||
echo "==========================="
|
echo "==========================="
|
||||||
echo ""
|
echo ""
|
||||||
echo "📋 What was tested:"
|
echo "📋 What was tested:"
|
||||||
|
echo " ✅ Dependency hash calculation (matching CI workflow)"
|
||||||
|
echo " ✅ Docker cache detection and usage"
|
||||||
|
echo " ✅ PostgreSQL service with Docker Compose"
|
||||||
echo " ✅ Go dependencies installation"
|
echo " ✅ Go dependencies installation"
|
||||||
echo " ✅ Swagger documentation generation"
|
echo " ✅ Swagger documentation generation"
|
||||||
echo " ✅ Code compilation"
|
echo " ✅ Code compilation"
|
||||||
@@ -275,5 +369,6 @@ echo " Push to main branch to trigger full CI/CD pipeline"
|
|||||||
echo " Docker image will be built and pushed to Gitea Container Registry"
|
echo " Docker image will be built and pushed to Gitea Container Registry"
|
||||||
echo ""
|
echo ""
|
||||||
echo "💡 Local testing complete! Your changes are ready for CI/CD."
|
echo "💡 Local testing complete! Your changes are ready for CI/CD."
|
||||||
|
echo "💡 This script now matches the Gitea workflow structure and behavior."
|
||||||
# ⚠️ IMPORTANT: Local Dockerfile.prod uses 'latest' tag for testing only
|
# ⚠️ IMPORTANT: Local Dockerfile.prod uses 'latest' tag for testing only
|
||||||
# ✅ CI/CD workflow generates correct Dockerfile.prod with dependency hash
|
# ✅ CI/CD workflow generates correct Dockerfile.prod with dependency hash
|
||||||
|
|||||||
Reference in New Issue
Block a user