Docker/CI: 获取在另一个阶段创建的nodeJS应用程序的访问权限

Docker/CI: Get access to nodeJS app, which is created in another stage

在我的 CI 管道 (gitlab) 中有一个 build 和一个 end2end-testing 阶段。在构建阶段,将创建应用程序的文件。然后我想将生成的文件复制到 e2e_testing 容器中,以对该应用程序进行一些测试。

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

对于 e2e 测试,我想使用 nightwatchJS - 请参见下面的 e2e docker 图片。也许可以在 e2e 映像中使用构建映像?

我需要做的是对生成的 nodeJS 应用程序进行 nightwatchJS e2e 测试


我的尝试

使用 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 图像创建一个容器。所以在这个容器中不存在 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 的容器是从这个图像创建的,它一直是 运行。所以当时 CI 管道是 运行,容器已经存在。

但当时创建此映像时应用程序文件不存在,因为它们是在构建阶段生成的。所以我无法使用 Dockerfile 将这些文件放入 docker 图像中。

那么如何在e2e阶段获取build阶段生成的文件呢?

或者是否可以在守夜人映像 (e2e) 中使用构建映像 ($CI_REGISTRY_IMAGE:latest)

使用 artifacts 怎么样?

基本上是在构建之后将 bundle 文件夹移动到存储库的根目录,并将 bundle 文件夹定义为工件。然后,从 e2e 作业中,将从构建阶段的工件下载 bundle 文件夹,您将能够使用其内容。下面是如何执行此操作的示例:

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 部分,所以我把它留在那里,以防你想把那个容器推到某个地方。