Skip to content

Develop

Develop #14

Workflow file for this run

name: 'Continuous Delivery'
on:
pull_request:
branches:
- "main"
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout code
- name: Checkout code
uses: actions/checkout@v3
# Authenticate to Google Cloud
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'
# Cache dependencies
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
# Install dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -r requirements-dev.txt -r requirements-test.txt
# Download model from GCS
- name: Download model from GCS
env:
BUCKET_NAME: ${{ secrets.BUCKET_NAME }}
MODEL: ${{ secrets.MODEL }}
run: |
export PYTHONPATH=$PYTHONPATH:$(pwd)
mkdir -p ./challenge/models
gsutil cp gs://$BUCKET_NAME/$MODEL.pkl ./challenge/models/$MODEL.pkl
# Build and push Docker image
- name: Build and push Docker image
env:
CONTAINER_IMAGE_URL: ${{ secrets.CONTAINER_IMAGE_URL }}
GCLOUD_REGION: ${{ secrets.GCLOUD_REGION }}
run: |
gcloud auth configure-docker us-docker.pkg.dev
docker build -t $CONTAINER_IMAGE_URL:latest .
docker push $CONTAINER_IMAGE_URL:latest
deploy:
needs: build
runs-on: ubuntu-latest
steps:
# Checkout code
- name: Checkout code
uses: actions/checkout@v3
# Authenticate to Google Cloud
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'
# Deploy container to Cloud Run and capture URL
- name: Deploy container to Cloud Run
env:
CONTAINER_IMAGE_URL: ${{ secrets.CONTAINER_IMAGE_URL }}
GCLOUD_REGION: ${{ secrets.GCLOUD_REGION }}
GCLOUD_PROJECT_ID: ${{ secrets.GCLOUD_PROJECT_ID }}
id: deploy
run: |
echo "Deployment running."
URL=$(gcloud run deploy latam-challenge \
--image=$CONTAINER_IMAGE_URL:latest \
--platform=managed \
--allow-unauthenticated \
--region=$GCLOUD_REGION \
--port=8000 \
--project=$GCLOUD_PROJECT_ID \
--format="value(status.url)")
echo "::set-output name=url::$URL"
echo "Image URL: $URL"
# Cache dependencies
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
# Install dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -r requirements-test.txt
# Set STRESS_URL environment variable for later use
- name: Set STRESS_URL as env variable to use later the Makefile
run: echo "STRESS_URL=${{ steps.deploy.outputs.url }}" >> $GITHUB_ENV
# Run stress tests
- name: Run stress tests
run: |
make stress-test STRESS_URL=${{ env.STRESS_URL }}