🔧 refactor: simplify local CI/CD script by assuming Docker availability

- Remove conditional Docker availability checks
- Assume Docker is always available (required for workflow)
- Simplify logic flow
- Maintain same functionality but cleaner code
- Match CI/CD workflow assumptions

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-04-07 23:41:15 +02:00
parent 18213f365d
commit 22099d0ac6

View File

@@ -16,18 +16,18 @@ if ! command -v go >/dev/null 2>&1; then
exit 1
fi
# Assume Docker is available (required for this workflow)
if ! command -v docker >/dev/null 2>&1; then
echo "⚠️ Docker not found. Docker build steps will be skipped"
HAS_DOCKER=false
else
HAS_DOCKER=true
echo " Docker is required for this CI/CD workflow"
echo "Please install Docker and Docker Compose plugin"
exit 1
fi
# 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
echo "✅ Environment ready"
echo ""
@@ -41,7 +41,6 @@ echo ""
# 3. Check for Docker cache
echo "3. Checking for Docker build cache..."
if [ "$HAS_DOCKER" = true ]; then
IMAGE_NAME="gitea.arcodange.lab/arcodange/dance-lessons-coach-build-cache:$DEPS_HASH"
# Try to pull the cache image
@@ -52,15 +51,10 @@ if [ "$HAS_DOCKER" = true ]; then
echo "⚠️ Cache miss - will build without cache"
USE_DOCKER_CACHE=false
fi
else
echo "⚠️ Docker not available - running natively"
USE_DOCKER_CACHE=false
fi
echo ""
# 4. Start PostgreSQL with Docker Compose
echo "4. Starting PostgreSQL..."
if [ "$HAS_DOCKER" = true ]; then
docker compose -f docker-compose.yml up -d postgres
# Wait for PostgreSQL to be ready
@@ -75,40 +69,32 @@ if [ "$HAS_DOCKER" = true ]; then
done
# Set PostgreSQL environment variables for BDD tests
# Use container name for Docker, localhost for native (port mapping)
if [ "$HAS_DOCKER" = true ]; then
export DLC_DATABASE_HOST="dance-lessons-coach-postgres"
else
export DLC_DATABASE_HOST="localhost"
fi
export DLC_DATABASE_PORT=5432
export DLC_DATABASE_USER=postgres
export DLC_DATABASE_PASSWORD=postgres
export DLC_DATABASE_NAME=dance_lessons_coach_bdd_test
export DLC_DATABASE_SSL_MODE=disable
else
echo "⚠️ Docker not available - PostgreSQL tests will be skipped"
fi
echo ""
# 5. Check dependencies
echo "5. Checking dependencies..."
# 5. Install dependencies
if [ "$USE_DOCKER_CACHE" = true ]; then
echo "5. Checking dependencies..."
echo "✅ Using pre-installed dependencies from Docker cache"
# No need to run go mod tidy - dependencies are already in the cache
else
echo "Running natively - ensuring dependencies are up to date..."
echo "5. Installing dependencies..."
go mod tidy
fi
echo "✅ Dependencies ready"
echo ""
# 6. Generate Swagger Docs
echo "6. Generating Swagger documentation..."
if [ "$USE_DOCKER_CACHE" = true ]; then
echo "6. Generating Swagger documentation..."
echo "Running in Docker Compose container..."
docker compose -f docker-compose.build.yml run -w /workspace/pkg/server build-cache sh -c "go generate"
else
echo "6. Generating Swagger documentation..."
echo "Running natively..."
cd pkg/server && go generate
cd ../..
@@ -117,11 +103,12 @@ echo "✅ Swagger documentation generated"
echo ""
# 7. Build and test
echo "7. Building and testing..."
if [ "$USE_DOCKER_CACHE" = true ]; then
echo "7. Building and testing..."
echo "Running in Docker Compose container..."
docker compose -f docker-compose.build.yml run -w /workspace build-cache sh -c "go build ./..."
else
echo "7. Building and testing..."
echo "Running natively..."
go build ./...
fi
@@ -141,12 +128,6 @@ if [ "$USE_DOCKER_CACHE" = true ]; then
sh -c "go test ./... -coverprofile=coverage.out -v && go tool cover -func=coverage.out > coverage.txt"
else
echo "Running natively with Docker Compose PostgreSQL..."
export DLC_DATABASE_HOST=dance-lessons-coach-postgres
export DLC_DATABASE_PORT=5432
export DLC_DATABASE_USER=postgres
export DLC_DATABASE_PASSWORD=postgres
export DLC_DATABASE_NAME=dance_lessons_coach_bdd_test
export DLC_DATABASE_SSL_MODE=disable
go test ./... -coverprofile=coverage.out -v
go tool cover -func=coverage.out > coverage.txt
fi
@@ -154,11 +135,12 @@ echo "✅ Tests passed"
echo ""
# 8. Build binaries
echo "8. Building binaries..."
if [ "$USE_DOCKER_CACHE" = true ]; then
echo "8. Building binaries..."
echo "Running in Docker Compose container..."
docker compose -f docker-compose.build.yml run -w /workspace build-cache sh -c "./scripts/build.sh"
else
echo "8. Building binaries..."
echo "Running natively..."
./scripts/build.sh
fi
@@ -190,8 +172,7 @@ CURRENT_VERSION="$MAJOR.$MINOR.$PATCH${PRERELEASE:+-$PRERELEASE}"
echo "📊 Current version: $CURRENT_VERSION"
echo ""
# 7. Local Docker build instructions
if [ "$HAS_DOCKER" = true ]; then
# 10. Local Docker build instructions
echo "🐳 LOCAL DOCKER BUILD INSTRUCTIONS"
echo "================================"
echo ""
@@ -214,22 +195,22 @@ if [ "$HAS_DOCKER" = true ]; then
echo " docker tag dance-lessons-coach:$CURRENT_VERSION dance-lessons-coach:latest"
echo ""
echo "3. Test the local image (check port availability first):"
echo "5. Test the local image (check port availability first):"
echo " docker run -d -p 8080:8080 dance-lessons-coach:$CURRENT_VERSION"
echo " # Or use alternative port if 8080 is in use:"
echo " docker run -d -p 8081:8080 dance-lessons-coach:$CURRENT_VERSION"
echo ""
echo "4. Branch-specific container naming (recommended):"
echo " BRANCH=\"(git rev-parse --abbrev-ref HEAD | tr '/' '-')"
echo "6. Branch-specific container naming (recommended):"
echo " BRANCH=\"$(git rev-parse --abbrev-ref HEAD | tr '/' '-')\""
echo " docker run -d -p 8080:8080 --name dance-lessons-coach-\"$BRANCH\" dance-lessons-coach:$CURRENT_VERSION"
echo ""
echo "5. Test API endpoints:"
echo "7. Test API endpoints:"
echo " curl http://localhost:8080/api/health"
echo " curl http://localhost:8080/api/v1/greet/YourName"
echo ""
echo "5. Clean up:"
echo "8. Clean up:"
echo " docker stop <container_id> && docker rm <container_id>"
echo ""
@@ -356,9 +337,6 @@ if [ "$HAS_DOCKER" = true ]; then
echo " Or run: docker stop $CONTAINER_NAME && docker rm $CONTAINER_NAME"
fi
fi
else
echo " Docker not available - skipping Docker build instructions"
fi
echo ""
echo "✅ LOCAL CI/CD TEST COMPLETE"
@@ -374,9 +352,7 @@ echo " ✅ Code compilation"
echo " ✅ Unit tests with coverage"
echo " ✅ Binary build"
echo " ✅ Version bump simulation"
if [ "$HAS_DOCKER" = true ]; then
echo " ✅ Docker build (development and/or production if chosen)"
fi
echo ""
echo "🎯 When ready for production:"
echo " Push to main branch to trigger full CI/CD pipeline"