From 4fe3a4e9b180ccb9a4bf1b1eb7faf14a662093be Mon Sep 17 00:00:00 2001 From: Sebastian Pietschner Date: Tue, 8 Mar 2022 05:18:06 +0000 Subject: [PATCH] reduce the size of docker images --- Dockerfile | 22 ++++++++++------------ package.json | 3 ++- tsconfig.json | 4 ++-- tsup.config.js | 2 ++ yarn.lock | 17 +++++++++++------ 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 602e8ca..c4ecd74 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,8 @@ # Deps -FROM node:16-buster as base +FROM node:16-alpine as base WORKDIR /app -# RUN apt-get update && \ -# apt-get upgrade -y --no-install-recommends && \ -# apt-get install -y --no-install-recommends openssl && \ -# apt-get clean && \ -# rm -rf /var/lib/apt/lists/* +RUN apk update +RUN apk add python3 make gcc g++ COPY package.json . COPY prisma prisma COPY yarn.lock . @@ -15,10 +12,9 @@ COPY tsconfig.json . # Build FROM base as build WORKDIR /app - - COPY src ./src -RUN yarn install --frozen-lockfile +RUN yarn install +RUN yarn cache clean RUN yarn build:tsup # Runner @@ -30,7 +26,8 @@ ENV DATABASE_URL "file:/app/config/db.sqlite" ARG DRONE_TAG ENV VERSION=$DRONE_TAG COPY --from=build /app/dist dist -RUN yarn install --frozen-lockfile --production +RUN yarn install --production +RUN yarn cache clean # CMD yarn deploy && echo "Test" && yarn start CMD ls dist && yarn deploy && npx prisma migrate deploy && yarn start @@ -44,8 +41,9 @@ ARG DRONE_TAG ENV VERSION=$DRONE_TAG WORKDIR /app COPY --from=build /app/dist dist -RUN yarn install --frozen-lockfile --production -RUN useradd container -m -s /bin/bash +RUN yarn install --production +RUN yarn cache clean +RUN adduser -H -D container USER container COPY entrypoint.sh /entrypoint.sh diff --git a/package.json b/package.json index 5b28f0c..a85b240 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "@discordjs/builders": "^0.12.0", "@discordjs/rest": "^0.3.0", "@prisma/client": "^3.10.0", - "@swc/core": "^1.2.151", "apollo-server-core": "^3.6.3", "apollo-server-express": "^3.6.3", "bufferutil": "^4.0.6", @@ -57,6 +56,8 @@ "@types/node": "^17.0.5", "@types/romans": "^2.0.0", "@types/signale": "^1.4.2", + "@swc/core": "^1.2.151", + "node-prune": "^1.0.2", "nodemon": "^2.0.15", "prettier": "^2.5.1", "prettier-plugin-organize-imports": "^2.3.4", diff --git a/tsconfig.json b/tsconfig.json index 1159836..df13583 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,8 +7,8 @@ "resolveJsonModule": true, // Language and Environment - "emitDecoratorMetadata": true, - "experimentalDecorators": true, + // "emitDecoratorMetadata": true, + // "experimentalDecorators": true, "lib": ["esnext", "DOM"], "target": "esnext", "useDefineForClassFields": true, diff --git a/tsup.config.js b/tsup.config.js index 656eee8..24932d7 100644 --- a/tsup.config.js +++ b/tsup.config.js @@ -9,4 +9,6 @@ export default defineConfig((options) => ({ platform: "node", minify: !options.watch, tsconfig: "tsconfig.json", + bundle: true, + dts: true, })); diff --git a/yarn.lock b/yarn.lock index d43ea6c..1ef4703 100644 --- a/yarn.lock +++ b/yarn.lock @@ -205,9 +205,9 @@ integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA= "@sapphire/async-queue@^1.1.9": - version "1.2.0" - resolved "https://registry.yarnpkg.com/@sapphire/async-queue/-/async-queue-1.2.0.tgz#7a56afd318101d338433d7180ebd6af349243268" - integrity sha512-O5ND5Ljpef86X5oy8zXorQ754TMjWALcPSAgPBu4+76HLtDTrNoDyzU2uGE2G4A8Wv51u0MXHzGQ0WZ4GMtpIw== + version "1.3.0" + resolved "https://registry.yarnpkg.com/@sapphire/async-queue/-/async-queue-1.3.0.tgz#98b1b364a5fe820366a786827f2e987590de5964" + integrity sha512-z+CDw5X4UgIEpZL8KM+ThVx1i8V60HBg0l/oFewTNbQQeRDJHdVxHyJykv+SF1H+Rc8EkMS81VTWo95jVYgO/g== "@sapphire/snowflake@^3.0.1": version "3.2.0" @@ -1789,6 +1789,11 @@ node-gyp-build@^4.3.0: resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.3.0.tgz#9f256b03e5826150be39c764bf51e993946d71a3" integrity sha512-iWjXZvmboq0ja1pUGULQBexmxq8CV4xBhX7VDOTbL7ZR4FOowwY/VOtRxBN/yKxmdGoIp4j5ysNT4u3S2pDQ3Q== +node-prune@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/node-prune/-/node-prune-1.0.2.tgz#003b3edf886ab1f67e3915102d6c4835f3087181" + integrity sha512-WSDCF2F/ad+IZp7Gx9b5l8TT3ezP56pn0pCSm4nnkUT00rP1yuOHCapv+jKy/Q87ZqYcPtV4Z+2IifozGDpR0Q== + nodemon@^2.0.15: version "2.0.15" resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-2.0.15.tgz#504516ce3b43d9dc9a955ccd9ec57550a31a8d4e" @@ -2525,9 +2530,9 @@ xdg-basedir@^4.0.0: integrity sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q== xss@^1.0.8: - version "1.0.10" - resolved "https://registry.yarnpkg.com/xss/-/xss-1.0.10.tgz#5cd63a9b147a755a14cb0455c7db8866120eb4d2" - integrity sha512-qmoqrRksmzqSKvgqzN0055UFWY7OKx1/9JWeRswwEVX9fCG5jcYRxa/A2DHcmZX6VJvjzHRQ2STeeVcQkrmLSw== + version "1.0.11" + resolved "https://registry.yarnpkg.com/xss/-/xss-1.0.11.tgz#211cb82e95b5071d4c75d597283c021157ebe46a" + integrity sha512-EimjrjThZeK2MO7WKR9mN5ZC1CSqivSl55wvUK5EtU6acf0rzEE1pN+9ZDrFXJ82BRp3JL38pPE6S4o/rpp1zQ== dependencies: commander "^2.20.3" cssfilter "0.0.10"