Using Quay as your Container Registry in Travis
In some cases, I prefer using Quay.io as my container registry instead of Dockerhub. If this is the case for you and want to learn how to switch between the two keep reading, Quay and Docker both have their upsides and downsides depending on what type of project you’re doing. In this post, I’m going to show you how to implement Travis into your Quay build, and of course this means you’ll know how to switch between container registries.
This is just one of many things you can do with Quay/Travis powerhouse duo that a lot of users are just learning about, but don’t worry I’ve been using this duo for a while now, so I’ll let you in on all my secrets, ways to do things quicker, etc. So stay tuned as I will be putting out more of these weekly.
Using Travis CI with Quay.io
I’ve setup a tutorial repository, so fork the tutorial repository, https://github.com/Montana/travis-quay-tutorial. Next, you’ll need to edit the
docker_push files in your repo, replacing [yourusername] with the username of your quay account.
Creating your Quay repository
When signed into Quay, in the upper right-hand corner, you’ll see a
+ Create New Repository button. Click the button.
Make sure you select Public instead of Private this is a mistake I made when first starting out with Quay. I made a repo entitled
Creating your Quay robot account
+ button to create your robot account. Give the Robot admin privileges, you’ll then see where you can expand on your account name, here will be the
secrets you want to use as
env vars in Travis.
The Dockerfile that I made for this example is as follows:
FROM alpine:3.8 LABEL LABEL Author="Montana Mendy email@example.com" CMD ["echo", "Hello", "Montana", "and Travis"]
docker_push file reads as follows:
#!/bin/bash echo "$QUAY_BOT_PASSWORD" | docker login -u "$QUAY_BOT_USERNAME" --password-stdin quay.io docker push quay.io/montana/travis-quay-tutorial
Remember in Travis to name the
QUAY_BOT_PASSWORD, also important you store the
token or your
password as well as an
env var. It’s also important you make this file exectuable, you can do this by running:
chmod u+x docker_push
You can set
env vars two ways, from the CLI, if you want to do it this way run:
The simpler way is to do it through the UI, and it looks like this:
Make sure you have all your
env vars correct in the Robots page on Quay, this meaning
password. Copy and paste them into the Travis UI, or run
encrypt and invoke the variables like that.
Now that you’ve set everything Quay up, you can commit your changes to
docker_push, then push your changes to your fork. This should trigger a build with Travis, which will build the container, and instead of pushing it to Dockerhub, it will push it to Quay.
As you can see I’ve successfully pushed to Quay, and in turn am now using Quay as my container registry. As stated in the beginning this is just one of many things you can do with Quay/Travis duo that users are just learning about. Stay tuned as I will be putting out more of these weekly.