Docker / CI:访问在另一个阶段创build的nodeJS应用程序

在我的CIpipe道(gitlab)中有一个构build和一个end2endtesting阶段。 在构build阶段,应用程序的文件将被创build。 然后我想复制生成的文件到e2e_testing容器做一些testing与这个应用程序。

如何将生成的文件(/ opt / project / build / core / bundle)复制到映像中?

对于e2etesting,我想使用nightwatchJS – 请参阅下面的e2e docker镜像。 也许有可能在e2e图像中使用构build图像?

我需要做的是nightwatchJS e2etesting生成的nodeJS应用程序


我的企图

使用e2e_testing docker cp命令将生成的文件复制到e2e_testing容器。

 build: stage: build before_script: - meteor build /opt/project/build/core --directory script: - cd /opt/jaqua/build/core/bundle - docker build -t $CI_REGISTRY_IMAGE:latest . after_script: - docker cp /opt/project/build/core/bundle e2e_testing:/opt/project/build/core/ 

但是这是行不通的,因为下一阶段(e2e)将会从e2e:latest创build一个容器e2e:latest图像。 所以在这个容器中没有bundle文件夹存在,所以这个示例脚本失败了。

 e2e: image: e2e:latest stage: e2e before_script: - cd /opt/project/build/core/bundle && ls -la script: # - run nightwatchJS to do some e2e testing with the build bundle 

e2e:最新的图片Dockerfile

 FROM java:8-jre ## Node.js setup RUN curl -sL https://deb.nodesource.com/setup_4.x | bash - RUN apt-get install -y nodejs ## Nightwatch RUN npm install -g nightwatch 

一个名为e2e_testing的容器是从这个镜像创build的,并且一直在运行。 所以在CIpipe道运行的时候,容器已经存在了。

但是当时,这个图像是在应用程序文件不存在的情况下创build的,因为它们是在构build阶段生成的。 所以我不能使用Dockerfile将这些文件放在Docker镜像中。

那么我怎样才能访问在e2e阶段的构build阶段生成的文件呢?

或者是否可以在夜视图像(e2e)中使用构build图像($ CI_REGISTRY_IMAGE:latest)

怎么样使用工件 ?

基本上,在构build之后将bundle文件夹移动到版本库的根目录,并将bundle文件夹定义为工件。 然后,从e2e作业中,将从构build阶段的工件下载该文件夹文件夹,并且您将能够使用其内容。 这是一个如何做到这一点的例子:

 build: stage: build before_script: - meteor build /opt/project/build/core --directory script: # Copy the contents of the bundle folder to ./bundle - cp -r /opt/project/build/core/bundle ./bundle - cd /opt/jaqua/build/core/bundle - docker build -t $CI_REGISTRY_IMAGE:latest . artifacts: paths: - bundle e2e: image: e2e:latest stage: e2e dependencies: - build script: - mkdir -p /opt/project/build/core/bundle - cp -r ./bundle /opt/project/build/core/bundle # - run nightwatchJS to do some e2e testing with the build bundle 

我不知道你是否仍然需要docker build部分,所以我把它留在那里,以防你想将该容器推到某个地方。