name: Build and Validate on: push: branches: - main jobs: build-and-test: runs-on: ubuntu-latest steps: - name: Check out repository code uses: actions/checkout@v3 - name: Build Docker image run: docker build -t todoizer-app:latest . - name: Run container run: | docker run -d --name todoizer -p 4567:4567 todoizer-app:latest # Wait for application to start sleep 5 - name: Validate web application loads run: | echo "Waiting for application to start..." for i in {1..15}; do # Run curl inside the container to bypass any host-runner networking port mapping quirks HTTP_STATUS=$(docker exec todoizer curl -o /dev/null -s -w "%{http_code}\n" http://localhost:4567/ || echo "failed") if [ "$HTTP_STATUS" == "200" ]; then echo "Web application loaded successfully. HTTP status: $HTTP_STATUS" exit 0 fi echo "Attempt $i: App not ready (Status: $HTTP_STATUS). Sleeping 2s..." sleep 2 done echo "Failed to load web application after 30 seconds." docker logs todoizer exit 1 - name: Cleanup Test Container if: always() run: | docker stop todoizer || true docker rm todoizer || true - name: Login to Gitea Container Registry if: success() run: echo "${{ secrets.GITEA_TOKEN || gitea.token || github.token }}" | docker login gitea.krisforbes.ca -u ${{ gitea.actor || github.actor }} --password-stdin - name: Push Docker image if: success() run: | docker tag todoizer-app:latest gitea.krisforbes.ca/krisf/todoizer:latest docker push gitea.krisforbes.ca/krisf/todoizer:latest