QuarKUS7
QuarKUS7

Reputation: 133

Set .travis.yml to automatically deploy docker image

I am deploying a web app written in python (flask) in Docker container to Heroku using Travis-CI. How to set up travis.yml to deploy an image to Heroku automatically?

I am able to login to Docker and push the image there automatically.

My .travis.yml:

language: python
sudo: required

services:
  - docker

before_install:
  - docker build -t quarkus7/which-tram .

script:
  - docker run quarkus7/which-tram python test.py

after_success:
  - bash docker_hub_push
  - docker tag quarkus7/which-tram registry.heroku.com/$HEROKU_APP_NAME/web
  - docker push registry.heroku.com/$HEROKU_APP_NAME/web
  - ( echo "$HEROKU_USERNAME" echo "$HEROKU_PASSWORD" ) | heroku login -i
  - heroku container:login
  - heroku container:release web --app $HEROKU_APP_NAME

However I get an error in Travis log:

$ ( echo "$HEROKU_USERNAME" echo "$HEROKU_PASSWORD" ) | heroku login -i
heroku: Enter your login credentials
Email: Password: sh: 1: read: Illegal option -s

Do you know how to amend .travis.yml in order to login to Heroku and release the container?

Upvotes: 1

Views: 812

Answers (2)

Mihir Joshi
Mihir Joshi

Reputation: 450

This is how you can login to push to the heroku registry:

.travis.yml:

before_install:
- wget -qO- https://toolbelt.heroku.com/install.sh | sh #installed heroku CLI
- docker login -u "$HEROKU_USERNAME" --password=$(heroku auth:token) registry.heroku.com #logged in

$HEROKU_USERNAME is your Heroku e-mail.

And then, deploy using heroku container:release like this:

deploy:
  provider: script
  script: 
    heroku container:release web --app your-app-name

Upvotes: 1

Yang J
Yang J

Reputation: 38

There are some methods: Script "heroku login" in a CI environment. I think you can try Method 2: Environment Variable.

Upvotes: 0

Related Questions