Continuous Deployment con Docker + Travis + Heroku

Javier Fernandes
Jun 20, 2018 · 13 min read

La Aplicación

Lo que vamos a hacer

CI: Travis + Docker

(caripela x200)
sudo: required

services:
- docker
sudo: required
language: node_js
node_js:
- "9"
services:
- docker
before_install:
# login to docker registries (dockerhub + heroku)
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
install:
# install deps
- yarn install
script:
- yarn test
- yarn build
En travis se definen en settings
Mantenemos las variables en secreto para que no aparezcan en logs
sudo: required
language: node_js
node_js:
- "9"
services:
- docker
before_install:
# login to docker registries (dockerhub + heroku)
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
install:
# install deps
- yarn install
script:
- yarn test
- yarn build
# build docker images
- docker build -t unqpdes/todo-list-front .
deploy:
provider: script
script:
# push to dockerhub
docker push unqpdes/todo-list-front;
branch: master

CD: Travis + Heroku

Nota sobre cómo deployar en Heroku con Docker

Settings de Heroku. Se ve que soporta varias formas. Nosotros vamos a usar la última “Container Registry”
before_install:
# install heroku CLI
- wget -qO- https://toolbelt.heroku.com/install.sh | sh

# login to docker registries (dockerhub + heroku)
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- echo "$HEROKU_PASSWORD" | docker login -u "$HEROKU_USERNAME" --password-stdin registry.heroku.com
registry.heroku.com/$HEROKU_APP_NAME/web
sudo: required
language: node_js
node_js:
- "9"
services:
- docker

before_install:
# install heroku CLI
- wget -qO- https://toolbelt.heroku.com/install.sh | sh
# login to docker registries (dockerhub + heroku)
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- echo "$HEROKU_PASSWORD" | docker login -u "$HEROKU_USERNAME" --password-stdin registry.heroku.com

install:
# install deps
- yarn install

script:
- yarn test
- yarn build
# build docker images
- docker build -t unqpdes/todo-list-front .
- docker tag unqpdes/todo-list-front registry.heroku.com/$HEROKU_APP_NAME/web

deploy:
provider: script
script:
# push to dockerhub & heroku
docker push unqpdes/todo-list-front;
docker push registry.heroku.com/$HEROKU_APP_NAME/web;
on:
branch: master
(HEROKU_API_KEY la vamos a definir a continuación)

Release

sudo: required
language: node_js
node_js:
- "9"
services:
- docker

before_install:
# install heroku CLI
- wget -qO- https://toolbelt.heroku.com/install.sh | sh
# login to docker registries (dockerhub + heroku)
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- echo "$HEROKU_PASSWORD" | docker login -u "$HEROKU_USERNAME" --password-stdin registry.heroku.com

install:
# install deps
- yarn install

script:
- yarn test
- yarn build
# build docker images
- docker build -t unqpdes/todo-list-front .
- docker tag unqpdes/todo-list-front registry.heroku.com/$HEROKU_APP_NAME/web

deploy:
provider: script
script:
# push to dockerhub & heroku
docker push unqpdes/todo-list-front;
docker push registry.heroku.com/$HEROKU_APP_NAME/web;
heroku container:release web --app $HEROKU_APP_NAME

on:
branch: master

Cambios en las apps

Notas de Troubleshooting

Debuggear cuando no buildea travis

Particularidades del Backend: Conexión a Mongo

Asegurarse de elegir el plan FREE :P

Reverse Proxy

[entryPoints]
[entryPoints.http]
address = ":80" # will be overriden

[frontends]
[frontends.frontend1]
backend = "backend1"

[frontends.frontend2]
backend = "backend2"
[frontends.frontend2.routes.test_1]
rule = "Path:/todos"

[backends]
[backends.backend1]
[backends.backend1.servers.server1]
url = "https://pdes-2018-todo-list-front.herokuapp.com/"
[backends.backend2]
[backends.backend2.servers.server1]
url = "https://pdes-2018-todo-list-back.herokuapp.com/"
#!/bin/sh
echo "Starting traefik on port $PORT!"

traefik --file --entrypoints="NAME:http Address::$PORT"
FROM traefik:alpine

COPY traefik/traefik.toml /traefik.toml
ADD entrypoint.sh /

CMD ["/entrypoint.sh"]
ENTRYPOINT [ "/entrypoint.sh" ]

Links

Javier Fernandes

Written by

Software Engineer@SCVSoft. Professor@UNQ (Public National University, Argentina). Creator of Wollok Programming Language. Always learning & creating things :)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade