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