v0.1.0 #42
Workflow file for this run
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 Caddy to GCP | |
on: | |
push: | |
branches: | |
- main | |
- testing | |
- production | |
paths: | |
- "deployment/docker-compose/caddy/**" | |
- ".github/workflows/deploy_gcp_caddy.yaml" | |
release: | |
types: [released] | |
workflow_dispatch: | |
jobs: | |
set-env: | |
runs-on: ubuntu-latest | |
outputs: | |
env_name: ${{ steps.set-env.outputs.env_name }} | |
steps: | |
- name: Resolve deployment environment name | |
id: set-env | |
run: | | |
if [ "${{ github.event_name }}" == "release" ] && [ "${{ github.event.action }}" == "released" ]; then | |
echo "env_name=production" >> "$GITHUB_OUTPUT" | |
elif [ "${{ github.ref_name }}" == "main" ]; then | |
echo "env_name=testing" >> "$GITHUB_OUTPUT" | |
else | |
echo "env_name=${{ github.ref_name }}" >> "$GITHUB_OUTPUT" | |
fi | |
DeployCaddyToGCP: | |
needs: [set-env] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: "read" | |
id-token: "write" | |
environment: gcp-${{ needs.set-env.outputs.env_name }} | |
env: | |
RESOURCE_PREFIX: ${{ secrets.PROJECT_NAME }}-${{ needs.set-env.outputs.env_name }} | |
steps: | |
- uses: "actions/checkout@v4" | |
- id: "auth" | |
name: "Authenticate to Google Cloud" | |
uses: "google-github-actions/auth@v2" | |
with: | |
project_id: ${{ secrets.GCP_PROJECT_ID }} | |
workload_identity_provider: projects/${{ secrets.GCP_PROJECT_NUMBER }}/locations/global/workloadIdentityPools/${{ vars.POOL_ID }}/providers/${{ vars.PROVIDER_ID }} | |
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT_EMAIL }} | |
- name: Retrieve secrets from Secret Manager | |
id: "secrets" | |
uses: "google-github-actions/get-secretmanager-secrets@v2" | |
with: | |
secrets: |- | |
domain:${{ secrets.GCP_PROJECT_ID }}/${{ env.RESOURCE_PREFIX }}-domain | |
- name: Copy Caddy deployment files | |
working-directory: deployment/docker-compose | |
run: | | |
gcloud compute scp Caddyfile \ | |
${{ secrets.DEPLOYMENT_INSTANCE_NAME }}:~/Caddyfile \ | |
--zone ${{ secrets.DEPLOYMENT_ZONE }} | |
- name: Deploy Caddy container | |
id: "compute-ssh" | |
uses: "google-github-actions/ssh-compute@v1" | |
with: | |
instance_name: "${{ secrets.DEPLOYMENT_INSTANCE_NAME }}" | |
zone: "${{ secrets.DEPLOYMENT_ZONE }}" | |
ssh_private_key: "${{ secrets.GCP_SSH_PRIVATE_KEY }}" | |
command: | | |
docker stop caddy | |
docker rm caddy | |
docker run -d \ | |
-v caddy_data:/data \ | |
-v caddy_config:/config \ | |
-e DOMAIN=${{ steps.secrets.outputs.domain }} \ | |
-p 80:80 \ | |
-p 443:443 \ | |
-p 443:443/udp \ | |
-v ~/Caddyfile:/etc/caddy/Caddyfile \ | |
--log-driver=gcplogs \ | |
--restart always \ | |
--network aaq-network \ | |
--name caddy \ | |
caddy:2.7.6 | |
docker system prune --volumes -f || true | |
- name: Show deployment command output | |
run: |- | |
echo '${{ steps.compute-ssh.outputs.stdout }}' | |
echo '${{ steps.compute-ssh.outputs.stderr }}' | |
- name: Wait for Application to start | |
id: wait-for-app | |
run: sleep 1m | |
shell: bash | |
- name: Check if deployment was successful | |
id: check-deployment | |
run: | | |
curl -f -X 'GET' \ | |
'https://${{ steps.secrets.outputs.domain }}/api/healthcheck' \ | |
-H 'accept: application/json' |