|
| 1 | +# syntax=docker/dockerfile:1.3-labs |
| 2 | +ARG NODE_VERSION |
| 3 | + |
| 4 | +FROM node:${NODE_VERSION}-alpine AS base |
| 5 | +RUN apk add --no-cache cpio findutils git |
| 6 | +WORKDIR /src |
| 7 | + |
| 8 | +FROM base AS deps |
| 9 | +RUN --mount=type=bind,target=.,rw \ |
| 10 | + --mount=type=cache,target=/src/node_modules <<EOT |
| 11 | +yarn install |
| 12 | +mkdir /vendor |
| 13 | +cp yarn.lock /vendor |
| 14 | +EOT |
| 15 | + |
| 16 | +FROM scratch AS vendor-update |
| 17 | +COPY --from=deps /vendor / |
| 18 | + |
| 19 | +FROM deps AS vendor-validate |
| 20 | +RUN --mount=type=bind,target=.,rw <<EOT |
| 21 | +set -e |
| 22 | +git add -A |
| 23 | +cp -rf /vendor/* . |
| 24 | +diff=$(git status --porcelain -- yarn.lock) |
| 25 | +if [ -n "$diff" ]; then |
| 26 | + echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor-update"' |
| 27 | + echo "$diff" |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | +EOT |
| 31 | + |
| 32 | +FROM deps AS build |
| 33 | +RUN --mount=type=bind,target=.,rw \ |
| 34 | + --mount=type=cache,target=/src/node_modules <<EOT |
| 35 | +yarn run build |
| 36 | +mkdir /out |
| 37 | +cp -Rf dist /out/ |
| 38 | +EOT |
| 39 | + |
| 40 | +FROM scratch AS build-update |
| 41 | +COPY --from=build /out / |
| 42 | + |
| 43 | +FROM build AS build-validate |
| 44 | +RUN --mount=type=bind,target=.,rw <<EOT |
| 45 | +set -e |
| 46 | +git add -A |
| 47 | +cp -rf /out/* . |
| 48 | +diff=$(git status --porcelain -- dist) |
| 49 | +if [ -n "$diff" ]; then |
| 50 | + echo >&2 'ERROR: Build result differs. Please build first with "docker buildx bake build"' |
| 51 | + echo "$diff" |
| 52 | + exit 1 |
| 53 | +fi |
| 54 | +EOT |
| 55 | + |
| 56 | +FROM deps AS format |
| 57 | +RUN --mount=type=bind,target=.,rw \ |
| 58 | + --mount=type=cache,target=/src/node_modules <<EOT |
| 59 | +yarn run format |
| 60 | +mkdir /out |
| 61 | +find . -name '*.ts' -not -path './node_modules/*' | cpio -pdm /out |
| 62 | +EOT |
| 63 | + |
| 64 | +FROM scratch AS format-update |
| 65 | +COPY --from=format /out / |
| 66 | + |
| 67 | +FROM deps AS format-validate |
| 68 | +RUN --mount=type=bind,target=.,rw \ |
| 69 | + --mount=type=cache,target=/src/node_modules \ |
| 70 | + yarn run format-check |
| 71 | + |
| 72 | +FROM deps AS test |
| 73 | +ENV RUNNER_TEMP=/tmp/github_runner |
| 74 | +ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache |
| 75 | +RUN --mount=type=bind,target=.,rw \ |
| 76 | + --mount=type=cache,target=/src/node_modules \ |
| 77 | + yarn run test --coverageDirectory=/tmp/coverage |
| 78 | + |
| 79 | +FROM scratch AS test-coverage |
| 80 | +COPY --from=test /tmp/coverage / |
0 commit comments