2017-04-25 51 views
1

在我的CI管道(gitlab)中,有一個構建和一個end-end-testing階段。在構建階段,應用程序的文件將被創建。然後我想將生成的文件複製到e2e_testing容器中,以使用此應用程序進行一些測試。Docker/CI:訪問在另一個階段創建的nodeJS應用程序

如何將生成的文件(/ opt/project/build/core/bundle)複製到映像中?

對於e2e測試,我想使用nightwatchJS - 請參閱下面的e2e docker鏡像。也許有可能在e2e圖像中使用構建圖像?

我需要做的是對生成的應用程序的NodeJS


我嘗試

複製生成的文件e2e_testing容器docker cp命令nightwatchJS端對端測試。

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階段的構建階段生成的文件?

或者是有可能使用的生成圖像($ CI_REGISTRY_IMAGE:最新)夜巡圖像(E2E)內

+0

https://github.com/moby/moby/pull/31257 – johnharris85

+0

@ johnharris85我沒有看到,你想向我展示哪個部分... :-( – user3142695

+0

什麼應用解析這些yml文件?ie你使用什麼CI工具? – BMitch

回答

0

怎麼樣使用artifacts

基本上,在構建之後,將包文件夾移到存儲庫的根目錄,並將包文件夾定義爲工件。然後,從e2e作業中,將從構建階段的工件下載該文件夾文件夾,並且您將能夠使用其內容。下面是如何做到這一點的例子:

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一部分,所以我把它在那裏的情況下,你想不想找個推動該容器。

+0

爲什麼我必須將文件夾複製到根目錄?難道不能用原始路徑設置工件嗎? – user3142695

+0

如果您查看了答案中鏈接的工件文檔,您會看到:「您只能使用項目工作區內的路徑。」 – Jawad

相關問題