From e6bce8b331c440f39575dab7d2cab3428ada96a6 Mon Sep 17 00:00:00 2001 From: Isaac Date: Tue, 14 Feb 2023 23:21:36 +0000 Subject: [PATCH] feat(docker): add new Dockerfile Co-authored-by: Uzurka <101745008+Uzurka@users.noreply.github.com> --- .dockerignore | 20 +++++++++++++++++++- Dockerfile | 32 ++++++++++++++++++++++++++++++++ scripts/preinstall.js | 5 +++++ scripts/start.sh | 10 ++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 scripts/start.sh diff --git a/.dockerignore b/.dockerignore index b512c09..cbeb323 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,19 @@ -node_modules \ No newline at end of file +# only db, scripts, src, and user directories are needed +.github +.husky +.vscode +logs +node_modules +# prisma will generated by postinstall script +prisma +.all-contributorsrc +.commitlintrc.js +.dockerignore +.env +.eslintrc.json +.gitattributes +.gitignore +CONTRIBUTORS.md +Dockerfile +jsconfig.json +README.md \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6e676e8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# syntax=docker/dockerfile:1 + +FROM node:18-alpine + +ENV NODE_ENV=production \ + HTTP_HOST=0.0.0.0 \ + HTTP_PORT=80 \ + SETTINGS_HOST=127.0.0.1 \ + SETTINGS_PORT=8169 + +WORKDIR /usr/bot + +COPY package.json pnpm-lock.yaml ./ + +COPY --link scripts scripts + + # install python etc so node-gyp works for the optional dependencies +RUN apk add --no-cache --virtual .build-deps make gcc g++ python3 \ + # install pnpm to make dependency installation faster (because it has a lockfile) + && npm install -g pnpm \ + # install dependencies, CI=true to skip pre/postinstall scripts + && CI=true pnpm install --prod --frozen-lockfile \ + # pnpm isn't needed now + && npm uninstall pnpm --global \ + # remove node-gyp stuff + && apk del .build-deps + +COPY --link . . + +EXPOSE ${HTTP_PORT} + +ENTRYPOINT [ "/bin/sh", "/usr/bot/scripts/start.sh" ] \ No newline at end of file diff --git a/scripts/preinstall.js b/scripts/preinstall.js index 2e51c02..cdc23a7 100644 --- a/scripts/preinstall.js +++ b/scripts/preinstall.js @@ -7,6 +7,11 @@ function log (...strings) { console.log(short('&9[preinstall]&r'), ...strings); } +if (process.env.CI) { + log('CI detected, skipping'); + process.exit(0); +} + const env = { DB_CONNECTION_URL: '', DB_PROVIDER: '', // don't default to sqlite, postinstall checks if empty diff --git a/scripts/start.sh b/scripts/start.sh new file mode 100644 index 0000000..89fede7 --- /dev/null +++ b/scripts/start.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +echo "Checking environment..." +node scripts/preinstall + +echo "Preparing the database..." +node scripts/postinstall + +echo "Starting..." +node src/ \ No newline at end of file