Add deployment scripts #4
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 Redis to GCP | |
on: | |
push: | |
branches: | |
- main | |
- testing | |
- deployment-action | |
paths: | |
- ".github/workflows/deploy_gcp_redis.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 | |
DeployRedisToGCP: | |
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: Deploy Redis 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 redis | |
docker rm redis | |
docker run -d \ | |
--log-driver=gcplogs \ | |
--restart always \ | |
--network aaq-network \ | |
--name redis \ | |
-p 6379:6379 \ | |
redis:6.0-alpine | |
docker system prune --volumes -f || true | |
- name: Show deployment command output | |
run: |- | |
echo '${{ steps.compute-ssh.outputs.stdout }}' | |
echo '${{ steps.compute-ssh.outputs.stderr }}' |