From ea5cb3acb8dc9954df937167d7914de39f013e52 Mon Sep 17 00:00:00 2001 From: Alan Grainger Date: Fri, 1 Nov 2024 08:55:54 +0100 Subject: [PATCH] Remove dev-dependencies from the final build --- Dockerfile | 7 +++++-- package.json | 12 ++++++++---- src/index.ts | 4 ++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index baa5613..cd4f839 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,11 +2,14 @@ FROM node:lts-slim WORKDIR /app -COPY package*.json ./ +COPY package.json ./ + RUN npm install --omit=dev COPY . . -RUN npm run build +# Build without type checking, as we have removed the Typescript +# dev-dependencies above to save space in the final build +RUN npx tsc --noCheck CMD [ "node", "dist/index.js" ] diff --git a/package.json b/package.json index e1996df..81e04cc 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "ts-node src/index.ts", "build": "npx tsc", + "test": "podman build -t immich-proxy-test . && podman run --init -it -p=3000:3000 immich-proxy-test", "start": "node dist/index.js" }, "author": "", @@ -15,13 +16,16 @@ "dotenv": "^16.4.5", "dayjs": "^1.11.13", "ejs": "^3.1.10", - "@types/express": "^4.17.21", + "typescript": "^5.6.2", + "tslib": "^2.8.1" + }, + "devDependencies": { + "ts-node": "^10.9.2", "@types/node": "^16.18.111", + "@types/express": "^4.17.21", "@typescript-eslint/eslint-plugin": "5.29.0", "@typescript-eslint/parser": "5.29.0", "eslint": "^8.49.0", - "eslint-config-standard": "^17.1.0", - "ts-node": "^10.9.2", - "typescript": "^5.6.2" + "eslint-config-standard": "^17.1.0" } } diff --git a/src/index.ts b/src/index.ts index 7658590..b82d10e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -91,6 +91,10 @@ const getSize = (req: Request) => { */ export const log = (message: string) => console.log(dayjs().format() + ' ' + message) +// Handle process termination requests (e.g. Ctrl+C) +process.on('SIGTERM', () => { process.exit(0) }) +process.on('SIGINT', () => { process.exit(0) }) + app.listen(3000, () => { console.log(dayjs().format() + ' Server started') })