Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle deployments based on different branches #13

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- main
- develop
- release/*

jobs:
deploy:
Expand Down Expand Up @@ -40,11 +42,27 @@ jobs:
docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/flight-predictor . --platform linux/amd64
docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/flight-predictor

- name: Deploy to Cloud Run
id: deploy
- name: Deploy to Cloud Run (Main)
if: github.ref == 'refs/heads/main'
run: |
echo "Deploying to Google Cloud Run..."
URL=$(gcloud run deploy flight-predictor-api --image gcr.io/${{ secrets.GCP_PROJECT_ID }}/flight-predictor --platform managed --region us-central1 --allow-unauthenticated --format="value(status.url)")
echo "Deploying Main API to Google Cloud Run..."
URL=$(gcloud run deploy main-api --image gcr.io/${{ secrets.GCP_PROJECT_ID }}/flight-predictor --platform managed --region us-central1 --allow-unauthenticated --format="value(status.url)")
echo "::set-output name=url::$URL"
echo "Deployment completed at $URL"

- name: Deploy to Cloud Run (Develop)
if: github.ref == 'refs/heads/develop'
run: |
echo "Deploying Develop API to Google Cloud Run..."
URL=$(gcloud run deploy develop-api --image gcr.io/${{ secrets.GCP_PROJECT_ID }}/flight-predictor --platform managed --region us-central1 --allow-unauthenticated --format="value(status.url)")
echo "::set-output name=url::$URL"
echo "Deployment completed at $URL"

- name: Deploy to Cloud Run (Release)
if: contains(github.ref, 'refs/heads/release/')
run: |
echo "Deploying Release API to Google Cloud Run..."
URL=$(gcloud run deploy release-api --image gcr.io/${{ secrets.GCP_PROJECT_ID }}/flight-predictor --platform managed --region us-central1 --allow-unauthenticated --format="value(status.url)")
echo "::set-output name=url::$URL"
echo "Deployment completed at $URL"

Expand Down
1 change: 1 addition & 0 deletions docs/challenge.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,5 @@ The training script `./challenge/train.py` used all the data we have for trainin
**REMARKS**:
- There are better ways of dealing with this last problem. Instead of training inside the `cd.yml`, we could have a model registry (using for example, MLflow), and then deploying our API with a model we have available in our model registry.
- Even though some variables like the project name and the key for my Service Account are treated as secret variables in the repository, I am aware that some variables are still hardcoded (and even the project name which is 'secret', is explicitly mentioned a few times in this markdown documentation just to simplify the exposition). One hardcoded variable is for example `STRESS_URL` in the Makefile, which shouldn't be harcoded. However, I still added a few steps in the `cd.yml` to get the URL to my API when it deploys with gcloud, and uses that URL to run the stress-test.
- After everything worked with the main branch, I modified my `cd.yml` file to handle deployments based on different branches (main, develop, and release/*), by including conditional logic within the deployment steps or create separate jobs for each branch scenario.

Loading