-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from naumanzchaudhry/phase-1/2-pipeline-release…
…-stage Setup Deploy.yml
- Loading branch information
Showing
2 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
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
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 |
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