-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae2b315
commit 9c13344
Showing
7 changed files
with
666 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
**/node_modules | ||
**/dist | ||
|
||
.DS_Store |
This file contains 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
FROM node:20-slim as base | ||
|
||
ENV PNPM_HOME="/root/.local/share/pnpm" | ||
ENV PATH="${PATH}:${PNPM_HOME}" | ||
|
||
RUN corepack enable | ||
RUN pnpm add -g fastify-cli | ||
|
||
FROM base as dependencies | ||
|
||
WORKDIR /app | ||
COPY package.json pnpm-lock.yaml tsconfig.json ./ | ||
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store pnpm fetch --frozen-lockfile --prod | ||
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store pnpm install --frozen-lockfile --prod | ||
|
||
FROM base as build | ||
|
||
WORKDIR /app | ||
COPY package.json pnpm-lock.yaml tsconfig.json ./ | ||
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store pnpm fetch --frozen-lockfile | ||
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store pnpm install --frozen-lockfile | ||
COPY src/ ./src | ||
RUN pnpm build:ts | ||
|
||
FROM base | ||
|
||
WORKDIR /app | ||
COPY --from=dependencies /app/node_modules /app/node_modules | ||
COPY --from=build /app/dist /app/dist | ||
EXPOSE 3000 | ||
CMD ["fastify", "start", "-l", "info", "dist/app.js"] | ||
|
||
#FROM node:20-slim as build | ||
# | ||
#RUN corepack enable | ||
#WORKDIR /app | ||
#COPY package.json pnpm-lock.yaml ./ | ||
#RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store pnpm fetch --frozen-lockfile | ||
#RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store pnpm install --frozen-lockfile --prod |
This file contains 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Fastify API example with optimized Dockerfile for `pnpm` | ||
|
||
This is an example repository that demonstrates a bare bones [Fastify API](https://fastify.dev/) with [`pnpm`]() as the provided package manager. It also includes an example Dockerfile that is optimized to build the image as quick as possible [via the guide here](https://depot.dev/docs/languages/node-pnpm-dockerfile). |
This file contains 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "example-api-project", | ||
"version": "0.0.1", | ||
"description": "This is an example Fastify API project that uses pnpm and TypeScript.", | ||
"main": "index.ts", | ||
"scripts": { | ||
"start": "node -r source-map-support ./dist/index.js", | ||
"build": "tsc", | ||
"watch": "tsc -w" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"fastify": "^4.22.0", | ||
"source-map-support": "^0.5.21" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.5.7", | ||
"prettier": "^3.0.3", | ||
"prettier-plugin-organize-imports": "^3.2.3", | ||
"prettier-plugin-pkg": "^0.18.0", | ||
"ts-node": "^10.4.0", | ||
"typescript": "^5.2.2" | ||
}, | ||
"prettier": { | ||
"printWidth": 120, | ||
"semi": false, | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"bracketSpacing": false | ||
} | ||
} |
Oops, something went wrong.