0
0
GCPcloud~5 mins

Artifact Registry creation in GCP - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you build software, you create files called artifacts like container images or packages. Artifact Registry is a place in Google Cloud where you can store and manage these files safely and access them when needed.
When you want to store container images for your applications in a secure Google Cloud location.
When you need a central place to keep your software packages for easy sharing among your team.
When you want to control who can access your build artifacts with Google Cloud permissions.
When you want to organize your artifacts by project and region for better management.
When you want to use Google Cloud tools to scan your artifacts for security issues.
Config File - artifact-registry-config.yaml
artifact-registry-config.yaml
apiVersion: artifactregistry.cnrm.cloud.google.com/v1beta1
kind: ArtifactRegistryRepository
metadata:
  name: example-repo
  namespace: default
spec:
  format: DOCKER
  location: us-central1
  description: "Docker repository for example app images"
  repositoryId: example-repo

This file defines an Artifact Registry repository named example-repo in the us-central1 region. It stores Docker container images. The format key tells Google Cloud what kind of artifacts this repository holds. The description helps identify the repository purpose.

Commands
This command creates a new Artifact Registry repository named 'example-repo' in the 'us-central1' region to store Docker images. The description helps identify the repository.
Terminal
gcloud artifacts repositories create example-repo --repository-format=docker --location=us-central1 --description="Docker repository for example app images"
Expected OutputExpected
Created repository [example-repo] in location [us-central1].
--repository-format - Specifies the type of artifacts stored, here Docker images.
--location - Sets the geographic location for the repository.
--description - Adds a human-readable description for the repository.
This command lists all Artifact Registry repositories in the 'us-central1' region to verify that the repository was created successfully.
Terminal
gcloud artifacts repositories list --location=us-central1
Expected OutputExpected
NAME FORMAT LOCATION DESCRIPTION example-repo DOCKER us-central1 Docker repository for example app images
--location - Filters the list to repositories in the specified region.
This command shows detailed information about the 'example-repo' repository, confirming its settings and status.
Terminal
gcloud artifacts repositories describe example-repo --location=us-central1
Expected OutputExpected
name: projects/PROJECT_ID/locations/us-central1/repositories/example-repo format: DOCKER description: Docker repository for example app images location: us-central1 createTime: '2024-06-01T12:00:00Z' updateTime: '2024-06-01T12:00:00Z'
--location - Specifies the region of the repository.
Key Concept

If you remember nothing else from this pattern, remember: Artifact Registry is your secure Google Cloud storage for software files like container images, created and managed by simple gcloud commands.

Common Mistakes
Not specifying the --location flag when creating or listing repositories.
Artifact Registry repositories are regional, so omitting the location causes errors or lists repositories in the wrong region.
Always include the --location flag with the correct region when running gcloud artifact registry commands.
Using an unsupported repository format like 'docker' spelled incorrectly or unsupported types.
The command fails because the format must be one of the supported types like DOCKER, MAVEN, NPM, etc., and is case-sensitive.
Use the exact supported format names in uppercase, for example, DOCKER.
Summary
Use 'gcloud artifacts repositories create' with --repository-format and --location to make a new Artifact Registry repository.
Check your repository exists with 'gcloud artifacts repositories list' filtered by location.
Get detailed info about your repository with 'gcloud artifacts repositories describe' and the location flag.