feat: Improve GitHub Actions workflows with better error handling and… #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to Development | |
| # Test workflow with ACTIONS token | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| deploy: | |
| runs-on: self-hosted | |
| env: | |
| DOCKER_BUILDKIT: 1 | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v3 | |
| with: | |
| token: ${{ secrets.ACTIONS }} | |
| - name: Setup Environment | |
| run: | | |
| echo "Setting up environment..." | |
| if [ ! -f .env ]; then | |
| echo "Creating .env file..." | |
| cp .env.example .env || echo "No .env.example found, skipping..." | |
| fi | |
| - name: Load Environment Variables | |
| uses: falti/dotenv-action@v1.1.4 | |
| with: | |
| export-variables: true | |
| keys-case: bypass | |
| - name: Setup Docker | |
| run: | | |
| echo "Current user and groups:" | |
| id | |
| echo "Docker info:" | |
| docker info || true | |
| echo "Ensuring docker group membership..." | |
| if ! groups | grep -q docker; then | |
| 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 | |
| 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 | |
| - name: Verify Deployment | |
| run: | | |
| echo "Verifying deployment..." | |
| docker ps | |
| echo "Waiting for container health check..." | |
| 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!" | |
| 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 | |
| exit 1 |