Pushing packages to packagecloud

Mar 28, 2016 • packagecloud

TL;DR

This blog post details all ways you can push packages to packagecloud using different languages and platforms.

Pushing a Package: Fundamentals

For this example, we’ll use our packagecloud-test package. We’ll be pushing this package to julio/example_repo for the ubuntu/utopic distribution.

If you’d like to follow along, make sure you have your API token handy.

The steps for pushing a package are as follows:

  1. Skip this step for rubygems Use the distributions API to get the desired distro_version_id for your upload. (This is also a great endpoint for testing that your API token and http client are setup correctly)

  2. Send a POST request with the distro_version_id to the package create API to push your package.

Using packagecloud.io

Click the Add Package button.

Repo Page

Using curl

Fetch the list of distributions.

$ curl https://xxx_token_xxx:@packagecloud.io/api/v1/distributions.json

We can see that it’s 142 (helps if you pretty print the JSON).

{
  "id": 142,
  "display_name": "14.10 Utopic Unicorn",
  "index_name": "utopic",
  "version_number": "14.10"
}
$ curl -F "package[distro_version_id]=142" \
-F "package[package_file]=@path/to/packagecloud-test_1.1-2_amd64.deb" \ https://xxx_token_xxx:@packagecloud.io/api/v1/repos/julio/example_repo/packages.json

Using package_cloud gem

$ gem install package_cloud
$ package_cloud push julio/example_repo/ubuntu/utopic path/to/packagecloud-test_1.1-2_amd64.deb

(It will ask for your API token on first use)

Using packagecloud-ruby gem

require 'packagecloud'

credentials = Packagecloud::Credentials.new("julio", "xxx_token_xxx")
client = Packagecloud::Client.new(credentials)

deb_package = Packagecloud::Package.new(:file => "path/to/packagecloud-test_1.1-2_amd64.deb")

client.put_package("example_repo", deb_package, "ubuntu/utopic")

Using io.packagecloud.client java library

import io.packagecloud.client.Connection;
import io.packagecloud.client.Credentials;
import io.packagecloud.client.Client;
import io.packagecloud.client.PackageCloud;
import io.packagecloud.client.Package;
import java.io.File;

Connection connection = new Connection("localhost", 8080, "http");
Credentials credentials = new Credentials("julio", "xxx_token_xxx");
Client client = new Client(credentials, connection);
PackageCloud pcloud = new PackageCloud(client);

InputStream file = new File("path/to/packagecloud-test_1.1-2_amd64.deb");
Package pkg = Package.fromFile(file, "example_repo", 142);

pcloud.putPackage(pkg);

Using pkgcloud go library

$ pkgcloud-push julio/example_repo/ubuntu/utopic path/to/packagecloud-test_1.1-2_amd64.deb

Using Jenkins Packagecloud Plugin

See the plugin documentation for usage and install instructions.

Using Travis CI

See the plugin documentation for usage instructions.

Using anything that can speak HTTP

To construct a package create API request, you need the following:

  • A POST request of the Content-Type multipart/form-data
  • The body of which needs to be a valid MIME Multipart message with two parts:
    • package[distro_version_id]: a text/plain part containing the distro_version_id
    • package[package_file]: an application/octet-stream part containing the binary data of that package

Conclusion

We are always adding new integrations and ways to push to packagecloud, check back often to see if your favorite language or platform has been added!

Check out our slack or email support@packagecloud.io if you have any suggestions for new languages or platforms to support.

Never miss an update!

Subscribe to our RSS feed