Skip to content

Commit 8f34405

Browse files
committed
chore: add custom dockerfile
1 parent 006b44a commit 8f34405

File tree

5 files changed

+966
-5
lines changed

5 files changed

+966
-5
lines changed

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.env
2+
.git
3+
.github
4+
.next
5+
.vscode
6+
node_modules
7+
8+
*Dockerfile*
9+
*docker-compose*
10+
11+
**/dist
12+
**/__tests__

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Dockerfile

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,53 @@
1-
FROM graphile/postgraphile:4
1+
# Global args, set before the first FROM, shared by all stages
2+
ARG NODE_ENV="production"
23

3-
# Install additional plugins
4-
RUN yarn global add \
5-
postgraphile-plugin-connection-filter-relations \
6-
@graphile-contrib/pg-simplify-inflector
4+
################################################################################
5+
# Build stage 1 - `yarn build`
6+
7+
FROM node:22-alpine as builder
8+
# Import our shared args
9+
ARG NODE_ENV
10+
11+
# Cache node_modules for as long as possible
12+
COPY package.json yarn.lock /app/
13+
WORKDIR /app/
14+
RUN yarn install --frozen-lockfile --production=false --no-progress
15+
16+
# Copy over the server source code
17+
COPY server/ /app/server/
18+
19+
# Finally run the build script
20+
RUN yarn run build
21+
22+
################################################################################
23+
# Build stage 2 - COPY the relevant things (multiple steps)
24+
25+
FROM node:22-alpine as clean
26+
# Import our shared args
27+
ARG NODE_ENV
28+
29+
# Copy over selectively just the things we need, try and avoid the rest
30+
COPY --from=builder /app/package.json /app/yarn.lock /app/
31+
COPY --from=builder /app/server/dist/ /app/server/dist/
32+
33+
################################################################################
34+
# Build stage FINAL - COPY everything, once, and then do a clean `yarn install`
35+
36+
FROM node:22-alpine
37+
# Import our shared args
38+
ARG NODE_ENV
39+
40+
EXPOSE 5000
41+
WORKDIR /app/
42+
# Copy everything from stage 2, it's already been filtered
43+
COPY --from=clean /app/ /app/
44+
45+
# Install yarn ASAP because it's the slowest
46+
RUN yarn install --frozen-lockfile --production=true --no-progress
47+
48+
LABEL description="My PostGraphile-powered server"
49+
50+
# You might want to disable GRAPHILE_TURBO if you have issues
51+
ENV GRAPHILE_TURBO=1
52+
ENV NODE_ENV=$NODE_ENV
53+
ENTRYPOINT yarn start

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"scripts": {
3+
"start": "postgraphile"
4+
},
5+
"dependencies": {
6+
"@graphile-contrib/pg-simplify-inflector": "^6.1.0",
7+
"postgraphile": "^4.14.0",
8+
"postgraphile-plugin-connection-filter-relations": "^2.3.0"
9+
}
10+
}

0 commit comments

Comments
 (0)