Skip to content

Instantly share code, notes, and snippets.

@seun-beta
Last active September 14, 2022 13:03
Show Gist options
  • Save seun-beta/8ee0aab70363edcf4a5e07c7ad24c93e to your computer and use it in GitHub Desktop.
Save seun-beta/8ee0aab70363edcf4a5e07c7ad24c93e to your computer and use it in GitHub Desktop.

Using Travis CI to build your Docker Image

I decided to use the lesson on course 3 of the Cloud Developer Nanodegree titled Automating the Application Development Lifecycle to avoid duplication

In Automating the Application Development Lifecycle Module, Lesson 10 & Lesson 11 explain how to build your Docker image on Travis CI.

To sheds more light on using Travis CI, this documentation breaks down the commands into simple bits: https://docs.travis-ci.com/user/docker/

N/B: your file must be named .travis.yml NOT .travis.yaml

The code block starts below

language: node_js
node_js: 
  - 13

services:
  - docker 

install:
  - echo "nothing needs to be installed"

before_script:
  - echo "no tests"

script: 
  - docker --version 
  - docker build -t NAME_OF_IMAGE .
  - docker tag NAME_OF_IMAGE DOCKER_HUB_USER_NAME/DOCKER_HUB_REPO_NAME

after_success:
  - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
  - docker push DOCKER_HUB_USER_NAME/DOCKER_HUB_REPO_NAME

An example to shed more light on this

The code block starts below

language: node_js
node_js: 
  - 13

services:
  - docker 

install:
  - echo "nothing needs to be installed"

before_script:
  - echo "no tests"

script: 
  - docker --version 
  - docker build -t travis-simple-node .
  - docker tag travis-simple-node seunfunmi/travis-simple-node:latest

after_success:
  - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
  - docker push seunfunmi/travis-simple-node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment