Deploy docker container from external registry to Heroku

后端 未结 2 821
深忆病人
深忆病人 2021-02-05 22:50

I got project repository hosted on gitlab. I am using gitlab-ci to build docker container from my project. What I would like to achieve is deploying that container to heroku.

相关标签:
2条回答
  • 2021-02-05 23:09

    You are starting the app for some reason (using docker run) you might don't need. The dpl tool is intended to be used inside a codebase, rather than for image deployment. As you said

    build_image:
      image: docker:latest
      services:
      - docker:dind
      stage: package
      script:
        - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
        - docker build -t registry.gitlab.com/maciejsobala/myApp .
        - docker push registry.gitlab.com/maciejsobala/myApp:latest
    

    is working, what means your runner is able to run docker in docker and successfully pushing images. For heroku deployment, you must only push that image to the heroku docker registry, according to the official heroku documentation. In short you do a

    deploy_to_heroku:
      stage: deploy
      services:
      - docker:dind
      script:
        - docker login --email=_ --username=_ --password=<YOUR-HEROKU-AUTH-TOKEN> registry.heroku.com
        - docker tag registry.gitlab.com/maciejsobala/myApp:latest registry.heroku.com/maciejsobala/myApp:latest
        - docker push registry.heroku.com/maciejsobala/myApp:latest
    

    with your heroku auth token, which you can get by heroku auth:token

    As said in the documentation, pushing to herokus registry triggers a release process of the app.

    0 讨论(0)
  • 2021-02-05 23:20

    The reason for

    "No such image: registry.gitlab.com/username/image:tag"

    error is that tag source should be pulled beforehand. script block should include a docker pull statement. The overall script block should be as follows:

      script:
        - docker login --email=_ --username=_ --password=<YOUR-HEROKU-AUTH-TOKEN> registry.heroku.com
        - docker pull registry.gitlab.com/maciejsobala/myApp:latest
        - docker tag registry.gitlab.com/maciejsobala/myApp:latest registry.heroku.com/maciejsobala/myApp:latest
        - docker push registry.heroku.com/maciejsobala/myApp:latest
    

    Still this is not enough. Heroku changed its release policy so that pushing to Heroku Container Registry does not trigger a release anymore. Here is the extra command to fulfill the missing release task:

        - docker run --rm -e HEROKU_API_KEY=<YOUR-HEROKU-AUTH-TOKEN> wingrunr21/alpine-heroku-cli container:release web --app myApp
    
    0 讨论(0)
提交回复
热议问题