将 docker 容器从外部注册表部署到 Heroku [英] Deploy docker container from external registry to Heroku
问题描述
我在 gitlab 上托管了项目存储库.我正在使用 gitlab-ci 从我的项目中构建 docker 容器.我想要实现的是将该容器部署到heroku.
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.
我试图遵循这个问题的解决方案:如何使用 Jhipster、Docker、Gitlab 和 Heroku 构建、测试和部署
I was trying to follow solution from this question: How to build, test and deploy using Jhipster, Docker, Gitlab and Heroku
这是我的 .gitlab-ci.yaml
的样子:
stages:
- build
- package
- deploy
build_npm:
image: node:latest
stage: build
script:
- npm install
- npm run build:prod
artifacts:
paths:
- dist/
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
deploy_to_heroku:
stage: deploy
services:
- docker:dind
script:
- gem install dpl
- docker run registry.gitlab.com/maciejsobala/myApp:latest
- dpl --provider=heroku --app= myApp --api-key=$HEROKU_API_KEY
我想要实现的是,有 3 个阶段:
What I am trying to achieve is, have 3 stages:
- build:此时,只编译 npm 项目(以后我想在这里添加一些
jar
) - package:创建并推送到注册表 docker 镜像.
- 部署:在heroku上安装docker镜像.
我遇到了最后阶段(deploy
)的问题.老实说,我不太确定,应该在这里做什么.
I am running into issues with the last stage (deploy
). To be honest I am not really sure, what should be done here.
我尝试使用 dpl,关于本教程:https://docs.gitlab.com/ce/ci/examples/test-and-deploy-ruby-application-to-heroku.html
I tried to use dpl, regarding to this tutorial: https://docs.gitlab.com/ce/ci/examples/test-and-deploy-ruby-application-to-heroku.html
不幸的是,我在尝试运行 docker image 时遇到了问题
Unfornatelly I am running into issues when trying to run docker image
$ docker run registry.gitlab.com/maciejsobala/myApp:latest
/bin/bash: line 49: docker: command not found
我在这里完全失明.我非常感谢任何解决方案、文章/教程的链接等.
I am completely blind here. I would really appreciate any solutions, links to articles/tutorials etc.
推荐答案
由于某些原因(使用 docker run
)您可能不需要启动应用程序.dpl
工具旨在用于代码库内部,而不是用于映像部署.正如你所说的
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
正在工作,这意味着您的跑步者能够在 docker 中运行 docker 并成功推送图像.根据 theheroku 官方文档.总之你做一个
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
使用您的 heroku 身份验证令牌,您可以通过 heroku auth:token
with your heroku auth token, which you can get by heroku auth:token
如文档中所述,推送到 herokus 注册表会触发应用程序的发布过程.
As said in the documentation, pushing to herokus registry triggers a release process of the app.
这篇关于将 docker 容器从外部注册表部署到 Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!