Skip to content

Instantly share code, notes, and snippets.

@berkorbay
Last active February 14, 2023 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berkorbay/9536e54aa18229fa2663ad78b15ae533 to your computer and use it in GitHub Desktop.
Save berkorbay/9536e54aa18229fa2663ad78b15ae533 to your computer and use it in GitHub Desktop.
GCP (gcloud) ops cheat sheet

Cloud Run

https://cloud.google.com/run/docs/quickstarts/build-and-deploy/deploy-python-service

  • Prepare project and dockerfile
  • Prepare requirements.txt

Dockerfile example

# Copyright 2020 Google, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START cloudrun_helloworld_dockerfile]
# [START run_helloworld_dockerfile]

# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.10-slim

# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

# Install production dependencies.
RUN pip install --no-cache-dir -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.
# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app

# [END run_helloworld_dockerfile]
# [END cloudrun_helloworld_dockerfile]

.dockerignore example

Dockerfile
README.md
*.pyc
*.pyo
*.pyd
__pycache__
.pytest_cache

Discussions

Not curated yet

GCP Ops Cheat Sheet - 1: Setup

Introduction

This little gist is a curation of Google Cloud Platform tutorials to provide faster step by step setup. This material is primarily for my own use, since I usually forget how to do it properly. Tags with square brackets such as [EXAMPLE] are variables which you should fill with proper values (without using the brackets).

WARNING: Please refer to original references as they might have been updated since I wrote these gists.

Setup

https://cloud.google.com/sdk/docs/install-sdk

  1. Install Google Cloud SDK (gcloud) with Brew (https://formulae.brew.sh/cask/google-cloud-sdk)
brew install --cask google-cloud-sdk

https://cloud.google.com/api-gateway/docs/get-started-cloud-run#before-you-begin

  1. Update gcloud components
gcloud components update
  1. Login
gcloud init
  1. Set default project
gcloud config set project [PROJECT_ID]

Other Stuff

  • List accounts with gcloud auth list
  • List default configurations with gcloud config list
  • Info about gcloud installation gcloud info
  • Help with gcloud commands gcloud help [some command] (e.g. gcloud help compute instances create)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment