0%

Travis CI: push docker manifest to dockerhub

I am going to use Travis to continue create docker multiarch images, then push back to dockerhub repo.

create a repo in my github account named travis-CICD and add it to Travis GitHub Apps Integration

under the travis-CICD repo, create a .travis.yml file

Since github uses ruby, I don’t need to specify the language. For this project, I am going to work on docker, so I need to start docker.
I am going to use two docker images to create a multiarch using docker manifest create command.
Note: Because manifest is an experimental feature, I need to add DOCKER_CLI_EXPERIMENTAL=enabled in .travis.yml file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
sudo: required
addons:
apt:
update: true
packages:
- docker-ce
services:
- docker
before_install:
script:
- docker pull treehouses/turtleblocksjs-tags:nginx-x86
- docker pull treehouses/turtleblocksjs-tags:nginx-rpi
- export DOCKER_CLI_EXPERIMENTAL=enabled
- docker manifest create vmnet8/turtleblocksjs:annarocks2 treehouses/turtleblocksjs-tags:nginx-x86
treehouses/turtleblocksjs-tags:nginx-rpi
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker manifest push vmnet8/turtleblocksjs:annarocks2
env:
global:

Go to dockerhub to get a new token

install travis cli on my local

before install travis, I need to solove dependencies.

1
2
sudo apt install ruby-dev libffi-dev make gcc
sudo gem install travis

to verify it

1
2
3
4
5
6
7
8
9
10
11
12
13
anna@ubuntu1804:~/OLE_intern/travis/travis-CICD$ which travis
/usr/local/bin/travis
anna@ubuntu1804:~$ travis login --com
Shell completion not installed. Would you like to install it now? |y| y
We need your GitHub login to identify you.
This information will not be sent to Travis CI, only to api.github.com.
The password will not be displayed.

Try running with --github-token or --auto if you don't want to enter your password anyway.

Username: vmnet8
Password for vmnet8: ********
Successfully logged in as vmnet8!

create env variable for travis

1
2
travis env set DOCKER_USERNAME vmnet8
travis env set DOCKER_PASSWORD "******"

Use travis CLI to encrypt data wiht the public key.

1
travis encrypt --pro SOMEVAR="secretvalue"

It will output a string, I can add it to .travis.yml file

1
travis encrypt SOMEVAR="secretvalue" --add

It will automaticlly add encrpted data to .travis.yml file

git add .travis.yml file, commit and push to github

after the pull request, the travis will build automatic

exited with 0.
Go to dockerhub to verify, it pushed to dockerhub successfully.