在构建之间传递文件夹 - GitLab CI 和 Docker
Pass folder between builds - GitLab CI with Docker
我想要一个单独的 docker 容器来构建我的应用程序,当它完成时,它会将 'dist' 目录传递给已部署的第二个容器。
我尝试使用工件和 "volume" 指令,但它似乎不起作用。现在有人有任何解决方法或解决方案吗?
.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
您的问题是您没有在 build.docker 中正确使用 VOLUME 命令。如果启动 build:latest 映像,/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
你要找的是caching:
cache is used to specify a list of files and directories which should be cached between builds.
所以你会在你的 gitlab-ci.yml
:
的 root 中定义这样的东西
cache:
untracked: true
key: "$CI_BUILD_REF_NAME"
paths:
- dist/
build_app: ...
然后 dist/
将在所有构建中缓存。
我想要一个单独的 docker 容器来构建我的应用程序,当它完成时,它会将 'dist' 目录传递给已部署的第二个容器。
我尝试使用工件和 "volume" 指令,但它似乎不起作用。现在有人有任何解决方法或解决方案吗?
.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
您的问题是您没有在 build.docker 中正确使用 VOLUME 命令。如果启动 build:latest 映像,/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
你要找的是caching:
cache is used to specify a list of files and directories which should be cached between builds.
所以你会在你的 gitlab-ci.yml
:
cache:
untracked: true
key: "$CI_BUILD_REF_NAME"
paths:
- dist/
build_app: ...
然后 dist/
将在所有构建中缓存。