Merge pull request #360 from AdminRAT/docker-improvements

feat(docker): Docker improvements
This commit is contained in:
Isaac 2023-01-06 16:17:40 +00:00 committed by GitHub
commit ca2556b24f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 6 deletions

View File

@ -1,9 +1,20 @@
FROM node:16 # Use the alpine image of node 16
FROM node:16-alpine
WORKDIR /usr/src/app # Create a dir for the app and make it owned by a non-root user (node)
COPY package*.json ./ RUN mkdir /tickets && \
chown -R 1000:1000 /tickets
WORKDIR /tickets
RUN npm i --production # Change user to node
USER node
COPY . . # Install packages
CMD ["npm", "start"] 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/"]

20
compose.Dockerfile Normal file
View File

@ -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/"]

38
docker-compose.yml Normal file
View File

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