diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index fcac7ad..7a22d43 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -4,14 +4,18 @@ name: Deploy to Development on: push: branches: - - main + - main + paths-ignore: + - '**.md' + - 'docs/**' jobs: deploy: - runs-on: self-hosted + runs-on: self-hosted env: DOCKER_BUILDKIT: 1 - + COMPOSE_FILE: docker-compose.dev.yml + steps: - name: Checkout Repository uses: actions/checkout@v3 @@ -25,6 +29,8 @@ jobs: echo "Creating .env file..." cp .env.example .env || echo "No .env.example found, skipping..." fi + # Set development port prefix for the containers + echo "DEV_PORT_PREFIX=30" >> .env - name: Load Environment Variables uses: falti/dotenv-action@v1.1.4 @@ -43,44 +49,36 @@ jobs: echo "::warning::Current user is not in docker group" fi - - name: Build Docker Image for Frontend - run: | - echo "Building frontend image..." - cd frontend - docker build --progress=plain -t secfit-frontend:latest . - - - name: Clean Up Existing Container - run: | - echo "Cleaning up existing container..." - docker rm -f secfit-frontend || true - - - name: Deploy Container + - name: Build and Deploy Services run: | - echo "Deploying new container..." - docker run -d \ - --name secfit-frontend \ - -p 3000:3000 \ - --restart unless-stopped \ - -e NODE_ENV=production \ - --health-cmd="curl -f http://localhost:3000 || exit 1" \ - --health-interval=10s \ - --health-timeout=5s \ - --health-retries=3 \ - secfit-frontend:latest + echo "Building and deploying services..." + docker compose -f $COMPOSE_FILE down --remove-orphans + docker compose -f $COMPOSE_FILE build --no-cache + docker compose -f $COMPOSE_FILE up -d - name: Verify Deployment run: | - echo "Verifying deployment..." - docker ps - echo "Waiting for container health check..." + echo "Checking running containers..." + docker compose -f $COMPOSE_FILE ps + echo "Waiting for services to be healthy..." for i in {1..12}; do - if docker inspect secfit-frontend --format='{{.State.Health.Status}}' 2>/dev/null | grep -q healthy; then - echo "Container is healthy!" + if docker compose -f $COMPOSE_FILE ps | grep -q "unhealthy\|exit"; then + echo "Some containers are unhealthy or have exited" + docker compose -f $COMPOSE_FILE logs + exit 1 + elif docker compose -f $COMPOSE_FILE ps | grep -q "starting"; then + echo "Some containers are still starting... (attempt $i/12)" + sleep 10 + continue + else + echo "All containers appear to be running!" + # Test frontend + curl -f http://localhost:3005 || echo "Frontend not responding on port 3005" + # Test backend + curl -f http://localhost:3004/api/health || echo "Backend not responding on port 3004" exit 0 fi - echo "Waiting for container to be healthy... (attempt $i/12)" - sleep 10 done - echo "Container health check failed" - docker logs secfit-frontend + echo "Deployment verification timed out" + docker compose -f $COMPOSE_FILE logs exit 1