-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: turbo cache, generic build dockerfile, dependency caching in g…
…ithub actions (#1116) Makes various build improvements - utilises turbo repo remote cache in build and lint pipeline - produces an automated Dockerfile.build which is capable of building any node based target in the monorepo without specifying manually the dependencies to bundle in the output - updates README to explain Dockerfile.build - utilises `npm i` cache in the Github Actions
- Loading branch information
Showing
17 changed files
with
294 additions
and
119 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 |
---|---|---|
|
@@ -3,4 +3,5 @@ docs/ | |
node_modules/ | ||
tests/ | ||
.env | ||
Dockerfile.build | ||
out |
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
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
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,93 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
# BASED ON https://turbo.build/repo/docs/guides/tools/docker | ||
# AND https://github.com/ThaddeusJiang/turborepo-starter/blob/main/apps/api/Dockerfile | ||
|
||
# Use Node 20 base | ||
FROM node:20-alpine AS alpine | ||
|
||
# What is the @faims3/... name of the package to build | ||
ARG PACKAGE_NAME | ||
ENV PACKAGE_NAME=${PACKAGE_NAME} | ||
|
||
# What directory relative to the monorepo will the node build folder containing | ||
# index.js be built to. For example API -> api/build/src | ||
ARG NODE_RUN_DIR | ||
ENV NODE_RUN_DIR=${NODE_RUN_DIR} | ||
|
||
# install some dependencies | ||
RUN apk update && apk add --no-cache libc6-compat | ||
|
||
# create this layer to use to avoid repeatedly installing | ||
FROM alpine AS base | ||
|
||
# PRUNE TO GET DEPENDENCIES [pruner] | ||
# =================================== | ||
|
||
# Use turbo to prune package dependencies | ||
FROM base AS pruner | ||
|
||
# work in /app folder | ||
WORKDIR /app | ||
|
||
# install turbo global | ||
RUN npm install turbo@^2.0.11 -g | ||
|
||
# copy everything into pruner | ||
COPY . . | ||
|
||
# prune using turbo for only faims3 and it's dependencies. This produces an | ||
# /app/out folder which has /full (all needed deps) or /json (package*.json | ||
# only) | ||
RUN turbo prune ${PACKAGE_NAME} --docker | ||
|
||
|
||
# INSTALL PACKAGES [builder] | ||
# ============================ | ||
|
||
# add lockfiles dependencies | ||
FROM base AS builder | ||
|
||
WORKDIR /app | ||
|
||
# Install dependencies | ||
COPY .gitignore .gitignore | ||
COPY --from=pruner /app/out/json/ . | ||
|
||
# install turbo global | ||
RUN npm install turbo@^2.0.11 -g | ||
RUN npm install | ||
|
||
|
||
# Build the project | ||
COPY --from=pruner /app/out/full/ . | ||
COPY --from=pruner /app/out/json/ json | ||
|
||
# build packages using turbo | ||
RUN turbo run build --filter=${PACKAGE_NAME} | ||
|
||
# Package all necessary files to run app into pruner out | ||
COPY bundle.sh . | ||
RUN sh bundle.sh json . out && cp -R json/* /app/out/ | ||
|
||
# PRODUCTION RUNNER [runner] | ||
# ========================== | ||
|
||
FROM alpine AS runner | ||
WORKDIR /app | ||
|
||
# Don't run production as root | ||
RUN addgroup --system --gid 1001 nodejs | ||
RUN adduser --system --uid 1001 faims | ||
USER faims | ||
|
||
# Copy all files which are required to run the app | ||
COPY --from=builder /app/out . | ||
|
||
# Run the node app | ||
WORKDIR /app/${NODE_RUN_DIR} | ||
|
||
CMD ["node", "index.js"] | ||
|
||
|
||
|
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
"main": "build/src/index.js", | ||
"packageManager": "[email protected]", | ||
"engines": { | ||
"node": "20.9.0" | ||
"node": "^20.9.0" | ||
}, | ||
"scripts": { | ||
"lint": "gts lint", | ||
|
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 |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
] | ||
}, | ||
"engines": { | ||
"node": "20.9.0" | ||
"node": "^20.9.0" | ||
}, | ||
"scripts": { | ||
"start": "vite", | ||
|
Oops, something went wrong.