Publishing Packages to packagecloud
Packagecloud is a hosted package repository service. It allows users to host npm, Java/Maven, python, apt, yum and rubygem repositories without any pre-configuration.
- Configure environment variables
- Install the packagecloud CLI
- Pushing packages with the packagecloud CLI
-
Deploy
npm
packages - Using the packagecloud API
Configure environment variables
Set the $PACKAGECLOUD_TOKEN
Under project settings in CircleCI, create an environment variable with the name PACKAGECLOUD_TOKEN
, containing the value of a packagecloud API token. This environment variable will be used to authenticate with the packagecloud API directly, or using the packagecloud CLI.
The packagecloud CLI will automatically read this environment variable from the system when interacting with repositories.
Alternatively, if you prefer to keep your sensitive environment variables checked into git, but encrypted, you can follow the process outlined at circleci/encrypted-files.
Set the $PACKAGECLOUD_URL
for packagecloud:enterprise
Only set the $PACKAGECLOUD_URL
if you’re a packagecloud:enterprise customer
This setting is only for packagecloud:enterprise customers. Under project settings in CircleCI, set the $PACKAGECLOUD_URL
environment variable to the URL of the packagecloud:enterprise installation.
Install the packagecloud CLI
To use the packagecloud CLI from CircleCI, install it using RubyGems by adding the following run
step to your .circleci/config.yml
under the job that is configured to deploy the package:
- run:
name: Install packagecloud CLI
command: gem install package_cloud
The CLI will automatically use the $PACKAGECLOUD_TOKEN
environment variable to authenticate against the packagecloud service.
Using dependency caching
If you want to cache this dependency between builds, you can add the package_cloud
gem to a Gemfile
and follow CircleCI’s guide for Caching Dependencies.
Pushing packages with the packagecloud CLI
The build processes for package types will vary, but pushing them into a packagecloud repository is quite simple. To add packages to a repository from your CircleCI builds, add a step in your deploy
configuration that uses the packagecloud CLI.
The following is a full example .circleci/config.yml
that will checkout a git repository, run a make
task (this command can be anything configured to build your package), then deploy the package to a packagecloud repo.
version: 2
defaults: &defaults
working_directory: ~/repo
docker:
- image: cimg/ruby:3.0.2
auth:
username: mydockerhub-user
password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
jobs:
build:
<<: *defaults
steps:
- checkout
- run:
name: Build the package
command: make
- persist_to_workspace:
root: ~/repo
paths: .
deploy:
<<: *defaults
steps:
- attach_workspace:
at: ~/repo
- run:
name: Install packagecloud CLI
command: gem install package_cloud
- run:
name: Push deb package
command: package_cloud push example-user/example-repo/debian/jessie debs/packagecloud-test_1.1-2_amd64.deb
workflows:
version: 2
package-deploy:
jobs:
- build
- deploy:
requires:
- build
Deploy npm
packages
CircleCI users can deploy packages directly to npm registries hosted on packagecloud.
Configure the test job
This job will retrieve the project code, install its dependencies and run any tests in the NodeJS project:
jobs:
test:
<<: *defaults
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-.
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: npm install
- run:
name: Run tests
command: npm test
- save_cache:
paths:
- node_modules
key: v1-dependencies-
- persist_to_workspace:
root: ~/repo
paths: .
Configure the deploy job
The next job configured is the deploy job. This job will authenticate and publish to the packagecloud npm registry:
jobs:
...
deploy:
<<: *defaults
steps:
- attach_workspace:
at: ~/repo
- run:
name: Set registry URL
command: npm set registry https://packagecloud.io/example-user/example-repo/npm/
- run:
name: Authenticate with registry
command: echo "//packagecloud.io/example-user/example-repo/npm/:_authToken=$PACKAGECLOUD_TOKEN" > ~/repo/.npmrc
- run:
name: Publish package
command: npm publish
-
Set registry URL : This command sets the registry to URL that will be used by the
npm
CLI. -
Authenticate with the registry : This command will set the
authToken
to be used by thenpm
CLI to the environment variable configured in the project settings. - Publish package : Publish the package to the configured npm registry on packagecloud.
The packagecloud npm registry URL is in the following format:
https://packagecloud.io/:username/:repo_name/npm/
The full .circleci/config.yml
should look something like this:
version: 2
defaults: &defaults
working_directory: ~/repo
docker:
- image: cimg/node:16.13.1
auth:
username: mydockerhub-user
password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
jobs:
test:
<<: *defaults
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-.
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: npm install
- run:
name: Run tests
command: npm test
- save_cache:
paths:
- node_modules
key: v1-dependencies-
- persist_to_workspace:
root: ~/repo
paths: .
deploy:
<<: *defaults
steps:
- attach_workspace:
at: ~/repo
- run:
name: Set registry URL
command: npm set registry https://packagecloud.io/example-user/example-repo/npm/
- run:
name: Authenticate with registry
command: echo "//packagecloud.io/example-user/example-repo/npm/:_authToken=$PACKAGECLOUD_TOKEN" > ~/repo/.npmrc
- run:
name: Publish package
command: npm publish
workflows:
version: 2
test-deploy:
jobs:
- test
- deploy:
requires:
- test
The workflows section will tie together both the test
and deploy
jobs into sequential steps in the build process.
You can read more about publishing npm packages to packagecloud on the CircleCI blog post: Publishing npm Packages Using CircleCI
Using the packagecloud API
Packagecloud also provides a robust API to manage package repositories. You can read more about the packagecloud API and how to upload, delete, and promote packages across repositories.
See also
Storing and Accessing Artifacts
Help make this document better
This guide, as well as the rest of our docs, are open source and available on GitHub. We welcome your contributions.
- Suggest an edit to this page (please read the contributing guide first).
- To report a problem in the documentation, or to submit feedback and comments, please open an issue on GitHub.
- CircleCI is always seeking ways to improve your experience with our platform. If you would like to share feedback, please join our research community.
Need support?
Our support engineers are available to help with service issues, billing, or account related questions, and can help troubleshoot build configurations. Contact our support engineers by opening a ticket.
You can also visit our support site to find support articles, community forums, and training resources.
CircleCI Documentation by CircleCI is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.