Skip to content

Commit 507af96

Browse files
committed
Add a test stage to run tests during the image build
1 parent 3b5447e commit 507af96

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Dockerfile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,32 @@ COPY client/public ./public
3737
COPY client/src ./src
3838
RUN yarn build
3939

40+
###################################################
41+
# Stage: test
42+
#
43+
# This stage runs the tests on the backend. This is split into a separate
44+
# stage to allow the final image to not have the test dependencies or test
45+
# cases.
46+
###################################################
47+
FROM base AS test
48+
COPY backend/package.json backend/yarn.lock ./
49+
RUN --mount=type=cache,id=yarn,target=/root/.yarn yarn install --frozen-lockfile
50+
COPY backend/spec ./spec
51+
COPY backend/src ./src
52+
RUN yarn test
53+
4054
###################################################
4155
# Stage: final
4256
#
4357
# This stage is intended to be the final "production" image. It sets up the
4458
# backend and copies the built client application from the client-build stage.
59+
#
60+
# It pulls the package.json and yarn.lock from the test stage to ensure that
61+
# the tests run (without this, the test stage would simply be skipped).
4562
###################################################
4663
FROM base AS final
4764
ENV NODE_ENV=production
48-
COPY backend/package.json backend/yarn.lock ./
65+
COPY --from=test /usr/local/app/package.json /usr/local/app/yarn.lock ./
4966
RUN --mount=type=cache,id=yarn,target=/root/.yarn yarn install --production --frozen-lockfile
5067
COPY backend/src ./src
5168
COPY --from=client-build /usr/local/app/dist ./src/static

0 commit comments

Comments
 (0)