Use Google Artifact Registry images

Start a deployment or a job from a private image in Google Artifact Registry. There are two ways to give Lightning AI access to the image:

  • Registry credential. Works on any cluster. You store a service account key as a teamspace secret.
  • Connected GCP account. Works on a BYOC cluster, which runs on your own GCP account. Lightning AI uses that account's permissions, so there is no key to store.

Use a registry credential

  1. In the GCP project that owns the repository, create a service account and give it the Artifact Registry Reader role (roles/artifactregistry.reader) on that repository.
  2. Create a JSON key for the service account and download it.
  3. In Lightning AI, go to Settings → Secrets → New Secret, and open the Credential tab:
    • Name: for example, gar_pull.
    • Username: _json_key
    • Password: the full contents of the JSON key file.
  4. Click Create.

To use the credential in a deployment, enter the image name and tag in the Docker image field, then choose the secret under Registry credentials. Click Deploy.

To use it in a job, pass the secret name as image_credentials:

from lightning_sdk import Job, Machine, Teamspace

teamspace = Teamspace(name="my-teamspace", user="my-user")

submitted_job = Job.run(
    name="my-job",
    command="python /scripts/train.py",
    image="<location>-docker.pkg.dev/<project>/<repository>/my-image:latest",
    machine=Machine.CPU,
    teamspace=teamspace,
    image_credentials="gar_pull",
)

Push and pull a test image

To try the registry path, push a test image to your repository and pull it back. Pushing uses your own gcloud login and needs the Artifact Registry Writer role (roles/artifactregistry.writer) on the repository. If the repository doesn't exist yet, create it first with gcloud artifacts repositories create <repository> --repository-format=docker --location=<location>.

# login
gcloud auth configure-docker <location>-docker.pkg.dev
# pull test image (or use your own)
docker pull nginx:latest
# tag
docker tag nginx:latest <location>-docker.pkg.dev/<project>/<repository>/nginx-test:latest
# push
docker push <location>-docker.pkg.dev/<project>/<repository>/nginx-test:latest
# pull
docker pull <location>-docker.pkg.dev/<project>/<repository>/nginx-test:latest

Then use <location>-docker.pkg.dev/<project>/<repository>/nginx-test:latest in a deployment or job, with a registry credential or your connected GCP account.

Use your connected GCP account

This method needs a GCP account attached to Lightning AI, so that clusters from it can pull images from your registry. It doesn't need a key.

Enable the GCP role

First step is to give Lightning AI permission to pull images, using the project role we created to attach your GCP account to Lightning AI.

  1. Find the project role that we created for your BYOC account. They are named "Lightning AI BYOC Project Role ()", and its permissions should look like:

Lightning AI project roles

  1. Edit the role to allow it to access your GCP Artifact Registry:

Filtering the roles

  1. Select all permissions to enable pulling images (it needs to list, download, etc.)

enabling registry permissions

  1. Now, filter by "artifactregistry.repositories" (you can remove the create/delete permissions):

Add the registry repositories get/list/download permissions

  1. Save the role.

Deploy

With the role in place, choose the private image name and tag when starting the deployment. No registry credential is needed.

Run a job

Pass cloud_account_auth=True when you submit the job:

from lightning_sdk import Job, Machine, Teamspace

teamspace = Teamspace(name="my-teamspace", user="my-user")

submitted_job = Job.run(
    name="my-job",
    command="python /scripts/train.py",
    image="<location>-docker.pkg.dev/<project>/<repository>/my-image:latest",
    machine=Machine.CPU,
    teamspace=teamspace,
    cloud_account_auth=True,
)

See Submit jobs for all the job options.

Was this page helpful?

What went wrong?

↑↓ Navigate↵ Open⌘↵ New tabesc Close