我正在尝试使用docker + bitbucket管道进行自动发布;不幸的是,我有问题。我在Docker Hub上阅读了管道部署说明,并创建了以下模板:
# This is a sample build configuration for Docker.
# Check our guides at https://confluence.atlassian.com/x/O1toN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: atlassian/default-image:2
pipelines:
default:
- step:
services:
- docker
script: # Modify the commands below to build your repository.
# Set $DOCKER_HUB_USERNAME and $DOCKER_HUB_PASSWORD as environment variables in repository settings
- export IMAGE_NAME=paweltest/tester:$BITBUCKET_COMMIT
# build the Docker image (this will use the Dockerfile in the root of the repo)
- docker build -t paweltest/tester .
# authenticate with the Docker Hub registry
- docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
# push the new Docker image to the Docker registry
- docker push paweltest/tester:tagname
我已经完成了数据,但是在进行推送之后,构建开始时出现以下错误:
无法准备上下文:lstat / opt / atlassian / pipelines / agent / build / Dockerfile:无干燥文件或目录
我想实现什么?将更改发布到存储库后,我希望自动生成映像并将其发送到Docker集线器,最好发送到应用程序所在的目标服务器。
我一直在寻找解决方案,并尝试了不同的组合。目前,我大约有200项状态为“失败”的提交,没有进一步的想法。
答案 0 :(得分:2)
Bitbucket管道是一项CI / CD服务,您可以构建应用程序并将资源部署到生产或测试服务器实例。您也可以构建和部署docker映像-除非您做错了什么,否则应该没问题...
bitbucket-pipelines.yml
文件中所有已定义的脚本都在根据指示的图像(在您的情况下为atlassian/default-image:2
)创建的容器中运行
您应该在项目中拥有Dockerfile
,并且可以从该文件中构建和发布docker映像。
我创建了没有Dockerfile的简单存储库,然后开始构建:
无法准备上下文:无法评估Dockerfile中的符号链接 路径:lstat / opt / atlassian / pipelines / agent / build / Dockerfile:否这样 文件或目录
我需要在项目中使用Dockerfile
来构建图像(与bitbucket-pipelines.yml
文件处于同一级别):
FROM node:latest
WORKDIR /src/
EXPOSE 4000
下一步,我创建了一个公共的DockerHub存储库:
我还更改了您的bitbucket-pipelines.yml
文件(您忘记了用标签标记新图像):
image: atlassian/default-image:2
pipelines:
default:
- step:
services:
- docker
script:
# build the Docker image (this will use the Dockerfile in the root of the repo)
- docker build -t appngpl/stackoverflow-question-56065689 .
# add new image tag
- docker tag appngpl/stackoverflow-question-56065689 appngpl/stackoverflow-question-56065689:$BITBUCKET_COMMIT
# authenticate with the Docker Hub registry
- docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
# push the new Docker image to the Docker registry
- docker push appngpl/stackoverflow-question-56065689:$BITBUCKET_COMMIT
结果:
一切正常:)
Bitbucket存储库:https://bitbucket.org/krzysztof-raciniewski/stackoverflow-question-56065689
GitHub映像存储库:https://hub.docker.com/r/appngpl/stackoverflow-question-56065689