From 0e5f158f116dfb5fc19dc4a6175fd0737e0c4633 Mon Sep 17 00:00:00 2001 From: liushuyu Date: Wed, 14 Sep 2022 03:04:27 -0600 Subject: [PATCH] docker: update dockerfile to use rollup --- Dockerfile | 9 +++------ bundle.sh | 13 +++++++++++++ package.json | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100755 bundle.sh diff --git a/Dockerfile b/Dockerfile index 8b626e1..e3973fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,9 +4,9 @@ FROM node:16-alpine AS build WORKDIR /usr/src/app # Install app dependencies and add source files -COPY package.json yarn.lock tsconfig.json ./ -COPY src/ ./src -RUN yarn install --frozen-lockfile && yarn build && rm -f dist/*.map +COPY package.json env.json yarn.lock tsconfig.json bundle.sh *.js ./ +COPY ./src ./src +RUN yarn install --frozen-lockfile && sh -e ./bundle.sh # Second stage FROM node:16-alpine @@ -15,9 +15,6 @@ WORKDIR /usr/src/app # Copy artifacts COPY --from=build /usr/src/app/dist/ ./ -COPY --from=build /usr/src/app/node_modules ./node_modules -COPY env.json src/responses.json ./ -COPY src/responses ./responses/ RUN addgroup -S app -g 50000 && \ adduser -S -g app -u 50000 app && \ diff --git a/bundle.sh b/bundle.sh new file mode 100755 index 0000000..82df217 --- /dev/null +++ b/bundle.sh @@ -0,0 +1,13 @@ +#!/bin/bash -e + +yarn + +[ -d "dist" ] && rm -rf dist + +yarn run build + +echo "[+] Installing non-bundle-able packages ..." +DISCORD_JS="$(grep discord.js package.json | sed 's|,||')" +cd "dist" +echo "{\"name\": \"citra-discord-bot\",\"license\": \"GPL-2.0+\",\"dependencies\": {${DISCORD_JS}}}" > package.json +yarn install diff --git a/package.json b/package.json index 9916dd8..40d5d92 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "postinstall": "node generateExports.js", "build": "yarn run rollup -c", "check": "yarn run tsc --noEmit", + "bundle": "./bundle.sh", "serve": "yarn run ts-node ./src/server.ts" } }