18 Commits

Author SHA1 Message Date
a0d2bd6996 🐛 fix: correct database.ssl_mode environment variable binding
Some checks failed
CI/CD Pipeline / Build Docker Cache (push) Successful in 10s
CI/CD Pipeline / CI Pipeline (push) Failing after 17s
- Fix environment variable binding for SSL mode
- Use correct mapstructure tag name
- Match struct field binding

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-08 00:28:18 +02:00
07dc72d19e 🐛 fix: remove incorrect argument from LoadConfig call
- Fix compilation error
- LoadConfig takes no arguments

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-08 00:27:18 +02:00
076bc120e0 🐛 fix: make BDD test server use actual config with environment variables
- Modify createTestConfig to load real config
- Respect DLC_DATABASE_HOST and other environment variables
- Fallback to defaults if config loading fails
- Enable proper database connection configuration
- Fix BDD tests in Docker containers

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-08 00:26:27 +02:00
0026515237 🐛 fix: add missing database environment variable bindings
- Add BindEnv calls for database configuration
- DLC_DATABASE_HOST, DLC_DATABASE_PORT, DLC_DATABASE_USER
- DLC_DATABASE_PASSWORD, DLC_DATABASE_NAME, DLC_DATABASE_SSL_MODE
- Enable environment variable override for database config
- Fix BDD test database connection issues

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-08 00:25:01 +02:00
543e9e240a 🐛 fix: use shasum on macOS, sha256sum on Linux
- Detect which hash command is available
- Fix script compatibility across platforms
- Maintain same functionality

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-08 00:18:38 +02:00
5ffa60ef65 🐛 fix: use correct DLC_DATABASE_HOST for Docker vs native execution
- Use localhost for native execution (PostgreSQL port mapping)
- Use dance-lessons-coach-postgres for Docker container execution
- Set appropriate environment variables for each execution mode
- Fix container-to-container communication

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-08 00:15:57 +02:00
f18716d447 🔧 refactor: simplify BDD database configuration
- Remove unnecessary getPostgresHost() function
- Use direct localhost configuration
- PostgreSQL port is mapped to host, so localhost works everywhere
- Simplify code by removing unnecessary abstraction
- Use existing config system properly

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-08 00:10:31 +02:00
cf13b44e0d 🐛 fix: properly detect Docker container vs native execution
- Enhance getPostgresHost() to detect Docker environment
- Check multiple Docker-specific indicators
- Use container name when running inside Docker
- Use localhost when running natively
- Fix BDD test PostgreSQL connection issues

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-08 00:03:49 +02:00
f8474b69c1 🐛 fix: BDD tests PostgreSQL connection for native execution
- Simplify getPostgresHost() to always use localhost by default
- Use DLC_DATABASE_HOST=localhost for all local execution
- Container name only needed when running INSIDE Docker containers
- Fix native execution PostgreSQL connection issues
- Ensure BDD tests connect to localhost:5432 (mapped port)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-07 23:52:57 +02:00
6c2399bea6 🔧 refactor: replace docker compose run with docker run --rm
- Use docker run --rm instead of docker compose run
- More explicit container cleanup with --rm flag
- Direct volume mounting and network configuration
- Maintain same functionality with cleaner approach
- Better matches CI/CD workflow style

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-07 23:51:54 +02:00
a1804d7aec 🐛 fix: add shared network configuration for Docker Compose services
- Add dance-lessons-coach-network to both compose files
- Ensure build-cache and postgres containers can communicate
- Fix container-to-container connectivity
- Maintain same network name for consistency

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-07 23:49:58 +02:00
22099d0ac6 🔧 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>
2026-04-07 23:41:15 +02:00
18213f365d 🐛 fix: BDD tests PostgreSQL connection for native execution
- Enhance getPostgresHost() to detect Docker vs native execution
- Use localhost for native execution (PostgreSQL port mapping)
- Use container name for Docker execution
- Fix local CI/CD script to set correct DLC_DATABASE_HOST
- Ensure BDD tests can connect in both Docker and native modes

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-07 23:40:08 +02:00
9528b7d288 🐛 fix: BDD tests PostgreSQL connection using DLC_* environment variables
- Add getPostgresHost() function to use DLC_DATABASE_HOST env var
- Default to dance-lessons-coach-postgres container name
- Update local CI/CD script to set proper DLC_* environment variables
- Fix Docker Compose test execution to pass correct database config
- Ensure BDD tests can connect to PostgreSQL in both Docker and native modes

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-07 23:38:27 +02:00
f54c60c6a3 🔧 refactor: simplify CI/CD workflow by removing redundant cache checks
- Remove duplicate steps section
- Eliminate redundant cache availability checks
- Simplify logic since build-cache job guarantees cache availability
- Remove unnecessary conditional execution
- Streamline Docker Compose usage

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-07 23:28:47 +02:00
9213c97da6 🔧 fix: optimize Docker cache usage by removing redundant go mod tidy
- Remove unnecessary go mod tidy execution when using Docker cache
- Dependencies are already pre-installed in the cache image
- Only run go mod tidy when not using cache (native execution)
- This leverages the true purpose of the Docker build cache

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-07 23:22:30 +02:00
da0dc0e30f 🔧 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>
2026-04-07 23:20:52 +02:00
2ca361ccd9 🔧 chore: align Gitea workflow with local CI/CD script
- Add go mod tidy step to match local script
- Execute build.sh script in Docker Compose container
- Maintain consistent build process between local and CI
- Ensure Docker cache compatibility

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-07 23:18:22 +02:00
6 changed files with 401 additions and 291 deletions

View File

@@ -152,58 +152,28 @@ jobs:
exit 1
fi
steps:
- name: Checkout code
uses: actions/checkout@v4
uses: docker/login-action@v3
with:
registry: ${{ env.CI_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.PACKAGES_TOKEN }}
- 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 "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
echo "CACHE_IMAGE=$IMAGE_NAME" >> $GITHUB_ENV
else
echo "⚠️ Building without cache (first run or new dependencies)"
echo "CACHE_AVAILABLE=false" >> $GITHUB_ENV
fi
# Cache is guaranteed to be available since build-cache job succeeded
echo "✅ Using Docker build cache (guaranteed by build-cache job)"
echo "CACHE_AVAILABLE=true" >> $GITHUB_ENV
- name: Start build cache container with Docker Compose
run: |
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
echo "Starting build cache container..."
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
echo "Running natively..."
cd pkg/server && go generate
fi
run: docker compose -f docker-compose.build.yml exec -w /workspace/pkg/server build-cache sh -c "go generate"
- name: Build all packages 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 build-cache sh -c "go build ./..."
else
echo "Running natively..."
go build ./...
fi
run: docker compose -f docker-compose.build.yml exec -w /workspace build-cache sh -c "go build ./..."
- name: Wait for PostgreSQL to be ready
run: |
@@ -225,7 +195,6 @@ jobs:
- name: Run tests with coverage using Docker Compose
run: |
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
echo "Running in Docker Compose container with PostgreSQL..."
docker compose -f docker-compose.build.yml exec \
-e PGHOST=dance-lessons-coach-postgres \
@@ -236,16 +205,6 @@ jobs:
-w /workspace \
build-cache \
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 PGHOST=dance-lessons-coach-postgres
export PGPORT=5432
export PGUSER=postgres
export PGPASSWORD=postgres
export PGDATABASE=dance_lessons_coach_bdd_test
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)
@@ -263,7 +222,7 @@ jobs:
run: swag fmt
- name: Build binaries
run: ./scripts/build.sh
run: docker compose -f docker-compose.build.yml exec -w /workspace build-cache sh -c "./scripts/build.sh"
# NOTE: Artifact upload disabled - actions/upload-artifact@v4 not available on Gitea
# TODO: Replace with Gitea-specific upload action when available

View File

@@ -13,4 +13,11 @@ services:
environment:
- GOPATH=/go
- PATH=/go/bin:/usr/local/go/bin:/usr/local/bin:/usr/bin:/bin
networks:
- dance-lessons-coach-network
restart: unless-stopped
networks:
dance-lessons-coach-network:
name: dance-lessons-coach-network
driver: bridge

View File

@@ -15,6 +15,8 @@ services:
interval: 5s
timeout: 5s
retries: 5
networks:
- dance-lessons-coach-network
restart: unless-stopped
# Application service (for reference)
@@ -38,3 +40,8 @@ services:
volumes:
postgres_data:
driver: local
networks:
dance-lessons-coach-network:
name: dance-lessons-coach-network
driver: bridge

View File

@@ -15,6 +15,8 @@ import (
"github.com/rs/zerolog/log"
)
// getPostgresHost returns the appropriate PostgreSQL host based on environment
type Server struct {
httpServer *http.Server
port int
@@ -237,6 +239,11 @@ func (s *Server) GetBaseURL() string {
}
func createTestConfig(port int) *config.Config {
// Load actual config to respect environment variables
cfg, err := config.LoadConfig()
if err != nil {
log.Warn().Err(err).Msg("Failed to load config, using defaults")
// Fallback to defaults if config loading fails
return &config.Config{
Server: config.ServerConfig{
Host: "localhost",
@@ -260,7 +267,7 @@ func createTestConfig(port int) *config.Config {
AdminMasterPassword: "admin123",
},
Database: config.DatabaseConfig{
Host: "localhost",
Host: "localhost", // Fallback if env vars not set
Port: 5432,
User: "postgres",
Password: "postgres",
@@ -271,4 +278,19 @@ func createTestConfig(port int) *config.Config {
ConnMaxLifetime: time.Hour,
},
}
}
// Override server port for testing
cfg.Server.Port = port
cfg.API.V2Enabled = true // Ensure v2 is enabled for testing
// Set default auth values if not configured
if cfg.Auth.JWTSecret == "" {
cfg.Auth.JWTSecret = "default-secret-key-please-change-in-production"
}
if cfg.Auth.AdminMasterPassword == "" {
cfg.Auth.AdminMasterPassword = "admin123"
}
return cfg
}

View File

@@ -188,6 +188,14 @@ func LoadConfig() (*Config, error) {
// API environment variables
v.BindEnv("api.v2_enabled", "DLC_API_V2_ENABLED")
// Database environment variables
v.BindEnv("database.host", "DLC_DATABASE_HOST")
v.BindEnv("database.port", "DLC_DATABASE_PORT")
v.BindEnv("database.user", "DLC_DATABASE_USER")
v.BindEnv("database.password", "DLC_DATABASE_PASSWORD")
v.BindEnv("database.name", "DLC_DATABASE_NAME")
v.BindEnv("database.ssl_mode", "DLC_DATABASE_SSL_MODE")
// Unmarshal into Config struct
var config Config
if err := v.Unmarshal(&config); err != nil {

View File

@@ -3,7 +3,7 @@
# Simulates the CI/CD pipeline but builds Docker image locally
# Use this for local development and testing without Gitea
set -e
set -eu
echo "🚀 Local CI/CD Testing"
echo "======================"
@@ -16,53 +16,162 @@ 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
echo "✅ Environment ready"
echo ""
# 2. Install dependencies
echo "2. Installing dependencies..."
go mod tidy
echo "✅ Dependencies installed"
# 2. Calculate dependency hash (match CI workflow)
echo "2. Calculating dependency hash..."
# Use shasum on macOS, sha256sum on Linux
if command -v sha256sum >/dev/null 2>&1; then
export DEPS_HASH=$(sha256sum go.mod go.sum | sha256sum | cut -d' ' -f1 | head -c 12)
else
export DEPS_HASH=$(shasum -a 256 go.mod go.sum | shasum -a 256 | cut -d' ' -f1 | head -c 12)
fi
echo "Dependency hash: $DEPS_HASH"
echo "✅ Dependency hash calculated"
echo ""
# 3. Install swag and generate docs
echo "3. Generating Swagger documentation..."
if [ ! -f pkg/server/docs/swagger.json ]; then
echo "📝 Generating Swagger docs..."
go install github.com/swaggo/swag/cmd/swag@latest
cd pkg/server && go generate
cd ../..
echo "✅ Swagger documentation generated"
# 3. Check for Docker cache
echo "3. Checking for Docker build cache..."
IMAGE_NAME="gitea.arcodange.lab/arcodange/dance-lessons-coach-build-cache:$DEPS_HASH"
# Try to pull the cache image
if docker pull "$IMAGE_NAME" >/dev/null 2>&1; then
echo "✅ Cache hit - using existing build cache"
USE_DOCKER_CACHE=true
else
echo "✅ Swagger documentation already exists"
echo "⚠️ Cache miss - will build without cache"
USE_DOCKER_CACHE=false
fi
echo ""
# 4. Build and test
echo "4. Building and testing..."
go build ./...
# 4. Start PostgreSQL with Docker Compose
echo "4. Starting PostgreSQL..."
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 for BDD tests
export DLC_DATABASE_HOST="localhost" # PostgreSQL port is mapped to host
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
echo ""
# 5. Install dependencies
if [ "$USE_DOCKER_CACHE" = true ]; then
echo "5. Checking dependencies..."
echo "✅ Using pre-installed dependencies from Docker cache"
else
echo "5. Installing dependencies..."
go mod tidy
fi
echo "✅ Dependencies ready"
echo ""
# 6. Generate Swagger Docs
if [ "$USE_DOCKER_CACHE" = true ]; then
echo "6. Generating Swagger documentation..."
echo "Running in Docker container..."
docker run --rm \
--network dance-lessons-coach-network \
-v "$(pwd):/workspace" \
-w /workspace/pkg/server \
"$IMAGE_NAME" \
sh -c "go generate"
else
echo "6. Generating Swagger documentation..."
echo "Running natively..."
cd pkg/server && go generate
cd ../..
fi
echo "✅ Swagger documentation generated"
echo ""
# 7. Build and test
if [ "$USE_DOCKER_CACHE" = true ]; then
echo "7. Building and testing..."
echo "Running in Docker container..."
docker run --rm \
--network dance-lessons-coach-network \
-v "$(pwd):/workspace" \
-w /workspace \
"$IMAGE_NAME" \
sh -c "go build ./..."
else
echo "7. Building and testing..."
echo "Running natively..."
go build ./...
fi
echo "✅ Code compiled successfully"
go test ./... -cover -v
if [ "$USE_DOCKER_CACHE" = true ]; then
echo "Running in Docker container with PostgreSQL..."
docker run --rm \
--network dance-lessons-coach-network \
-v "$(pwd):/workspace" \
-w /workspace \
-e DLC_DATABASE_HOST=dance-lessons-coach-postgres \
-e DLC_DATABASE_PORT=5432 \
-e DLC_DATABASE_USER=postgres \
-e DLC_DATABASE_PASSWORD=postgres \
-e DLC_DATABASE_NAME=dance_lessons_coach_bdd_test \
-e DLC_DATABASE_SSL_MODE=disable \
"$IMAGE_NAME" \
sh -c "go test ./... -coverprofile=coverage.out -v && go tool cover -func=coverage.out > coverage.txt"
else
echo "Running natively with Docker Compose PostgreSQL..."
go test ./... -coverprofile=coverage.out -v
go tool cover -func=coverage.out > coverage.txt
fi
echo "✅ Tests passed"
echo ""
# 5. Build binaries
echo "5. Building binaries..."
./scripts/build.sh
# 8. Build binaries
if [ "$USE_DOCKER_CACHE" = true ]; then
echo "8. Building binaries..."
echo "Running in Docker container..."
docker run --rm \
--network dance-lessons-coach-network \
-v "$(pwd):/workspace" \
-w /workspace \
"$IMAGE_NAME" \
sh -c "./scripts/build.sh"
else
echo "8. Building binaries..."
echo "Running natively..."
./scripts/build.sh
fi
echo "✅ Binaries built"
ls -la bin/
echo ""
# 6. Version bump simulation
echo "6. Version bump simulation..."
# 9. Version bump simulation
echo "9. Version bump simulation..."
LAST_COMMIT=$(git log -1 --pretty=%B | head -1)
echo "Last commit: $LAST_COMMIT"
@@ -85,60 +194,59 @@ CURRENT_VERSION="$MAJOR.$MINOR.$PATCH${PRERELEASE:+-$PRERELEASE}"
echo "📊 Current version: $CURRENT_VERSION"
echo ""
# 7. Local Docker build instructions
if [ "$HAS_DOCKER" = true ]; then
echo "🐳 LOCAL DOCKER BUILD INSTRUCTIONS"
echo "================================"
echo ""
# 10. Local Docker build instructions
echo "🐳 LOCAL DOCKER BUILD INSTRUCTIONS"
echo "================================"
echo ""
echo "1. Build Docker image locally (development):"
echo " docker build -t dance-lessons-coach:$CURRENT_VERSION ."
echo ""
echo "1. Build Docker image locally (development):"
echo " docker build -t dance-lessons-coach:$CURRENT_VERSION ."
echo ""
echo "2. Build production image using docker/Dockerfile.prod:"
echo " # Note: Local docker/Dockerfile.prod uses 'latest' tag for testing"
echo " docker build -t dance-lessons-coach-prod:$CURRENT_VERSION -f docker/Dockerfile.prod ."
echo " # For CI/CD, the workflow generates correct docker/Dockerfile.prod with dependency hash"
echo ""
echo "2. Build production image using docker/Dockerfile.prod:"
echo " # Note: Local docker/Dockerfile.prod uses 'latest' tag for testing"
echo " docker build -t dance-lessons-coach-prod:$CURRENT_VERSION -f docker/Dockerfile.prod ."
echo " # For CI/CD, the workflow generates correct docker/Dockerfile.prod with dependency hash"
echo ""
echo "3. Compare image sizes:"
echo " docker images | grep dance-lessons-coach"
echo ""
echo "3. Compare image sizes:"
echo " docker images | grep dance-lessons-coach"
echo ""
echo "4. Tag the image:"
echo " docker tag dance-lessons-coach:$CURRENT_VERSION dance-lessons-coach:latest"
echo ""
echo "4. Tag the image:"
echo " docker tag dance-lessons-coach:$CURRENT_VERSION dance-lessons-coach:latest"
echo ""
echo "3. 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 " docker run -d -p 8080:8080 --name dance-lessons-coach-\"$BRANCH\" dance-lessons-coach:$CURRENT_VERSION"
echo ""
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 "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 " curl http://localhost:8080/api/health"
echo " curl http://localhost:8080/api/v1/greet/YourName"
echo ""
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 " docker stop <container_id> && docker rm <container_id>"
echo ""
echo "8. Clean up:"
echo " docker stop <container_id> && docker rm <container_id>"
echo ""
echo "💡 Tip: Use 'docker images' to see your built images"
echo "💡 Use 'docker ps' to see running containers"
echo ""
echo "💡 Tip: Use 'docker images' to see your built images"
echo "💡 Use 'docker ps' to see running containers"
echo ""
# Ask if user wants to build Docker image now
read -p "🚀 Do you want to build the Docker image now? (y/n): " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Ask if user wants to build Docker image now
read -p "🚀 Do you want to build the Docker image now? (y/n): " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "🐳 Building Docker image..."
read -p "📋 Build (d)development or (p)production image? [d/p]: " -n 1 -r
echo ""
echo ""
if [[ $REPLY =~ ^[Pp]$ ]]; then
echo "🏗️ Building production image with docker/Dockerfile.prod..."
docker build -t dance-lessons-coach-prod:$CURRENT_VERSION -f docker/Dockerfile.prod .
@@ -152,17 +260,17 @@ if [ "$HAS_DOCKER" = true ]; then
echo "✅ Development Docker image built: dance-lessons-coach:$CURRENT_VERSION"
CONTAINER_IMAGE="dance-lessons-coach:$CURRENT_VERSION"
fi
echo ""
echo ""
# Check if port 8080 is available
echo "🔍 Checking port availability..."
if lsof -i :8080 > /dev/null 2>&1; then
echo "⚠️ Port 8080 is already in use"
read -p "🚀 Do you want to use a different port? (y/n): " -n 1 -r
echo ""
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
read -p "Enter port number (e.g., 8081): " CUSTOM_PORT
echo ""
echo ""
PORT=$CUSTOM_PORT
else
echo " Using port 8080 anyway (may fail if service is running)"
@@ -174,7 +282,7 @@ if [ "$HAS_DOCKER" = true ]; then
fi
read -p "🚀 Do you want to run the container now on port $PORT? (y/n): " -n 1 -r
echo ""
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Get current branch name for container naming
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD | tr '/' '-')
@@ -250,9 +358,6 @@ if [ "$HAS_DOCKER" = true ]; then
echo "💡 Press Ctrl+C to stop the container when done"
echo " Or run: docker stop $CONTAINER_NAME && docker rm $CONTAINER_NAME"
fi
fi
else
echo " Docker not available - skipping Docker build instructions"
fi
echo ""
@@ -260,20 +365,22 @@ echo "✅ LOCAL CI/CD TEST COMPLETE"
echo "==========================="
echo ""
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 " ✅ Swagger documentation generation"
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 " ✅ Docker build (development and/or production if chosen)"
echo ""
echo "🎯 When ready for production:"
echo " Push to main branch to trigger full CI/CD pipeline"
echo " Docker image will be built and pushed to Gitea Container Registry"
echo ""
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
# ✅ CI/CD workflow generates correct Dockerfile.prod with dependency hash