Skip to content

Instantly share code, notes, and snippets.

@Geremie
Last active April 18, 2022 19:51
Show Gist options
  • Save Geremie/ad3f35ca53a113f95348c83e8c79a65c to your computer and use it in GitHub Desktop.
Save Geremie/ad3f35ca53a113f95348c83e8c79a65c to your computer and use it in GitHub Desktop.
If you are using Python and Google Cloud Platform, this will Simplify Life for you (Part 2)
# Add artifact registry reader role for service account
gcloud projects add-iam-policy-binding <project_id> \
--member=serviceAccount:<your_service_account_id>@<project_id>.iam.gserviceaccount.com \
--role=roles/artifactregistry.reader
# Create key for service account
gcloud iam service-accounts keys create <path_to_key_file> \
--iam-account=<your_service_account_id>@<project_id>.iam.gserviceaccount.com
# Get the python repository url and authentication credentials
gcloud artifacts print-settings python --project <your_gcp_project> \
--repository <your_repository_name> --location <your_repository_location> --json-key <path_to_key_file>
# Get the dags folder
dags_folder=$(gcloud composer environments describe <your_environment_name> \
--project <your_gcp_project> --location <your_location_name> --format="get(config.dagGcsPrefix)")
# Copy the pip.conf file to the config/pip folder
config_folder=$(echo $dags_folder | cut -d / -f-3)/config/pip
gsutil cp pip.conf $config_folder
# Install the python package
gcloud composer environments update <your_environment_name> \
--update-pypi-package mypythonlib==0.2.0 --location <your_location_name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment