首页 > 解决方案 > dockerfile:在多个存储库上运行工具

问题描述

我有一个 cli 工具,我正在使用 docker 创建一个 E2E 测试套件。基本思想是在 docker 容器中构建本地代码,然后在多个公共存储库上运行该工具。这样做的主要目的是更容易地查看我的 CLI 工具可能需要添加的任何缺失功能。

我确实设法让它工作,但由于所有的链接和文件夹管理,管理起来有点痛苦。

## Build a node application
from node:8.11.1
WORKDIR /app

## Copy all the files
COPY . ./sortier

## Build run and test
RUN  cd ./sortier \
  && npm install --unsafe-perm \
  && npm run test \
  && cd .. \
## Run react-redux-typescript-guide/playground test
  && pwd \
  && git clone https://github.com/piotrwitek/react-redux-typescript-guide  \
  && cd react-redux-typescript-guide/playground \
  && npm install --unsafe-perm \
  && echo "{ isHelpMode: true }" > .sortierrc \
  && cd ../../sortier \
  && npm run start -- "../react-redux-typescript-guide/playground/src/**/*.ts" \
  && npm run start -- "../react-redux-typescript-guide/playground/src/**/*.tsx" \
  && cd ../react-redux-typescript-guide/playground \
  && npm run build \
  && cd ../.. \
## Run prettier test
  && pwd \
  && git clone https://github.com/prettier/prettier \
  && cd prettier \
  && npm install --unsafe-perm \
  && echo "{ isHelpMode: true }" > .sortierrc \
  && cd .. \
  && npm run start -- "prettier/src/**/*.js" \
  && cd prettier \
  && npm run build \
  && npm run test \
  && cd ..

我试图弄清楚如何使用 WORKDIR 来更改目录,这将对其进行大量清理,但能够相互引用工作目录似乎不起作用。

关于如何清理这个 dockerfile 的任何建议?

标签: dockerdockerfile

解决方案


当然,在我发布问题后,我会找到答案(do'h)

## Build a node application
from node:8.11.1

## Sortier creation, build and test
WORKDIR /sortier
COPY . .
RUN npm install --unsafe-perm
RUN npm run test

## react-redux-typescript-guide/playground
WORKDIR /react-redux-typescript-guide
RUN git clone https://github.com/piotrwitek/react-redux-typescript-guide .
WORKDIR /react-redux-typescript-guide/playground
RUN npm install --unsafe-perm
RUN echo "{ isHelpMode: true }" > .sortierrc
WORKDIR /sortier
RUN npm run start -- "/react-redux-typescript-guide/playground/src/**/*.ts"
RUN npm run start -- "/react-redux-typescript-guide/playground/src/**/*.tsx"
WORKDIR /react-redux-typescript-guide/playground
RUN npm run build
RUN set CI=true&&npm run test

## prettier
WORKDIR /prettier
RUN git clone https://github.com/prettier/prettier
WORKDIR /prettier
RUN npm install --unsafe-perm
RUN echo "{ isHelpMode: true }" > .sortierrc
WORKDIR /sortier
RUN npm run start -- "/prettier/src/**/*.js"
WORKDIR /prettier
RUN npm run build
RUN npm run test

推荐阅读