Skip to content

Delete event v2 (#74) #72

Delete event v2 (#74)

Delete event v2 (#74) #72

---
name: Deploy Staging
on:
push:
branches:
- staging
workflow_dispatch: {}
env:
AWS_REGION: us-east-2
jobs:
Publish:
runs-on: ubuntu-latest
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.STAGING_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.STAGING_AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Build and Push Docker Image
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: github-system76-cosmic-sync-server
IMAGE_TAG: ${{ github.sha }}
run: |
docker build \
--build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
--build-arg VCS_REF=$IMAGE_TAG \
--build-arg VERSION=$IMAGE_TAG \
--tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
.
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Download Task Definition
run: |
# Use explicit task definition family name instead of secret
aws ecs describe-task-definition \
--task-definition ${{ secrets.STAGING_AWS_TASK_DEFINITION }} \
--query taskDefinition > /tmp/task.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: /tmp/task.json
container-name: app
image: ${{ steps.build-image.outputs.image }}
- name: Deploy Amazon ECS task definition (no wait)
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: staging-genesis76-cosmic-sync
cluster: genesis76-us-east-2
wait-for-service-stability: false
force-new-deployment: true
- name: App health check (no ECS read permissions required)
env:
HEALTHCHECK_URL: https://sync.genesis76.com/health/live
run: |
echo "Waiting for app health endpoint..."
set +e
sleep 120
URL="${HEALTHCHECK_URL:-https://sync.genesis76.com/health/live}"
for i in $(seq 1 60); do
echo "Health check attempt $i/60..."
# Try HTTP/2 first
if curl -fsS --http2 --connect-timeout 5 --max-time 8 -A 'GitHubActionsHealthCheck/1.0' -H 'Accept: application/json' -H 'Cache-Control: no-cache, no-store' -H 'Pragma: no-cache' "$URL"; then
echo "App is healthy (HTTP/2)"
exit 0
fi
# Fallback to HTTP/1.1 in case ALB enforces HTTP/1.1 only
if curl -fsS --http1.1 --connect-timeout 5 --max-time 8 -A 'GitHubActionsHealthCheck/1.0' -H 'Accept: application/json' -H 'Cache-Control: no-cache, no-store' -H 'Pragma: no-cache' "$URL"; then
echo "App is healthy (HTTP/1.1)"
exit 0
fi
# Show debug info on failure
echo "Health check failed, checking /health/details..."
curl -v "https://sync.genesis76.com/health/details" || echo "Details endpoint also failed"
sleep 15
done
echo "App health check failed after 60 attempts"
exit 1