Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dylanroy/546bf122718503347745575d6fcb68df to your computer and use it in GitHub Desktop.
Save dylanroy/546bf122718503347745575d6fcb68df to your computer and use it in GitHub Desktop.
Deploy to Google Cloud Run Using Github Actions
Deploy to Google Cloud Run Using Github Actions
name: cloudrun-deploy
on:
push:
branches:
- main
jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
# Setup gcloud CLI
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
service_account_email: ${{ secrets.GCP_EMAIL }}
service_account_key: ${{ secrets.GCP_CREDENTIALS }}
export_default_credentials: true
# Configure Docker with Credentials
- name: Configure Docker
run: |
gcloud auth configure-docker
# Build the Docker image
- name: Build & Publish
run: |
gcloud config set project ${{ secrets.GCP_PROJECT }}
gcloud builds submit --tag gcr.io/${{ secrets.GCP_PROJECT }}/${{ secrets.GCP_APPLICATION }}
gcloud config set run/region us-central1
# Deploy the Docker image to the GKE cluster
- name: Deploy
run: |
gcloud run deploy ${{ secrets.GCP_APPLICATION }} --image gcr.io/${{ secrets.GCP_PROJECT }}/${{ secrets.GCP_APPLICATION }} \
--platform managed \
--allow-unauthenticated \
--memory 512M
FROM python:3.9-slim
# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True
# Copy local code to the container image.
COPY . /src
WORKDIR /src
# Install Python Requirements
RUN pip install -r requirements.txt
# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
import os
from flask import Flask, request
app = Flask(__name__)
@app.route('/')
def hello_world():
name = request.args.get('name', 'World')
return f'Hello {name}!'
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment