简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM