-
Notifications
You must be signed in to change notification settings - Fork 29
refactor(lint-pr-title): modernise Dockerfile #1121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
iainlane
merged 1 commit into
iainlane/fix-lint-pr-title-action
from
iainlane/refactor-lint-pr-title-dockerfile
Jul 15, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,48 +1,52 @@ | ||
| # This file must be built from the root of the repository. | ||
| # Example: docker build . -f actions/lint-pr-title/Dockerfile | ||
|
|
||
| FROM oven/bun:1.2.18@sha256:2cdd9c93006af1b433c214016d72a3c60d7aa2c75691cb44dfd5250aa379986b AS base | ||
|
|
||
| # Create a non-root user with a home directory | ||
| # Run tests as non-root user because one test expects EACCES when writing to a | ||
| # read-only file, and this will not fail as root. | ||
| RUN useradd -ms /bin/bash -d /home/newuser newuser | ||
| WORKDIR /usr/src/app | ||
|
|
||
| # Create a non-root user to run the tests. Run tests as non-root user because | ||
| # one test expects EACCES when writing to a read-only file, and this will not | ||
| # fail as root. | ||
| RUN useradd -ms /bin/bash newuser | ||
|
|
||
| # Install dependencies | ||
| FROM base AS deps | ||
|
|
||
| COPY package.json bun.lock ./ | ||
| COPY actions/dependabot-auto-triage/package.json ./actions/dependabot-auto-triage/ | ||
|
|
||
| # Because we use bun's workspaces, we need to have all package.json files | ||
| # available, even if they're not used. (We filter to one workspace.) | ||
| COPY actions/get-latest-workflow-artifact/package.json ./actions/get-latest-workflow-artifact/ | ||
| COPY actions/lint-pr-title/package.json ./actions/lint-pr-title/ | ||
|
|
||
| RUN --mount=type=cache,target=/root/.bun/install/cache \ | ||
| bun install --frozen-lockfile --filter lint-pr-title | ||
|
|
||
| # Run tests | ||
| FROM base AS test | ||
|
|
||
| COPY --from=deps /usr/src/app/node_modules ./node_modules | ||
| COPY --chown=newuser:newuser actions/lint-pr-title/ ./actions/lint-pr-title/ | ||
| USER newuser | ||
| WORKDIR /home/newuser | ||
|
|
||
| FROM base AS install | ||
| RUN mkdir -p temp/dev | ||
| WORKDIR /home/newuser/temp/dev | ||
| COPY --chown=newuser:newuser package.json bun.lock ./ | ||
| COPY --chown=newuser:newuser actions/dependabot-auto-triage/package.json ./actions/dependabot-auto-triage/ | ||
| COPY --chown=newuser:newuser actions/get-latest-workflow-artifact/package.json ./actions/get-latest-workflow-artifact/ | ||
| COPY --chown=newuser:newuser actions/lint-pr-title/package.json ./actions/lint-pr-title/ | ||
| RUN bun install --frozen-lockfile --filter lint-pr-title | ||
|
|
||
| # install with --production (exclude devDependencies) | ||
| RUN mkdir -p temp/prod | ||
| WORKDIR /home/newuser/temp/prod | ||
| COPY --chown=newuser:newuser package.json bun.lock ./ | ||
| COPY --chown=newuser:newuser actions/dependabot-auto-triage/package.json ./actions/dependabot-auto-triage/ | ||
| COPY --chown=newuser:newuser actions/get-latest-workflow-artifact/package.json ./actions/get-latest-workflow-artifact/ | ||
| COPY --chown=newuser:newuser actions/lint-pr-title/package.json ./actions/lint-pr-title/ | ||
| RUN bun install --frozen-lockfile --production --filter lint-pr-title | ||
|
|
||
| FROM base AS prerelease | ||
| WORKDIR /home/newuser/app | ||
| COPY --from=install /home/newuser/temp/dev/node_modules ./node_modules | ||
| COPY --chown=newuser:newuser . . | ||
|
|
||
| # Install dev dependencies to run the tests | ||
|
|
||
| ENV NODE_ENV=development | ||
|
|
||
| RUN bun run --filter lint-pr-title test | ||
iainlane marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| FROM base AS release | ||
| # Assemble final image from a clean stage | ||
| FROM base | ||
|
|
||
| USER root | ||
|
|
||
| WORKDIR /usr/src/app | ||
| COPY --from=install /home/newuser/temp/prod/node_modules ./node_modules | ||
| COPY --from=prerelease /home/newuser/app/actions/lint-pr-title/src ./actions/lint-pr-title/src | ||
| COPY --from=prerelease /home/newuser/app/actions/lint-pr-title/package.json ./actions/lint-pr-title/ | ||
| COPY --from=prerelease /home/newuser/app/actions/lint-pr-title/commitlint.config.js ./actions/lint-pr-title/ | ||
|
|
||
| COPY --from=deps /usr/src/app/node_modules ./node_modules | ||
| COPY actions/lint-pr-title/src ./actions/lint-pr-title/src | ||
| COPY actions/lint-pr-title/package.json ./actions/lint-pr-title/ | ||
| COPY actions/lint-pr-title/commitlint.config.js ./actions/lint-pr-title/ | ||
|
|
||
| WORKDIR /usr/src/app/actions/lint-pr-title | ||
|
|
||
| ENTRYPOINT [ "bun", "run", "src/index.ts" ] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it perhaps make sense to have the cache filled only with production dependencies and then another one that is filled with dev dependencies for the test run?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One cache makes sense to me, enables things to be shared, moved around when needed