Reputation: 836
I want to have a separate docker container that build's my app, and when it finishes, it passes a 'dist' catalog to second container, which is deployed.
I tried using the artifacts and "volume" instruction, but it seems not to work. Anybody nows any work-around or solution?
.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
Upvotes: 0
Views: 4251
Reputation: 11388
What you are looking for is caching:
cache is used to specify a list of files and directories which should be cached between builds.
So you would define something like this in the root of your gitlab-ci.yml
:
cache:
untracked: true
key: "$CI_BUILD_REF_NAME"
paths:
- dist/
build_app: ...
The dist/
will then be cached among all builds.
Upvotes: 2
Reputation: 1131
Your issue is that you're not using the VOLUME command correctly in build.docker. If you boot build:latest image, the contents of /app/dist are copied to the container directory on the host file system. That is not equal to your current working directory.
Here's a fixed version:
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
Upvotes: 1