How to deploy multi container application to heroku via travis ci - docker

Hey I am using travis ci and i dont understand what i have to write inside the travis yml to deploy multi container into heroku
this is my travis.yml
sudo: required
services:
- docker
before_install:
- docker build -t 307949230/client-test -f ./client/Dockerfile.dev ./client
script:
- docker run 307949230/client-test npm test -- --coverage
after_success:
- docker build -t 307949230/mern-client ./client
- docker build -t 307949230/mern-nginx ./nginx
- docker build -t 307949230/mern-server ./server
# Log in to the docker CLI
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin
# Take those images and push them to docker hub
- docker push 307949230/mern-client
- docker push 307949230/mern-nginx
- docker push 307949230/mern-server

Related

travis ci do nothing

I am new on Travis CI and I am trying to deploy my hobby project to AWS by Travis but in my first commit nothing happened here is my .travis.yml:
sudo: required
language: generic
services:
- docker
before_install:
- docker build -t aaa/fakewebappapi -f ./api/Dockerfile.dev ./api
script:
- docker run -e CI=true aaa/fakewebappapi npm run test
after_success:
- docker build -t aaa/fakewebappclient -f ./client/Dockerfile.dev ./client
- docker build -t aaa/fakewebappapi -f ./api/Dockerfile.dev ./api
- docker build -t aaa/fakewebappnginx -f ./nginx/Dockerfile.dev ./nginx
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin
- docker push aaa/fakewebappclient
- docker push aaa/fakewebappapi
- docker push aaa/fakewebappnginx
Each docker work correctly but when I push the repository to my GitHub nothing changed. Also I checked my GitHub profile and travis connected it succesfully.
Also there is no log in travis-ci.com when I see other travis project on YouTube everyone has log screen in built screen.
Check if you are using tabs instead of spaces.

Travis does not push docker image to hub

As in title, Travis does not want to push docker image to docker hub after successfully test passing? What is wrong? I have already set env variabales DOCKER_PASSWORD and DOCKER_USERNAME. Any ideas?
language: python
sudo: required
services:
- docker
script:
- docker-compose run web python manage.py test
after_success:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker build -t maciejwojtkowiak/todo .
- docker push maciejwojtkowiak/todo .
Remove the . at the end of the docker push

Docker efficiency of CI/CD pipeline

This is my travis.yml file and this is the latest run
https://travis-ci.com/github/harryyy27/allies-art-club:
sudo: required
language: generic
services:
- docker
stages:
- dev
- prod
jobs:
include:
- stage: dev
if: NOT(branch=master)
scripts:
- docker build -t harryyy27/allies_art_club/frontend -f ./client/Dockerfile.dev ./client
- docker build -t harryyy27/allies_art_club/backend -f ./src/Dockerfile.dev ./src
- docker run -e CI=true harryyy27/allies_art_club/frontend npm test
- docker run -e CI=true harryyy27/allies_art_club/backend npm test
- stage: prod
if: branch=master
before_deploy:
- docker build -t harryyy27/aac-client ./client
- docker tag harryyy27/aac-client registry.heroku.com/$HEROKU_APP/client
- docker build -t harryyy27/aac-src ./src
- docker tag harryyy27/aac-src registry.heroku.com/$HEROKU_APP/src
- docker build -t harryyy27/aac-nginx ./nginx
- docker tag harryyy27/aac-nginx registry.heroku.com/$HEROKU_APP/nginx
# Log in to docker CLI
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin
- curl https://cli-assets.heroku.com/install.sh | sh
- echo "$HEROKU_API" | docker login -u "$HEROKU_USERNAME" --password-stdin registry.heroku.com
deploy:
skip_cleanup: true
provider: script
script:
docker ps -a;
docker push harryyy27/aac-client;
docker push registry.heroku.com/$HEROKU_APP/client;
docker push harryyy27/aac-src;
docker push registry.heroku.com/$HEROKU_APP/src;
docker push harryyy27/aac-nginx;
docker push registry.heroku.com/$HEROKU_APP/nginx;
heroku container:release client src nginx --app $HEROKU_APP;
I'm unsure as to whether this is an efficient setup. Is there a way of caching the docker builds so it doesn't have to rebuild them every time? When I'm updating builds locally it can update just the parts that need to be changed. Is there a way of doing this on Travis? A whole new rebuild seems like a lot of unnecessary work for Travis. What's the most efficient combination of free CI/CD service and free hosting for docker deployments in terms of build efficiency and deployment efficiency? (I know this is subjective, just want to get some idea)
Sorry if these are rookie questions btw I am very new to docker and its corresponding workflows/pipelines... having a bit of trouble finding multi container examples with heroku.

Travis-ci stages - conditional logic

This is my travis.yml file followed by the latest run
https://travis-ci.com/github/harryyy27/allies-art-club:
sudo: required
services:
- docker
stages:
- name: before_deploy
if: branch = master
- name: before_install
if: branch != master
- name: scripts
if: branch != master
before_install:
- docker build -t harryyy27/allies_art_club/frontend -f ./client/Dockerfile.dev ./client
- docker build -t harryyy27/allies_art_club/backend -f ./src/Dockerfile.dev ./src
scripts:
- docker run -e CI=true harryyy27/allies_art_club/frontend npm test
- docker run -e CI=true harryyy27/allies_art_club/backend npm test
before_deploy:
- docker build -t harryyy27/aac-client ./client
- docker tag harryyy27/aac-client registry.heroku.com/$HEROKU_APP/client
- docker build -t harryyy27/aac-src ./src
- docker tag harryyy27/aac-src registry.heroku.com/$HEROKU_APP/src
- docker build -t harryyy27/aac-nginx ./nginx
- docker tag harryyy27/aac-nginx registry.heroku.com/$HEROKU_APP/nginx
# Log in to docker CLI
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin
- curl https://cli-assets.heroku.com/install.sh | sh
- echo "$HEROKU_API" | docker login -u "$HEROKU_USERNAME" --password-stdin registry.heroku.com
deploy:
skip_cleanup: true
provider: script
script:
docker ps -a;
docker push harryyy27/aac-client;
docker push registry.heroku.com/$HEROKU_APP/client;
docker push harryyy27/aac-src;
docker push registry.heroku.com/$HEROKU_APP/src;
docker push harryyy27/aac-nginx;
docker push registry.heroku.com/$HEROKU_APP/nginx;
heroku container:release client src nginx --app $HEROKU_APP;
on:
branch: master
However, I'd like to know why my branch != master does not work for the before_install and scripts stages. It runs both of these stages even on master branch after merging my pull request.
(I am aware of the other issues with this travis.yml, I have raised them as separate questions)
Resolved this, set it up differently though. See below. I think the stages have to be set up with the jobs/include object as seen below
see new travis.yml
sudo: required
language: generic
services:
- docker
stages:
- dev
- prod
jobs:
include:
- stage: dev
if: NOT(branch=master)
scripts:
- docker build -t harryyy27/allies_art_club/frontend -f ./client/Dockerfile.dev ./client
- docker build -t harryyy27/allies_art_club/backend -f ./src/Dockerfile.dev ./src
- docker run -e CI=true harryyy27/allies_art_club/frontend npm test
- docker run -e CI=true harryyy27/allies_art_club/backend npm test
- stage: prod
if: branch=master
before_deploy:
- docker build -t harryyy27/aac-client ./client
- docker tag harryyy27/aac-client registry.heroku.com/$HEROKU_APP/client
- docker build -t harryyy27/aac-src ./src
- docker tag harryyy27/aac-src registry.heroku.com/$HEROKU_APP/src
- docker build -t harryyy27/aac-nginx ./nginx
- docker tag harryyy27/aac-nginx registry.heroku.com/$HEROKU_APP/nginx
# Log in to docker CLI
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin
- curl https://cli-assets.heroku.com/install.sh | sh
- echo "$HEROKU_API" | docker login -u "$HEROKU_USERNAME" --password-stdin registry.heroku.com
deploy:
skip_cleanup: true
provider: script
script:
docker ps -a;
docker push harryyy27/aac-client;
docker push registry.heroku.com/$HEROKU_APP/client;
docker push harryyy27/aac-src;
docker push registry.heroku.com/$HEROKU_APP/src;
docker push harryyy27/aac-nginx;
docker push registry.heroku.com/$HEROKU_APP/nginx;
heroku container:release client src nginx --app $HEROKU_APP;
***note I had to add language to avoid a Rakefile error. Best to use generic here as using node_js will prompt travis to look for a package.json and and a "make test" error will occur

Trouble deploying multi-container docker application to heroku using travis

So really I have several problems here. This is my travis.yml file and this is the latest run
https://travis-ci.com/github/harryyy27/allies-art-club:
sudo: required
language: generic
services:
- docker
stages:
- dev
- prod
jobs:
include:
- stage: dev
if: NOT(branch=master)
scripts:
- docker build -t harryyy27/allies_art_club/frontend -f ./client/Dockerfile.dev ./client
- docker build -t harryyy27/allies_art_club/backend -f ./src/Dockerfile.dev ./src
- docker run -e CI=true harryyy27/allies_art_club/frontend npm test
- docker run -e CI=true harryyy27/allies_art_club/backend npm test
- stage: prod
if: branch=master
before_deploy:
- docker build -t harryyy27/aac-client ./client
- docker tag harryyy27/aac-client registry.heroku.com/$HEROKU_APP/client
- docker build -t harryyy27/aac-src ./src
- docker tag harryyy27/aac-src registry.heroku.com/$HEROKU_APP/src
- docker build -t harryyy27/aac-nginx ./nginx
- docker tag harryyy27/aac-nginx registry.heroku.com/$HEROKU_APP/nginx
# Log in to docker CLI
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin
- curl https://cli-assets.heroku.com/install.sh | sh
- echo "$HEROKU_API" | docker login -u "$HEROKU_USERNAME" --password-stdin registry.heroku.com
deploy:
skip_cleanup: true
provider: script
script:
docker ps -a;
docker push harryyy27/aac-client;
docker push registry.heroku.com/$HEROKU_APP/client;
docker push harryyy27/aac-src;
docker push registry.heroku.com/$HEROKU_APP/src;
docker push harryyy27/aac-nginx;
docker push registry.heroku.com/$HEROKU_APP/nginx;
heroku container:release client src nginx --app $HEROKU_APP;
For some reason I cannot deploy to heroku. The docker push registry.heroku.com/$HEROKU_APP/container_name appears to work along with the echo "$HEROKU_API" | docker login -u "$HEROKU_USERNAME" --password-stdin registry.heroku.com sign in but then when I go to release the heroku containers says "Invalid credentials provided" in the terminal and tells me to login. Is there a way of releasing these containers using the docker CLI on Travis?
If not, would the Heroku CLI help?
So I eventually resolved this by simply changing the $HEROKU_API to $HEROKU_API_KEY. This is an environment variable that when present automatically logs you into the Heroku CLI enabling you to run the scripts required to upload to your docker containers to Heroku. This is the travis.yml I eventually ended up with
sudo: required
language: generic
services:
- docker
stages:
- dev
- prod
jobs:
include:
- stage: dev
if: NOT(branch=master)
scripts:
- docker build -t harryyy27/allies_art_club/frontend -f ./client/Dockerfile.dev ./client
- docker build -t harryyy27/allies_art_club/backend -f ./src/Dockerfile.dev ./src
- docker run -e CI=true harryyy27/allies_art_club/frontend npm test
- docker run -e CI=true harryyy27/allies_art_club/backend npm test
- stage: prod
if: branch=master
before_deploy:
- docker build -t harryyy27/aac-client ./client
- docker tag harryyy27/aac-client registry.heroku.com/$HEROKU_APP/client
- docker build -t harryyy27/aac-src ./src
- docker tag harryyy27/aac-src registry.heroku.com/$HEROKU_APP/src
- docker build -t harryyy27/aac-nginx ./nginx
- docker tag harryyy27/aac-nginx registry.heroku.com/$HEROKU_APP/nginx
# Log in to docker CLI
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin
- curl https://cli-assets.heroku.com/install.sh | sh
- echo "$HEROKU_API_KEY" | docker login -u "$HEROKU_USERNAME" --password-stdin registry.heroku.com
- docker push harryyy27/aac-client;
- docker push registry.heroku.com/$HEROKU_APP/client;
- docker push harryyy27/aac-src;
- docker push registry.heroku.com/$HEROKU_APP/src;
- docker push harryyy27/aac-nginx;
- docker push registry.heroku.com/$HEROKU_APP/nginx;
deploy:
skip_cleanup: true
provider: script
script:
heroku container:login;
heroku container:release client src nginx --app $HEROKU_APP;
I do now have errors in Heroku though :P

Resources