无法使用 travis 将多容器 docker 应用程序部署到 heroku

Trouble deploying multi-container docker application to heroku using travis

所以我真的有几个问题。这是我的 travis.yml 文件,这是最新的 运行 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;



出于某种原因,我无法部署到 heroku。 docker push registry.heroku.com/$HEROKU_APP/container_name 似乎与 echo "$HEROKU_API" | 一起工作。 docker login -u "$HEROKU_USERNAME" --password-stdin registry.heroku.com sign in 但是当我去释放 heroku 容器时,在终端中说“提供的凭据无效”并告诉我登录。有没有办法在 Travis 上使用 docker CLI 释放这些容器?

如果没有,Heroku CLI 会有帮助吗?

所以我最终通过简单地将 $HEROKU_API 更改为 $HEROKU_API_KEY 解决了这个问题。这是一个环境变量,当它存在时会自动将您登录到 Heroku CLI,使您能够 运行 上传到 docker 容器到 Heroku 所需的脚本。这是 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_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;

我现在在 Heroku 中确实有错误 :P