Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

build: improvements for TS & Webpack & Docker #1225

Merged
merged 33 commits into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
cefc402
build: add separate tsconfig.build.json
pano9000 Feb 17, 2025
745b294
build(webpack): output webpack build in build folder
pano9000 Feb 17, 2025
2be9389
build(webpack): change to nosources-source-map
pano9000 Feb 17, 2025
e0c0086
build(tsconfig): fix glob for build config
pano9000 Feb 17, 2025
3a87d71
build(scripts): add build:ts and update build:prepare-dist
pano9000 Feb 17, 2025
d0bb5f9
build(scripts): add webpack progress flag
pano9000 Feb 21, 2025
6c4a173
build(copy-trilium): use `npm run build:ts`
pano9000 Feb 22, 2025
3e307f4
build(scripts): add "build:clean" script for removing dist and build …
pano9000 Feb 23, 2025
e483cbc
build(tsconfig): remove unnecessary exclude lines
pano9000 Feb 23, 2025
60a2b56
chore(copy-dist): removee unnecesary copy of tsconfig.webpack.json
pano9000 Feb 23, 2025
135101f
build(copy-dist): do not copy build folder into src folder
pano9000 Feb 24, 2025
af5e4ee
build(copy-dist): copy over required folders/files from "public" folder
pano9000 Feb 26, 2025
24382d8
build(copy-dist): avoid copying over the app dir into dist
pano9000 Feb 26, 2025
dbc2df0
build(copy-dist): consolidate folder copying
pano9000 Feb 26, 2025
9ac451e
build(copy-dist): consolidate files and folder copying into one asset…
pano9000 Feb 27, 2025
ac3e962
build(copy-dist): simplify "build" copying
pano9000 Feb 27, 2025
dbeae62
build(copy-dist): simplify "copyNodeModuleFileOrFolder" copying
pano9000 Feb 27, 2025
37f1525
build(copy-dist): remove unused paths
pano9000 Feb 27, 2025
a816abb
build(copy-dist): use sync copying
pano9000 Feb 27, 2025
d75cf8c
build(copy-dist): consolidate nodeModules copying into a single loop
pano9000 Feb 27, 2025
3032156
build(copy-dist): execute code in try/catch -> get rid of function
pano9000 Feb 27, 2025
5e289ea
build: get rid of intermediary "build" folder -> use "dist" directly
pano9000 Mar 3, 2025
e389592
build(copy-dist): copying build folder is not required anymore
pano9000 Mar 3, 2025
bb7a4f9
build(Docker): comment out seemingly useless installation of build de…
pano9000 Mar 3, 2025
2973d38
build(Docker): move server-package.json preparation into Dockerfile
pano9000 Mar 3, 2025
c68b0b0
build(Docker): simplify Docker build and runtime stage
pano9000 Mar 5, 2025
e9824c4
build(dockerignore): ignore unnecessary files
pano9000 Mar 5, 2025
6887568
build(Docker): get rid of apparently unused packages at build stage
pano9000 Mar 5, 2025
f544a84
build(Docker): simplify Docker alpine build and runtime stage
pano9000 Mar 5, 2025
3553d64
build(Docker/ci): get rid of running partial build locally
pano9000 Mar 5, 2025
3869005
build(Docker): improve image size, by deleting unnecessary node_modul…
pano9000 Mar 5, 2025
907b8c5
build: copy package-lock.json into dist folder as well
pano9000 Mar 5, 2025
70e227f
build(Docker): improve image size, by deleting node-compile-cache
pano9000 Mar 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
.git
.idea
# ignored Files
.dockerignore
.editorconfig
.git*
.prettier*
electron*
entitlements.plist
forge.config.cjs
nodemon.json
renovate.json
trilium.iml
Dockerfile
Dockerfile.*
npm-debug.log
/src/**/*.spec.ts

# ignored folders
/.cache
/.git
/.github
/.idea
/.vscode
/bin
/build
/dist
/docs
/npm-debug.log
node_modules
/dump-db
/e2e
/integration-tests
/spec
/test
/test-etapi
/node_modules


src/**/*.ts
!src/services/asset_path.ts
# exceptions
!/bin/copy-dist.ts
24 changes: 0 additions & 24 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ jobs:
- test_dev
steps:
- uses: actions/checkout@v4
- name: Set up node & dependencies
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
- run: npm ci
- name: Run the TypeScript build
run: npx tsc
- name: Create server-package.json
run: cat package.json | grep -v electron > server-package.json
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v6
with:
Expand Down Expand Up @@ -82,20 +72,6 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set up node & dependencies
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"

- run: npm ci

- name: Run the TypeScript build
run: npx tsc

- name: Create server-package.json
run: cat package.json | grep -v electron > server-package.json

- name: Build and export to Docker
uses: docker/build-push-action@v6
with:
Expand Down
15 changes: 0 additions & 15 deletions .github/workflows/main-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ jobs:
- name: Run the TypeScript build
run: npx tsc

- name: Create server-package.json
run: cat package.json | grep -v electron > server-package.json

- name: Build and export to Docker
uses: docker/build-push-action@v6
with:
Expand Down Expand Up @@ -154,18 +151,6 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3


- name: Set up node & dependencies
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
- run: npm ci
- name: Run the TypeScript build
run: npx tsc
- name: Create server-package.json
run: cat package.json | grep -v electron > server-package.json

- name: Login to GHCR
uses: docker/login-action@v3
with:
Expand Down
70 changes: 27 additions & 43 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,62 +1,46 @@
# Build stage
FROM node:22.14.0-bullseye-slim AS builder

# Configure build dependencies in a single layer
RUN apt-get update && apt-get install -y --no-install-recommends \
autoconf \
automake \
g++ \
gcc \
libtool \
make \
nasm \
libpng-dev \
python3 \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/app
WORKDIR /usr/src/app/build

# Copy only necessary files for build
COPY . .
COPY server-package.json package.json

# Build and cleanup in a single layer
RUN cp -R build/src/* src/. && \
cp build/docker_healthcheck.js . && \
rm docker_healthcheck.ts && \
npm install && \
npm run build:webpack && \
npm prune --omit=dev && \
RUN npm ci && \
npm run build:prepare-dist && \
npm cache clean --force && \
cp -r src/public/app/doc_notes src/public/app-dist/. && \
rm -rf src/public/app/* && \
mkdir -p src/public/app/services && \
cp -r build/src/public/app/services/mime_type_definitions.js src/public/app/services/mime_type_definitions.js && \
rm src/services/asset_path.ts && \
rm -r build
rm -rf dist/node_modules && \
mv dist/* \
start-docker.sh \
/usr/src/app/ && \
rm -rf \
/usr/src/app/build \
/tmp/node-compile-cache

#TODO: improve node_modules handling in copy-dist/Dockerfile -> remove duplicated work
# currently copy-dist will copy certain node_module folders, but in the Dockerfile we delete them again (to keep image size down),
# as we install necessary dependencies in runtime buildstage anyways

# Runtime stage
FROM node:22.14.0-bullseye-slim

WORKDIR /usr/src/app

# Install only runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
gosu \
&& rm -rf /var/lib/apt/lists/* && \
rm -rf /var/cache/apt/*
RUN apt-get update && \
apt-get install -y --no-install-recommends \
gosu && \
rm -rf \
/var/lib/apt/lists/* \
/var/cache/apt/*

WORKDIR /usr/src/app
COPY --from=builder /usr/src/app ./

# Copy only necessary files from builder
COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/src ./src
COPY --from=builder /usr/src/app/db ./db
COPY --from=builder /usr/src/app/docker_healthcheck.js .
COPY --from=builder /usr/src/app/start-docker.sh .
COPY --from=builder /usr/src/app/package.json .
COPY --from=builder /usr/src/app/config-sample.ini .
COPY --from=builder /usr/src/app/images ./images
COPY --from=builder /usr/src/app/translations ./translations
COPY --from=builder /usr/src/app/libraries ./libraries
RUN sed -i "/electron/d" package.json && \
npm ci --omit=dev && \
npm cache clean --force && \
rm -rf /tmp/node-compile-cache

# Configure container
EXPOSE 8080
Expand Down
57 changes: 20 additions & 37 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
# Build stage
FROM node:22.14.0-alpine AS builder

# Configure build dependencies
RUN apk add --no-cache --virtual .build-dependencies \
autoconf \
automake \
g++ \
gcc \
libtool \
make \
nasm \
libpng-dev \
python3

WORKDIR /usr/src/app
WORKDIR /usr/src/app/build

# Copy only necessary files for build
COPY . .
COPY server-package.json package.json

# Build and cleanup in a single layer
RUN cp -R build/src/* src/. && \
cp build/docker_healthcheck.js . && \
rm docker_healthcheck.ts && \
npm install && \
npm run build:webpack && \
npm prune --omit=dev && \
RUN npm ci && \
npm run build:prepare-dist && \
npm cache clean --force && \
cp -r src/public/app/doc_notes src/public/app-dist/. && \
rm -rf src/public/app && \
mkdir -p src/public/app/services && \
cp -r build/src/public/app/services/mime_type_definitions.js src/public/app/services/mime_type_definitions.js && \
rm src/services/asset_path.ts && \
rm -r build
rm -rf dist/node_modules && \
mv dist/* \
start-docker.sh \
/usr/src/app/ && \
rm -rf \
/usr/src/app/build \
/tmp/node-compile-cache

#TODO: improve node_modules handling in copy-dist/Dockerfile -> remove duplicated work
# currently copy-dist will copy certain node_module folders, but in the Dockerfile we delete them again (to keep image size down),
# as we install necessary dependencies in runtime buildstage anyways

# Runtime stage
FROM node:22.14.0-alpine
Expand All @@ -42,17 +30,12 @@ RUN apk add --no-cache su-exec shadow

WORKDIR /usr/src/app

# Copy only necessary files from builder
COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/src ./src
COPY --from=builder /usr/src/app/db ./db
COPY --from=builder /usr/src/app/docker_healthcheck.js .
COPY --from=builder /usr/src/app/start-docker.sh .
COPY --from=builder /usr/src/app/package.json .
COPY --from=builder /usr/src/app/config-sample.ini .
COPY --from=builder /usr/src/app/images ./images
COPY --from=builder /usr/src/app/translations ./translations
COPY --from=builder /usr/src/app/libraries ./libraries
COPY --from=builder /usr/src/app ./

RUN sed -i "/electron/d" package.json && \
npm ci --omit=dev && \
npm cache clean --force && \
rm -rf /tmp/node-compile-cache

# Add application user
RUN adduser -s /bin/false node; exit 0
Expand Down
5 changes: 0 additions & 5 deletions bin/build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ set -e # Fail on any command error
VERSION=`jq -r ".version" package.json`
SERIES=${VERSION:0:4}-latest

cat package.json | grep -v electron > server-package.json

echo "Compiling typescript..."
npx tsc

sudo docker build -t triliumnext/notes:$VERSION --network host -t triliumnext/notes:$SERIES .

if [[ $VERSION != *"beta"* ]]; then
Expand Down
Loading
Loading