Skip to content

Commit

Permalink
Merge pull request #6 from naumanzchaudhry/phase-1/2-pipeline-release…
Browse files Browse the repository at this point in the history
…-stage

Setup Deploy.yml
  • Loading branch information
naumanzchaudhry authored Oct 5, 2024
2 parents 1fb80a2 + 15cb1c6 commit e6fc6f3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
65 changes: 65 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Deploy

on:
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment (uat or prod)'
required: true
default: 'uat'

jobs:
deploy-api:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Log in to Docker Hub
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin

- name: Write GCP service account key to file
run: |
printf "${{ secrets.GCP_SA_TOKEN }}" | base64 -d > /home/runner/work/_temp/gcp-key.json
# Authenticate with GCP
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}

# Set up gcloud CLI
- name: Set up gcloud CLI
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}

# Ensure gcloud is authenticated with the service account
- name: Activate Service Account
run: gcloud auth activate-service-account --key-file=/home/runner/work/_temp/gcp-key.json

- name: Prepare Env Variables based on environment
run: |
if [[ "${{ github.event.inputs.environment }}" == "uat" ]]; then
ENVIRONMENT=uat
HTTP_PORT=${{ secrets.HTTP_PORT }}
DATABASE_URL=${{ secrets.UAT_DB_URL }}
JWT_SECRET=${{ secrets.JWT_SECRET }}
elif [[ "${{ github.event.inputs.environment }}" == "prod" ]]; then
ENVIRONMENT=prod
HTTP_PORT=${{ secrets.HTTP_PORT }}
DATABASE_URL=${{ secrets.UAT_DB_URL }}
JWT_SECRET=${{ secrets.JWT_SECRET }}
fi
- name: Deploy API to GCP (${{ github.event.inputs.environment }})
run: |
gcloud run deploy tasker-api-$ENVIRONMENT \
--image docker.io/naumanz/tasker-api:$ENVIRONMENT \
--region us-central1 \
--allow-unauthenticated \
--set-env-vars HTTP_PORT=$HTTP_PORT \
--set-env-vars DATABASE_URL=$DATABASE_URL \
--set-env-vars JWT_SECRET=$JWT_SECRET
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN npm install
COPY . .

# Step 6: Expose the port the app will run on
EXPOSE 3000
EXPOSE 8080

# Step 7: Start the app
CMD ["npm", "start"]

0 comments on commit e6fc6f3

Please sign in to comment.