Skip to content

Commit

Permalink
support multiple envs (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
eashwar authored Feb 18, 2024
1 parent f124108 commit 057437f
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 27 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Deploy Latest RMFPBot

on:
workflow_dispatch:
inputs:
environment:
type: choice
description: 'which environment to deploy to'
default: 'stage'
options:
- stage
- prod
push_db:
type: boolean
description: 'update prisma db on startup'
default: false
workflow_call:
inputs:
environment:
type: string
description: 'which environment to deploy to'
default: 'stage'
push_db:
type: boolean
description: 'update prisma db on startup'
default: false

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: '🔑 Authenticate With GCP'
id: auth
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
- name: '☁️ Set Up GCP SDK'
uses: 'google-github-actions/setup-gcloud@v2'
- name: '✍🏽 Map input to VM and DB name'
uses: kanga333/variable-mapper@master
with:
key: '${{ github.event.inputs.environment }}'
map: |
{
"stage": {
"APP_NAME": "rmfp-stage-final",
"DB_NAME": "rmfp-staging-db",
"APPLICATION_ID": "${{ secrets.APPLICATION_ID }}",
"CHANNEL_ID": "${{ secrets.CHANNEL_ID }}",
"DISCORD_TOKEN": "${{ secrets.DISCORD_TOKEN }}",
"GUILD_ID": "${{ secrets.GUILD_ID }}",
"RMFP_OWNER_ROLE_ID": "${{ secrets.RMFP_OWNER_ROLE_ID }}"
},
"prod": {
"APP_NAME": "rmfp-prod",
"DB_NAME": "rmfp-prod-db"
"APPLICATION_ID": "${{ secrets.PROD_APPLICATION_ID }}",
"CHANNEL_ID": "${{ secrets.PROD_CHANNEL_ID }}",
"DISCORD_TOKEN": "${{ secrets.PROD_DISCORD_TOKEN }}",
"GUILD_ID": "${{ secrets.PROD_GUILD_ID }}",
"RMFP_OWNER_ROLE_ID": "${{ secrets.PROD_RMFP_OWNER_ROLE_ID }}"
}
}
export_to: env
- name: '🤫 Create Environment Variables File'
run: |
touch .env
echo "APPLICATION_ID=${{ env.APPLICATION_ID }}" >> .env
echo "CHANNEL_ID=${{ env.CHANNEL_ID }}" >> .env
echo "DATABASE_URL=file:/usr/src/app/db/app.db" >> .env
echo "DISCORD_TOKEN=${{ env.DISCORD_TOKEN }}" >> .env
echo "GUILD_ID=${{ env.GUILD_ID }}" >> .env
echo "PUSH_DB=${{ inputs.push_db }}" >> .env
echo "RMFP_OWNER_ROLE_ID=${{ env.RMFP_OWNER_ROLE_ID }}" >> .env
- name: '☁️✅ Deploy to VM Instance'
run: |
gcloud compute instances update-container ${{ env.APP_NAME }} \
--zone us-east1-b \
--container-image us-east1-docker.pkg.dev/rmfp-bot/rmfp-repo/rmfp-bot:latest \
--container-mount-disk mount-path="/usr/src/app/db",name=${{ env.DB_NAME }} \
--container-env-file ./.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ on:
push:
branches:
- 'main'
workflow_dispatch:

jobs:
build-and-deploy:
build_upload:
runs-on: ubuntu-latest
outputs:
push_db: ${{ steps.changed-files.outputs.PUSH_DB }}
steps:
- name: '📥 Checkout Code'
uses: 'actions/checkout@v4'
Expand Down Expand Up @@ -43,28 +44,9 @@ jobs:
docker build -t rmfp-bot .
docker tag rmfp-bot us-east1-docker.pkg.dev/rmfp-bot/rmfp-repo/rmfp-bot:latest
docker push us-east1-docker.pkg.dev/rmfp-bot/rmfp-repo/rmfp-bot
# I know it's tedious, but it's what we've gotta do.
- name: '🤫 Create Environment Variables File'
env:
APPLICATION_ID: ${{ secrets.APPLICATION_ID }}
CHANNEL_ID: ${{ secrets.CHANNEL_ID }}
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
GUILD_ID: ${{ secrets.GUILD_ID }}
PUSH_DB: ${{ steps.changed-files.PUSH_DB }}
RMFP_OWNER_ROLE_ID: ${{ secrets.RMFP_OWNER_ROLE_ID }}
run: |
touch .env
echo "APPLICATION_ID=$APPLICATION_ID" >> .env
echo "CHANNEL_ID=$CHANNEL_ID" >> .env
echo "DATABASE_URL=file:/usr/src/app/db/app.db" >> .env
echo "DISCORD_TOKEN=$DISCORD_TOKEN" >> .env
echo "GUILD_ID=$GUILD_ID" >> .env
echo "PUSH_DB=$PUSH_DB" >> .env
echo "RMFP_OWNER_ROLE_ID=$RMFP_OWNER_ROLE_ID" >> .env
- name: '☁️✅ Deploy to VM Instance'
run: |
gcloud compute instances update-container rmfp-stage-final \
--zone us-east1-b \
--container-image us-east1-docker.pkg.dev/rmfp-bot/rmfp-repo/rmfp-bot:latest \
--container-mount-disk mount-path="/usr/src/app/db",name=rmfp-staging-db \
--container-env-file ./.env
deploy:
needs: build_upload
uses: ./.github/workflows/deploy.yml
with:
environment: ${{ needs.build_upload.outputs.push_db == 'true' && 'stage' || 'prod' }}
push_db: ${{ needs.build_upload.outputs.push_db }}

0 comments on commit 057437f

Please sign in to comment.