Merge pull request #1 from orangecoding/feat/sse-job-status #34
This file contains hidden or 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: Create and publish Docker image | |
| on: | |
| push: | |
| branches: | |
| - 'master' | |
| tags: | |
| - '*' | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build-and-push-image: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| platforms: linux/amd64,linux/arm64 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to the Container registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Test container with docker compose | |
| run: | | |
| echo "Starting container with docker compose..." | |
| mkdir -p ./db && chmod 777 ./db | |
| docker compose up --build -d | |
| echo "Waiting for container to be ready..." | |
| sleep 30 | |
| echo "Monitoring container health for 30 seconds..." | |
| SECONDS_ELAPSED=0 | |
| HEALTH_CHECK_INTERVAL=5 | |
| TOTAL_DURATION=30 | |
| while [ $SECONDS_ELAPSED -lt $TOTAL_DURATION ]; do | |
| HEALTH_STATUS=$(docker inspect --format='{{.State.Health.Status}}' cronpilot 2>/dev/null || echo "not_found") | |
| CONTAINER_STATUS=$(docker inspect --format='{{.State.Status}}' cronpilot 2>/dev/null || echo "not_found") | |
| echo "[$SECONDS_ELAPSED/$TOTAL_DURATION sec] Container: $CONTAINER_STATUS, Health: $HEALTH_STATUS" | |
| if [ "$CONTAINER_STATUS" != "running" ]; then | |
| echo "Container stopped running! Status: $CONTAINER_STATUS" | |
| docker compose logs cronpilot | |
| exit 1 | |
| fi | |
| if [ "$HEALTH_STATUS" = "unhealthy" ]; then | |
| echo "Container is unhealthy!" | |
| docker compose logs cronpilot | |
| exit 1 | |
| fi | |
| sleep $HEALTH_CHECK_INTERVAL | |
| SECONDS_ELAPSED=$((SECONDS_ELAPSED + HEALTH_CHECK_INTERVAL)) | |
| done | |
| docker compose down |