Skip to content

Instantly share code, notes, and snippets.

@darkn3rd
Last active October 12, 2022 07:15
Show Gist options
  • Save darkn3rd/84f281c33512d9bf09be8c8286197c14 to your computer and use it in GitHub Desktop.
Save darkn3rd/84f281c33512d9bf09be8c8286197c14 to your computer and use it in GitHub Desktop.
GKE/CCSM: Publishing pydgrpah-client images to GCR
pushd ./examples/pydgraph-client
###################
# STEP 1: Environment variables
#######################################
source env.sh
export GCR_PROJECT_ID="my-gcr-project" # CHANGE ME
export DOCKER_REGISTRY="gcr.io/$GCR_PROJECT_ID"
export ClOUD_BILLING_ACCOUNT="<my-cloud-billing-account>" # CHANGEME
###################
# STEP 2: Create GCR project and enable GCR
# NOTE: Best practices is to use a single project for store/retreive images
#######################################
gcloud projects create $GCR_PROJECT_ID
gcloud config set project $GCR_PROJECT_ID
gcloud beta billing projects link $GCR_PROJECT_ID \
--billing-account $ClOUD_BILLING_ACCOUNT
gcloud services enable "containerregistry.googleapis.com" # Enable GCR API
gcloud config set project $GKE_PROJECT_ID
###################
# STEP 3: Build local image
#######################################
docker build -t pydgraph-client:latest .
###################
# STEP 4: Publish Image to GCR
#######################################
gcloud auth configure-docker
docker tag pydgraph-client:latest $DOCKER_REGISTRY/pydgraph-client:latest
docker push $DOCKER_REGISTRY/pydgraph-client:latest
###################
# STEP 5: Grant GCR read access to GKE containers
#######################################
gsutil iam ch \
serviceAccount:$GKE_SA_EMAIL:objectViewer \
gs://artifacts.$GCR_PROJECT_ID.appspot.com
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment