Store Conda packages in Artifact Registry
This quickstart shows you how to set up a private Artifact Registry Conda repository and then upload a package to that repository.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Artifact Registry API.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Make sure that you have the following role or roles on the project: Artifact Registry Administrator
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
- Click Grant access.
-
In the New principals field, enter your user identifier. This is typically the email address for a Google Account.
- Click Select a role, then search for the role.
- To grant additional roles, click Add another role and add each additional role.
- Click Save.
-
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Artifact Registry API.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Make sure that you have the following role or roles on the project: Artifact Registry Administrator
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
- Click Grant access.
-
In the New principals field, enter your user identifier. This is typically the email address for a Google Account.
- Click Select a role, then search for the role.
- To grant additional roles, click Add another role and add each additional role.
- Click Save.
-
- To use the Conda CLI within your Google Cloud environment, install one of the following Conda package managers:
Launch Cloud Shell
In this quickstart, you will use Cloud Shell, which is a shell environment for managing resources hosted on Google Cloud.
Cloud Shell comes preinstalled with the Google Cloud CLI and Conda. The gcloud CLI provides the primary command-line interface for Google Cloud.
Launch Cloud Shell:
Go to Google Cloud console.
On the Google Cloud console toolbar, click Activate Cloud Shell.
A Cloud Shell session opens inside a frame lower on the console.
You use this shell to run gcloud commands.
Configure authentication
A Conda channel is the address to a location where one or more Conda packages are stored. Before you can install packages in your Conda environment, you must add the channel for that package to your Conda configuration file.
To allow the Conda CLI to call Artifact Registry directly, you must authenticate your Conda channel in Google Cloud by doing the following:
In the gcloud CLI, run the following command to store the identity of an
oauthtoken in a TOKEN variable:export TOKEN="oauth2accesstoken:$(gcloud auth print-access-token)"Add your Conda repository as a channel in your Conda configuration file:
Conda
conda config --add channels \ https://$TOKEN@LOCATION-conda.pkg.dev/PROJECT/REPOSITORYMiniforge
conda config --add channels \ https://$TOKEN@LOCATION-conda.pkg.dev/PROJECT/REPOSITORYMamba
mamba config --add channels \ https://$TOKEN@LOCATION-conda.pkg.dev/PROJECT/REPOSITORYMicromamba
micromamba config --add channels \ https://$TOKEN@LOCATION-conda.pkg.dev/PROJECT/REPOSITORYWhere:
- TOKEN stores the value of the
oauthtoken generated by runningoauth2accesstoken:$(gcloud auth print-access-token). - LOCATION is the regional or multi-regional location for the repository.
- PROJECT is the ID of the project containing the repository.
- REPOSITORY is the ID of the repository.
- TOKEN stores the value of the
Refresh an expired oauth token
An oauth token expires after one hour. To re-authenticate your channel
with a new token, do the following:
Remove your channel from your configuration file:
Conda
conda config --remove channels CHANNEL_NAMEMiniforge
conda config --remove channels CHANNEL_NAMEMamba
mamba config --remove channels CHANNEL_NAMEMicromamba
micromamba config --remove channels CHANNEL_NAMEFollow the previous step that described creating a new
oauthtoken.Add your Conda repository back to your Conda configuration file, using your new token value.
Create a repository
Create the repository for your package.
Run the following command to create a new Conda repository in the current project named
quickstart-conda-repoin the locationus-west1.gcloud artifacts repositories create quickstart-conda-repo \ --repository-format=conda \ --location=us-west1 \ --description="Conda repository"Run the following command to verify that your repository was created:
gcloud artifacts repositories listTo simplify
gcloudcommands, set the default repository toquickstart-conda-repoand the default location tous-west1. After the values are set, you don't need to specify them ingcloudcommands that require a repository or a location.To set the repository, run the following command:
gcloud config set artifacts/repository quickstart-conda-repoTo set the location, run the following command:
gcloud config set artifacts/location us-west1For more information about these commands, see the gcloud config set documentation.
Upload the package to the repository
To upload a package to your repository, run the following command:
gcloud artifacts files upload \
--source=PACKAGE_NAME \
--repository=REPO_NAME\
--project=PROJECT \
--location=LOCATION
Where:
- REPO_NAME is the ID of the repository.
- PROJECT is the ID of the project containing the repository.
- LOCATION is the regional or multi-regional location for the repository.
To upload multiple packages at one time:
gcloud artifacts files upload \
--source-directory="DIRECTORY" \
--repository="REPO_NAME"\
--project="PROJECT" \
--location="LOCATION"
Where:
- DIRECTORY is the address of a local folder containing your Conda packages.
View the package in the repository
To verify that your package was added, list the packages in the
quickstart-conda-repo repository.
Run the following command:
gcloud artifacts packages list --repository=quickstart-conda-repo
To view versions for a package, run the following command:
gcloud artifacts versions list --package=PACKAGE_NAME
To view the files for a package version, run the following command:
gcloud artifacts files list --package=PACKAGE_NAME --version=VERSION
Install the package
To install the package that you just added to your Artifact Registry repository, run the following command:
Conda
conda install -n ENVIRONMENT_NAME PACKAGE_NAME
Miniforge
conda install -n ENVIRONMENT_NAME PACKAGE_NAME
Mamba
mamba install -n ENVIRONMENT_NAME PACKAGE_NAME
Micromamba
micromamba install -n ENVIRONMENT_NAME PACKAGE_NAME
Where:
- ENVIRONMENT_NAME is the name of your Conda environment.
- PACKAGE_NAME is the name of the package to install in your repository.
Troubleshooting
See Troubleshooting for Conda packages for more information.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
Before you remove the repository, ensure that any packages you want to keep are available in another location.
To delete the
quickstart-conda-reporepository, run the following command:gcloud artifacts repositories delete quickstart-conda-repoIf you want to remove the default repository and location settings that you configured for the active
gcloudconfiguration, run the following commands:gcloud config unset artifacts/repository gcloud config unset artifacts/location
What's next
- Learn more about configuring authentication.
- Learn about managing repositories.
- Learn about managing packages.
- Read our resources about DevOps and explore our research program.