Skip to content

Merge pull request #23 from dotslashf:development #5

Merge pull request #23 from dotslashf:development

Merge pull request #23 from dotslashf:development #5

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches:
- main
env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GCE_INSTANCE: arsip-template-vm
GCE_INSTANCE_ZONE: asia-southeast1-c
REGION: asia-southeast1
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- id: "auth"
uses: "google-github-actions/auth@v2"
with:
credentials_json: "${{ secrets.GCP_SA_KEY }}"
- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v2"
- name: "Use gcloud CLI"
run: "gcloud info"
- name: Configure Docker for Artifact Registry
run: |
gcloud auth configure-docker $REGION-docker.pkg.dev
- name: Build and push Docker image
run: |
docker build -t $REGION-docker.pkg.dev/$PROJECT_ID/arsip-template/app:${{ github.sha }} .
docker push $REGION-docker.pkg.dev/$PROJECT_ID/arsip-template/app:${{ github.sha }}
- name: Deploy to VM
run: |
# create env file
echo NODE_ENV=production >> .env
echo DATABASE_URL=${{ secrets.DATABASE_URL }} >> .env
echo DISCORD_API_CLIENT_ID=${{ secrets.DISCORD_API_CLIENT_ID }} >> .env
echo DISCORD_API_CLIENT_SECRET=${{ secrets.DISCORD_API_CLIENT_SECRET }} >> .env
echo GOOGLE_API_CLIENT_ID=${{ secrets.GOOGLE_API_CLIENT_ID }} >> .env
echo GOOGLE_API_CLIENT_SECRET=${{ secrets.GOOGLE_API_CLIENT_SECRET }} >> .env
echo NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }} >> .env
echo NEXTAUTH_URL=${{ secrets.NEXTAUTH_URL }} >> .env
echo REDIS_HOST_URL=${{ secrets.REDIS_HOST_URL }} >> .env
echo REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }} >> .env
echo TWITTER_API_KEY=${{ secrets.TWITTER_API_KEY }} >> .env
echo TWITTER_API_SECRET=${{ secrets.TWITTER_API_SECRET }} >> .env
gcloud compute ssh --zone $GCE_INSTANCE_ZONE $GCE_INSTANCE --command '
# Pull the new image
gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
docker pull ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/arsip-template/app:${{ github.sha }}
docker stop arsip-template || true
docker rm arsip-template || true
docker run -d --name arsip-template -p 3000:3000 --env-file .env ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/arsip-template/app:${{ github.sha }}
'