How can I use Google Cloud Artifact registry?
This tutorial demonstrates how to set up a DevZero DevBox with access to Google Artifact Registry and use docker images stored there.
This tutorial assumes that a repository already exists in Google Artifact Registry. If you need to set up a repository, you can follow the quick start instructions here: https://cloud.google.com/artifact-registry/docs/docker/store-docker-container-images
Configure a DevZero Environment #
First, let’s configure a DevZero environment with docker and the google cloud CLI pre-installed. Add the following snippet to your template:
scriptpolicy:
- script: |
# docker install instructions from: https://docs.docker.com/engine/install/ubuntu
apt-get install apt-transport-https ca-certificates curl gnupg lsb-release -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update -y
apt-get install docker-ce docker-ce-cli containerd.io -y
usermod -aG docker devzero
- script: |
# install google cloud cli
cd /home/devzero && curl https://sdk.cloud.google.com > install.sh
bash install.sh --disable-prompts
source /home/devzero/google-cloud-sdk/path.bash.inc
runas: devzero
Now, start a DevBox for that environment and log into the terminal via ssh or using VS Code. At the command line, you may need to run this command to ensure that the gcloud shell is in your path:
source /home/devzero/google-cloud-sdk/path.bash.inc
To make this permanent, add the line to your .bashrc or .zshrc config.
Next, run the following command and follow the prompts to log into your Google Cloud account and project that contains the Artifact Registry:
gcloud init
Once authenticated, configure docker to use the correct repository. You will need to use the correct region for your artifact registry if it is not in us-west1:
gcloud auth configure-docker us-west1-docker.pkg.dev
Pull and Push Images from Artifact Registry #
The following example demonstrates how to pull an image from the Google Artifact Registry. This example starts with a public image but if you have a pre-existing private image you can substitute that.
Pull an image:
docker pull us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0
Add the image to your repository. Again, you will need to use the correct region if your registry is not in us-central1. Substitute your project name for PROJECT:
docker tag us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0 \
us-central1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1
Push the image up to your registry:
docker push us-central1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1