Skip to content

Commit

Permalink
example fastify project
Browse files Browse the repository at this point in the history
  • Loading branch information
kylegalbraith committed Sep 22, 2023
1 parent ae2b315 commit 9c13344
Show file tree
Hide file tree
Showing 7 changed files with 666 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/node_modules
**/dist

.DS_Store
39 changes: 39 additions & 0 deletions node/pnpm-fastify/Dockerfile
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
3 changes: 3 additions & 0 deletions node/pnpm-fastify/README.md
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).
33 changes: 33 additions & 0 deletions node/pnpm-fastify/package.json
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
}
}
Loading

0 comments on commit 9c13344

Please sign in to comment.