name: Deploy ttl.sh on: push: branches: - prerelease # Temporary: deploy on prerelease for testing # - main # TODO: Switch back to main after testing workflow_dispatch: # Manual trigger for emergencies concurrency: group: deploy-production cancel-in-progress: false # Don't cancel in-progress deploys env: REGISTRY: ghcr.io IMAGE_PREFIX: ghcr.io/${{ github.repository_owner }}/ttlsh jobs: build-and-push: name: Build & Push Images runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout uses: actions/checkout@v4 - name: Log in to GitHub Container Registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Build and push images run: | # Create empty .env file (docker-compose references it, but it's only needed at runtime) touch .env docker compose build docker compose push deploy: name: Deploy to Production runs-on: ubuntu-latest needs: build-and-push steps: - name: Checkout uses: actions/checkout@v4 - name: Install Doppler CLI uses: dopplerhq/cli-action@v3 - name: Install Ansible run: | sudo apt-get update sudo apt-get install -y ansible ansible-galaxy collection install community.general community.docker - name: Setup SSH key run: | mkdir -p ~/.ssh echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa ssh-keyscan -H 178.156.198.215 >> ~/.ssh/known_hosts - name: Run Ansible deployment working-directory: ./ansible env: DOPPLER_TOKEN: ${{ secrets.DOPPLER_TOKEN }} run: | ansible-playbook \ -e "cloudflare_api_token=$(doppler secrets get CF_API_TOKEN --plain)" \ -e "cloudflare_zone_id=$(doppler secrets get CF_ZONE_ID --plain)" \ -e "cloudflare_email=$(doppler secrets get LE_EMAIL --plain)" \ -e "le_email=$(doppler secrets get LE_EMAIL --plain)" \ -e "gcloud_sa_email=$(doppler secrets get GOOGLE_APPLICATION_CREDENTIALS_EMAIL --plain)" \ -e "gcloud_sa_key_json=$(doppler secrets get GCS_KEY_ENCODED --plain)" \ -e "gcs_key_encoded=$(doppler secrets get GCS_KEY_ENCODED --plain)" \ -e "hook_token=$(doppler secrets get HOOK_TOKEN --plain)" \ -e "hook_uri=$(doppler secrets get HOOK_URI --plain)" \ -e "redis_password=$(doppler secrets get REDIS_PASSWORD --plain)" \ -e "rediscloud_url=$(doppler secrets get REDISCLOUD_URL --plain)" \ -e "replreg_host=$(doppler secrets get REPLREG_HOST --plain)" \ -e "replreg_secret=$(doppler secrets get REPLREG_SECRET --plain)" \ -e "registry_url=$(doppler secrets get REGISTRY_URL --plain)" \ playbooks/site.yml smoke-test: name: Smoke Test (Push/Pull/TTL) runs-on: ubuntu-latest needs: deploy steps: - name: Test push and pull run: | IMAGE="ttl.sh/smoke-${{ github.sha }}:5m" echo "๐Ÿงช Testing with image: $IMAGE" # Use busybox - tiny image (~1MB) docker pull busybox:latest docker tag busybox:latest "$IMAGE" echo "๐Ÿ“ค Pushing image..." docker push "$IMAGE" # Remove local copy to force pull from registry docker rmi "$IMAGE" echo "๐Ÿ“ฅ Pulling image back..." docker pull "$IMAGE" echo "โœ… Push/pull test passed!" - name: Wait for TTL expiry run: | echo "โณ Waiting 7 minutes for 5m TTL to expire..." sleep 420 - name: Verify image expired run: | IMAGE="ttl.sh/smoke-${{ github.sha }}:5m" echo "๐Ÿ” Verifying image has expired..." # Remove local copy if cached docker rmi "$IMAGE" 2>/dev/null || true # Try to pull - should fail if docker pull "$IMAGE" 2>&1; then echo "โŒ ERROR: Image still exists after TTL expiry!" exit 1 else echo "โœ… Image correctly expired and unavailable!" fi