I have a Dockerfile with two stages; the first stage builds a react app from source and the second stage copies that build and adds an NGINX server:
FROM kkarczmarczyk/node-yarn as builder
COPY . /workspace
RUN set -ex \
yarn global add create-react-app \
&& yarn install \
&& GENERATE_SOURCEMAP=false yarn build
FROM nginx:mainline-alpine
COPY ./nginx-default.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /workspace/build /var/www/html/
I'm also using gitlab-ci, and I'd like to have multiple stages: build, test and deploy. But I don't know how to split the build and test stage since I'm using a multistage Dockerfile. The issue there is that all the JS tests (for React) need to be run before "yarn build" gets executed and the build gets copied over to the seconds docker stage.
A solution could be to just execute yarn test
before yarn build
gets run. But I really would like to have a separate test gitlab-ci stage.
Is this possible? Or do I need to split my Dockerfile stages into multiple Dockerfiles?
答案 0 :(得分:0)
您可能想要在gitlab中进行多个阶段的原因是快速失败。 但是使用多阶段docker或gitlab阶段进行构建可以为您提供相同的结果,如果测试失败,您将无法获得进一步的结果,并且可以获得stacktrace。从一方面讲,泊坞窗的多阶段操作更为方便,因为您始终可以调用前一个容器并重现/测试/修复错误。 但是总的来说,在CI中使用docker-builder模式是不必要的复杂操作,最好是将docker映像分开并在gitlab阶段使用它们。
答案 1 :(得分:0)
您是否考虑过使用gitlab工件传递必要的文件?如果您是通过
artifacts:
paths:
- some_path_or_file
然后gitlab在以下阶段提供这些内容。另请参见https://docs.gitlab.com/ee/user/project/pipelines/job_artifacts.html和https://forum.gitlab.com/t/access-artifact-in-next-task-to-deploy/9295/2。