From a6b9aace63b881c7d6e972e3006a1c7eaf5d2d55 Mon Sep 17 00:00:00 2001 From: Julian Waller Date: Thu, 26 Sep 2024 16:19:40 +0100 Subject: [PATCH] chore: fixup docker image building --- .dockerignore | 7 +++++++ Dockerfile | 36 ++++++++++++++++++++++++++---------- package.json | 1 + 3 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..dc90661 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +_media +.ffmpeg +.coverage +deploy +dist +node_modules +pouch__all_dbs__ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index a88234f..71c4c6c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,32 @@ -FROM node:18 +FROM node:18 AS builder WORKDIR /usr/src/app - ENV NODE_ENV production - ENV PATHS__FFMPEG ffmpeg - ENV PATHS__FFPROBE ffmpeg - COPY package.json package-lock.json ./ - RUN sed -i -e 's/^ "version": "[0-9.]\+",$//' package.json - RUN yarn install && \ - apt-get update && \ - apt-get install ffmpeg -y + COPY package.json yarn.lock .yarnrc.yml ./ + RUN sed -i -e 's/^ "version": "[0-9.]\+",$//' package.json + RUN corepack enable COPY ./src ./src + COPY tsconfig.build.json ./ + + RUN yarn install + RUN yarn build:ts + + RUN sed -i -e 's/^ "postinstall": "husky",$//' package.json + RUN yarn workspaces focus --production + +FROM node:18 + WORKDIR /usr/src/app + ENV NODE_ENV=production + ENV PATHS__FFMPEG=ffmpeg + ENV PATHS__FFPROBE=ffmpeg + + RUN apt-get update && \ + apt-get install ffmpeg -y && \ + rm -rf /var/lib/apt/lists/* - CMD [ "node", "src" ] + COPY --from=builder /usr/src/app/package.json ./ + COPY --from=builder /usr/src/app/dist ./dist + COPY --from=builder /usr/src/app/node_modules ./node_modules + + CMD [ "node", "dist" ] HEALTHCHECK CMD curl -f http://localhost:8000/healthcheck || exit 1 diff --git a/package.json b/package.json index a80615f..c4afe68 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "build-linux-arm64": "run build linux arm64", "build-linux-x64": "run build linux x64", "build-win32-x64": "run build win32 x64", + "build:docker": "docker build .", "lint:raw": "run eslint --ext .ts --ext .js --ext .tsx --ext .jsx --ext .mts --ext .mjs --ignore-pattern dist", "lint": "yarn lint:raw .", "lint-fix": "yarn lint --fix",