我正在嘗試將我的測驗移動到我的 docker 映像構建階段,但它似乎完全忽略了我的測驗構建,并且在我構建映像時跳過它。
可能是什么問題?
# Base build
FROM node:16.13 AS build
RUN mkdir /app
WORKDIR /app
ADD package*.json ./
RUN npm i -g [email protected]
RUN npm i --production
COPY . .
RUN npm run build
# Clean
RUN npm prune --production
RUN npm install -g node-prune
RUN node-prune
# Test
FROM build AS test
RUN npm i -g [email protected]
RUN npm i -D jest typescript
RUN npm i -D ts-jest @types/jest
RUN npm i -D @shelf/jest-mongodb
RUN npx jest
# Release
FROM node:16.13-alpine
RUN mkdir /app
WORKDIR /app
COPY --from=build /app/dist ./dist/
COPY --from=build /app/node_modules ./node_modules/
COPY --from=build /app/package.json ./
CMD npm start
在上面你可以看到我Dockerfile在哪里準備構建,然后計劃進行測驗,然后,我正在制作我的發布影像。
我已經玩了幾個小時了。我清除了快取,對檔案中的順序進行了調整)但沒有幫助。它一直忽略我的測驗版本。
歡迎任何關于我的 Dockerfile 的暗示
uj5u.com熱心網友回復:
Docker 內部有兩個不同的系統來構建鏡像。較新的 Dockers 默認使用名為BuildKit的較新系統。主要區別之一是兩個系統處理多階段構建的方式:舊系統只運行所有構建階段直到結束,但 BuildKit 計算出最后階段COPY --from=build但不使用test階段中的任何內容,并且只是跳過它。
我不會在 Dockerfile(因為它不會產生可運行的工件)或 Docker 中運行這些測驗。在構建 Docker 映像之前,我可能會在基于主機的開發環境中運行它們:
# On the host
npm install # devDependencies include all test dependencies
npm run tests # locally
# repeat until the tests pass (without involving a container)
# Build the image _after_ the tests pass
docker build -t myapp .
docker build還可以選擇--target命名特定階段,以便您可以告訴 Docker“構建測驗映像”,但您只需立即將其洗掉。這就是我認為 Docker 作為測驗運行者不太有意義的地方。
docker build -t delete-me --target test
docker build -t my-app .
docker rmi delete-me
您的 Dockerfile 還安裝了一個 MongoDB 測驗助手。如果測驗依賴于實時資料庫而不是模擬實作,那么這里要注意的另一件事是 Dockerfile 中的代碼永遠無法連接到其他容器。在這種情況下,您必須從其他地方運行此測驗。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/412499.html
標籤:
上一篇:如何洗掉磁區的唯一子磁區
下一篇:如何測驗是否單擊了反應組件
