我想要一个单独的docker容器来构建我的应用程序,当它完成时,它会传递一个' dist' dist目录到第二个容器,已部署。
我尝试使用工件和"卷"指示,但似乎不起作用。任何人都知道任何解决办法或解决方案吗?
.gitlab-ci.yml
stages:
- build
- push
- deploy
build_app:
stage: build
script:
- ./deployment/build.sh
tags:
- shell
artifacts:
paths:
- /dist
push_app:
stage: push
script:
- ./deployment/push.sh
tags:
- shell
dependencies:
- build_app
deploy_app:
stage: deploy
script:
- ./deployment/deploy.sh
tags:
- shell
build.sh
#!/bin/bash
set -e
echo "Building application"
docker build -t build:latest -f "deployment/build.docker" .
build.docker
RUN mkdir /app
ADD . /app/
WORKDIR /app
//code that creates /dist folder
VOLUME ["/app/dist"]
push.sh
#!/bin/bash
set -e
docker build -t push:latest -f "deployment/push.docker" .
#and other stuff here
push.docker
// the first catalog is not there
ADD /app/dist /web
答案 0 :(得分:2)
您要找的是caching:
cache用于指定应在构建之间缓存的文件和目录列表。
所以你要在gitlab-ci.yml
的 root 中定义类似的内容:
cache:
untracked: true
key: "$CI_BUILD_REF_NAME"
paths:
- dist/
build_app: ...
然后将dist/
缓存在所有版本中。
答案 1 :(得分:1)
您的问题是您没有在 build.docker 中正确使用VOLUME命令。如果引导build:latest image,则会将/ app / dist的内容复制到主机文件系统上的容器目录中。这不等于您当前的工作目录。
这是一个固定版本:
<强> build.sh 强>
#!/bin/bash
set -e
echo "Building application"
docker build -t build:latest -f "deployment/build.docker" .
# Remove old dist directory
rm -rf ${PWD}/dist
# Here we boot the image, make a directory on the host system ${PWD}/dist and mount it into the container.
# After that we copy the files from /app/dist to the host system /dist
docker run -i -v ${PWD}/dist:/dist -w /dist -u $(id -u) \
build:latest sh cp /app/dist /dist
<强> push.docker 强>
// the first catalog is not there
COPY /dist /web