docker: update dockerfile to use rollup

This commit is contained in:
liushuyu 2022-09-14 03:04:27 -06:00
parent 749bbdeb9d
commit 0e5f158f11
No known key found for this signature in database
GPG key ID: 23D1CE4534419437
3 changed files with 17 additions and 6 deletions

View file

@ -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 && \

13
bundle.sh Executable file
View file

@ -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

View file

@ -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"
}
}