From 6acd842c622c0f432575da66b00f4fa4b647d35c Mon Sep 17 00:00:00 2001 From: AdminRAT <24538037+AdminRAT@users.noreply.github.com> Date: Fri, 18 Nov 2022 13:04:31 -0800 Subject: [PATCH 1/2] refactor(docker): Rewrite Dockerfile - Image comes in at around 203 MB now --- Dockerfile | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 57cccb6..a842521 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,20 @@ -FROM node:16 +# Use the alpine image of node 16 +FROM node:16-alpine -WORKDIR /usr/src/app -COPY package*.json ./ +# Create a dir for the app and make it owned by a non-root user (node) +RUN mkdir /tickets && \ + chown -R 1000:1000 /tickets +WORKDIR /tickets -RUN npm i --production +# Change user to node +USER node -COPY . . -CMD ["npm", "start"] \ No newline at end of file +# Install packages +COPY --chown=1000:1000 package.json pnpm-lock.yaml ./ +RUN npx pnpm install --prod --frozen-lockfile + +# Copy src folder +COPY src ./src + +# Set the command +CMD ["node", "src/"] From 00194a93666463b6e38ed8ddf197dd126c1b03ed Mon Sep 17 00:00:00 2001 From: AdminRAT <24538037+AdminRAT@users.noreply.github.com> Date: Fri, 18 Nov 2022 13:55:41 -0800 Subject: [PATCH 2/2] feat(docker): Add compose config --- compose.Dockerfile | 20 ++++++++++++++++++++ docker-compose.yml | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 compose.Dockerfile create mode 100644 docker-compose.yml diff --git a/compose.Dockerfile b/compose.Dockerfile new file mode 100644 index 0000000..2003f24 --- /dev/null +++ b/compose.Dockerfile @@ -0,0 +1,20 @@ +# Use the alpine image of node 16 +FROM node:16-alpine + +# Create a dir for the app and make it owned by a non-root user (node) +RUN mkdir /tickets && \ + chown -R 1000:1000 /tickets +WORKDIR /tickets + +# Change user to node +USER node + +# Install packages +COPY --chown=1000:1000 package.json pnpm-lock.yaml ./ +RUN npx pnpm install --prod --frozen-lockfile --no-optional && \ + # Currently WIP since pnpm installs dev deps automatically when I don't want it to. + # Quick fix is to add to main deps + npx pnpm install mysql2 + +# Set the command +CMD ["node", "src/"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..cb40e1d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: "3.8" + +services: + bot: + build: + context: . + dockerfile: compose.Dockerfile + restart: unless-stopped + volumes: + - ./src:/tickets/src + - ./user:/tickets/user + - ./logs:/tickets/logs + - ./.env:/tickets/.env:ro + environment: + - DB_TYPE=mysql + - DB_HOST=db + - DB_PORT=3306 + - DB_NAME=tickets + - DB_USER=tickets + - DB_PASS=tickets + - DB_TABLE_PREFIX=dsctickets_ + depends_on: + - db + + db: + image: mariadb:10.6 + restart: unless-stopped + environment: + - "MYSQL_DATABASE=tickets" + - "MYSQL_USER=tickets" + - "MYSQL_PASSWORD=tickets" + + - "MYSQL_RANDOM_ROOT_PASSWORD=yes" + volumes: + - db:/var/lib/mysql + +volumes: + db: