The objective of this tutorial is to set up Travis Ci in order to deploy release into Github and DockerHub
Prerequisites
- Travis CI account
- DockerHub account
- Github account
- Install Ruby https://guides.rubygems.org/rubygems-basics/
Deploy Github release via personal OAuth Token
Create an OAuth Token
Go here and create new one.
Make sure you have at least those permissions below:
Encrypt the Github
Go where your .travis.yaml is located.
Install travis tools
gem install travis
Copy your token generated previously and substitute $YOUR_TOKEN with it.
travis encrypt GITHUB_TOKEN=$YOUR_TOKEN --add
This command above encrypt your token and add the encrypted key into your .travis.yaml;
env:
global:
secure: sOQ51G...
Next you can use the variable $GITHUB_TOKEN in the .travis.yaml to set the api_key.
deploy:
provider: releases
api_key: $GITHUB_TOKEN
file: dist/*
skip_cleanup: true
on:
tags: true
Then create a tag an push it:
git tag -a v0.0.1 -m "Release version v0.0.1"
git push --tags
Travis will automatically trigger a new build and deploy it.
Finally go to https://github.com/$GITHUB_USERNAME/$GIT_REPO/releases. You can see you package released !
Deploy Docker image to docker hub
Create encrypted variables $DOCKER_USER and DOCKER_PASSWORD
Go where your .travis.yaml is located.
Install travis tools
gem install travis
substitute username and password by your docker hub credentials.
travis encrypt DOCKER_USER=username --add
travis encrypt DOCKER_PASS=password --add
This command above encrypt your token and add the encrypted key into your .travis.yaml;
env:
global:
secure: sOQ51G...
secure: qiQR2A...
Next you can use the variable $DOCKER_USER and DOCKER_PASSWORD in the .travis.yaml.
Setup .travis.yaml
services:
- docker
script:
- export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo $TRAVIS_BRANCH;
fi`
- docker build -t $REPO:$TAG .
after_success:
- docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
- docker tag $REPO:$COMMIT $REPO:$TAG
- docker tag $REPO:$COMMIT $REPO:$TRAVIS_BUILD_NUMBER
- docker push $REPO
env:
global:
- secure: B8Z5pvFYnGMQR...
- secure: hmVbuNH4Z....
- COMMIT=${TRAVIS_COMMIT::8}
- REPO=$DOCKER_USER/chrono