Integrating a Cloudsmith repository with a CircleCI pipeline
CircleCI and Cloudsmith.
At Cloudsmith, we are proud of our partnership network. We work hard to collaborate and integrate with the best DevOps tools available. Building performant, modern workflows requires frictionless integrations between tooling.
Integrating Cloudsmith repositories with your CI/CD processes facilitates rapid development. Build, test, and deploy/distribute your software in repeatable, performant ways.
CircleCI is a best-in-class CI/CD platform, providing easy to configure, performant continuous integration/deployment processes. And as Cloudsmith is a CircleCI partner, deploying the results of these processes to your Cloudsmith repositories is simple with our CircleCI Orb.
What is a CircleCI Orb?
A CircleCI Orb is a packaged, reusable piece of configuration for CircleCI. It enables you to eliminate repetition in your CircleCI config, helps to automate repeat processes, and helps you integrate CircleCI projects with other tools.
For example, you could install the Cloudsmith CLI as part of your CircleCI config and then use Cloudsmith CLI commands to upload build artifacts to your Cloudsmith repositories. But by using the CircleCI Cloudsmith Orb, these additional steps are abstracted away for you, speeding up the development of your CircleCI projects and providing you with a simple, easy-to-use syntax to push your artifacts to Cloudsmith.
Using Cloudsmith and CircleCI
The first thing you need to do is create an account on CircleCI. Just like with Cloudsmith, you can get started for free, so you can follow along with the steps in this blog at zero cost.
You create your CircleCI account using your GitHub or Bitbucket credentials, and you then authorize CircleCI to access source repositories on these platforms. Once logged in, on your CircleCI dashboard, you can view a list of your GitHub or Bitbucket projects that you can start building right away:
CircleCI embraces `configuration-as-code`. The entire CI/CD process that runs when triggered by a commit to your source repository is controlled by a single file - the config.yml file. This whole CI/CD process is called a “pipeline.” A pipeline consists of one or more Workflows, Jobs, and Steps.
So let us take a look at how you define a pipeline in a config.yml file.
1 – Specify version and Orbs
The first thing that we specify in our pipeline is the CircleCI configuration version, and then immediately following this, we define an orb that we would like to use – the CircleCI Cloudsmith Orb:
Next, we define a Job. Jobs are collections of steps which run any commands or shell scripts that we need. Each job must declare an executor, which is where the job will run. An executor can be a docker container, or a Linux, Windows or macOS VM.
For this example, we declare a Job called “Publish”, which will run on Docker Container with Python 3.7 provided by CircleCI – but you can, of course, use your own Docker images also:
The first three steps check out the source from our repository, ensure that we have added our Cloudsmith API key as an environment variable in our CircleCI project settings, and install the Cloudsmith CLI.
Next, we run a series of commands that install the dependencies that we need to build our example project. For this example project, we will create a Debian package, and for that, we will use a packaging tool called FPM. FPM is written in Ruby, so we need to install Ruby, some related Ruby packages and FPM itself (as a Ruby gem).
Finally, we declare the cloudsmith/publish step, from our CircleCI Cloudsmith Orb. For this step, we need to declare the Cloudsmith repository that we wish to push our built package to, the distribution and version that the package is for (as it is a Debian package) and the path to the built package itself. And that’s it – that is all the steps needed for this pipeline.
4 – Declare Workflows
The last thing we add to our pipeline configuration is a workflow. Workflows define a list of jobs and their run order. We only need one workflow for this example pipeline, one that runs the “Publish” job (and therefore, the steps it contains) we declared previously:
All that is left to do now is add this config.yml file to our source project, in a directory called .circleci at the root of the project, and then commit and push to our Github or Bitbucket repository.
Once we have pushed this (and any subsequent commits) to our source repository, our pipeline will be triggered and will run our workflow:
We can click on the job name (in this case, “publish”) to see detailed console output from each step as it runs:
And once the pipeline has completed successfully, we can check the output from the “Publish Package” step:
We can see that our CircleCI pipeline has successfully uploaded our Debian package to our Cloudsmith “examples-repo” repository. If we now login to Cloudsmith and have a look at the repository, we can see the package is present:
That’s all there is to it!
Now, I’m sure that the steps involved in building your projects would be much more complicated than the example outlined above. However, thanks to the Cloudsmith CircleCI Orb, pushing the result of your build to a Cloudsmith repository should be no more complex than demonstrated.
The Cloudsmith CircleCI Orb really does simplify the entire process of getting your build artifacts into your own secure, private repository – and then onwards to other CI/CD processes that your build is a dependency for, or even for direct distribution to your customers.
Increase your build velocity, enable repeatable workflows and level up your DevOps, with CircleCI and Cloudsmith. In short, automate everything.
A secure, cloud-native repository in minutes. Sign up now.