|
| 1 | +# This file must be built from the root of the repository. |
| 2 | +# Example: docker build . -f actions/lint-pr-title/Dockerfile |
| 3 | + |
1 | 4 | FROM oven/bun:1.2.18@sha256:2cdd9c93006af1b433c214016d72a3c60d7aa2c75691cb44dfd5250aa379986b AS base
|
| 5 | + |
2 | 6 | WORKDIR /usr/src/app
|
3 | 7 |
|
4 |
| -FROM base AS install |
5 |
| -RUN mkdir -p /temp/dev |
6 |
| -COPY package.json bun.lockb /temp/dev/ |
7 |
| -RUN cd /temp/dev && bun install --frozen-lockfile |
| 8 | +# Create a non-root user to run the tests. Run tests as non-root user because |
| 9 | +# one test expects EACCES when writing to a read-only file, and this will not |
| 10 | +# fail as root. |
| 11 | +RUN useradd -ms /bin/bash newuser |
| 12 | + |
| 13 | +# Install dependencies |
| 14 | +FROM base AS deps |
| 15 | + |
| 16 | +COPY package.json bun.lock ./ |
| 17 | +COPY actions/dependabot-auto-triage/package.json ./actions/dependabot-auto-triage/ |
| 18 | + |
| 19 | +# Because we use bun's workspaces, we need to have all package.json files |
| 20 | +# available, even if they're not used. (We filter to one workspace.) |
| 21 | +COPY actions/get-latest-workflow-artifact/package.json ./actions/get-latest-workflow-artifact/ |
| 22 | +COPY actions/lint-pr-title/package.json ./actions/lint-pr-title/ |
| 23 | + |
| 24 | +RUN --mount=type=cache,target=/root/.bun/install/cache \ |
| 25 | + bun install --frozen-lockfile --filter lint-pr-title |
8 | 26 |
|
9 |
| -# install with --production (exclude devDependencies) |
10 |
| -RUN mkdir -p /temp/prod |
11 |
| -COPY package.json bun.lockb /temp/prod/ |
12 |
| -RUN cd /temp/prod && bun install --frozen-lockfile --production |
| 27 | +# Run tests |
| 28 | +FROM base AS test |
13 | 29 |
|
14 |
| -FROM base AS prerelease |
15 |
| -COPY --from=install /temp/dev/node_modules node_modules |
16 |
| -COPY . . |
| 30 | +COPY --from=deps /usr/src/app/node_modules ./node_modules |
| 31 | +COPY --chown=newuser:newuser actions/lint-pr-title/ ./actions/lint-pr-title/ |
| 32 | +USER newuser |
17 | 33 |
|
18 |
| -# Install dev dependencies to run the tests |
19 | 34 | ENV NODE_ENV=development
|
20 |
| -RUN bun install --frozen-lockfile --dev |
21 |
| -RUN bun run test |
22 |
| -RUN bun run build |
23 | 35 |
|
24 |
| -FROM base AS release |
25 |
| -COPY --from=install /temp/prod/node_modules node_modules |
26 |
| -COPY --from=prerelease /usr/src/app/index.ts . |
27 |
| -COPY --from=prerelease /usr/src/app/package.json . |
| 36 | +RUN bun run --filter lint-pr-title test |
| 37 | + |
| 38 | +# Assemble final image from a clean stage |
| 39 | +FROM base |
| 40 | + |
| 41 | +USER root |
| 42 | + |
| 43 | +WORKDIR /usr/src/app |
| 44 | + |
| 45 | +COPY --from=deps /usr/src/app/node_modules ./node_modules |
| 46 | +COPY actions/lint-pr-title/src ./actions/lint-pr-title/src |
| 47 | +COPY actions/lint-pr-title/package.json ./actions/lint-pr-title/ |
| 48 | +COPY actions/lint-pr-title/commitlint.config.js ./actions/lint-pr-title/ |
| 49 | + |
| 50 | +WORKDIR /usr/src/app/actions/lint-pr-title |
28 | 51 |
|
29 |
| -ENTRYPOINT [ "bun", "run", "index.ts" ] |
| 52 | +ENTRYPOINT [ "bun", "run", "src/index.ts" ] |
0 commit comments