Create an Artifact Registry
⚠️
Be sure to replace your PROJECT_ID environment variable in these scripts
We will now create a repository for our docker images (OCI Images) in Artifact Registry. This will allow us to store our images in a private registry. We will use this registry to store our images for Cloud Run and later GKE.
# so we can execute gcloud commands
gcloud auth login
# project name is phx-danl
export PROJECT_ID="pdcp-cloud-009-danl"
# Get the PROJECT_NUMBER from the PROJECT_ID
export PROJECT_NUMBER=$(gcloud projects describe ${PROJECT_ID} --format="value(projectNumber)")
export REGION="northamerica-northeast1"
export ARTIFACT_REGISTRY_REPO_NAME="garden-repo"
gcloud config set project ${PROJECT_ID}
# Create an artifact registry repository
gcloud artifacts repositories create ${ARTIFACT_REGISTRY_REPO_NAME} \
--repository-format=docker \
--location=${REGION} \
--description="${ARTIFACT_REGISTRY_REPO_NAME}"
# Allow our service account to read from the registry
gcloud artifacts repositories add-iam-policy-binding ${ARTIFACT_REGISTRY_REPO_NAME} \
--location=${REGION} \
--member=serviceAccount:${PROJECT_NUMBER}-compute@developer.gserviceaccount.com \
--role="roles/artifactregistry.reader"Confirm the repository was created:
gcloud artifacts repositories describe ${ARTIFACT_REGISTRY_REPO_NAME} --location ${REGION}Should yeild output similar to:
Encryption: Google-managed key
Repository Size: 0.000MB
createTime: '2023-04-17T17:01:06.020281Z'
description: garden-repo
dockerConfig: {}
format: DOCKER
mode: STANDARD_REPOSITORY
name: projects/pdcp-cloud-009-danl/locations/northamerica-northeast1/repositories/garden-repo
updateTime: '2023-04-17T17:01:06.020281Z'Now allow our docker client to read/write from the registry (for later)
gcloud auth configure-docker ${REGION}-docker.pkg.dev