Skip to content

Commit 218a45d

Browse files
committed
chore: improve docker + compose
The following docker fixes are in place: - transitions to using npm in docker. - removes extraneous comments and environmental variables in dockerfile. The following compose fixes are in place: - adds a networking layer - uses the correct mysql 8.4 auth plugin call - removes the extraneous UTF8 variables - removes the deprecated version tag
1 parent 20bc19c commit 218a45d

File tree

3 files changed

+39
-30
lines changed

3 files changed

+39
-30
lines changed

.dockerignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
node_modules
33
.git
44

5-
# ignore loggin utilities
5+
# ignore logging utilities
66
npm-debug.log
77
yarn-error.log
88

99
# ignore documentation
1010
*.md
11+
CNAME
1112

1213
# ignore unnecessary folders
1314
docs
1415
temp
15-
test
16+
test*
17+
results
1618
sh
1719
bin
20+

Dockerfile

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
1-
# define base image
2-
FROM node:lts-slim
1+
FROM node:lts
32

4-
# download all the missing dependencies for chromium, plus chromium itself
3+
# Install missing dependencies for chromium
4+
# These are all needed to make sure the browser can properly render all
5+
# the requiredd page
56
RUN apt-get update && apt-get install -y \
67
ca-certificates fonts-liberation gconf-service \
78
libappindicator1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 \
89
libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libgconf-2-4 \
910
libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 \
1011
libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \
1112
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 \
12-
libxss1 libxtst6 lsb-release libxshmfence1 chromium -y
13+
libxss1 libxtst6 lsb-release libxshmfence1 chromium -y \
14+
&& rm -rf /var/lib/apt/lists/*
1315

14-
# ENV NODE_ENV=production
15-
ENV YARN_VERSION 1.22.17
16-
#ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD 1
17-
RUN yarn policies set-version $YARN_VERSION
18-
#ENV CHROME_BIN /usr/bin/chromium
19-
#ENV PUPPETEER_EXECUTABLE_PATH /usr/bin/chromium
20-
21-
# define working directory inside the container
16+
# Set working directory
2217
WORKDIR /usr/src/app
2318

24-
# Copy all the source code from host machine to the container project directory
19+
# Copy source code
2520
COPY . .
2621

27-
# install all the dependencies
28-
RUN yarn --frozen-lockfile && yarn build
22+
# Install dependencies
23+
RUN npm install && \
24+
NODE_ENV=production npm run build && \
25+
npm install --omit=dev
2926

30-
# yarn build creates the bin/ folder
27+
# Copy environment file to bin folder
3128
COPY .env bin/
3229

33-
# change directory to the bin diretory
30+
# Change directory to bin
3431
WORKDIR /usr/src/app/bin/
3532

36-
# make sure the node user is the owner of all the underlying files.
33+
# Set ownership
3734
RUN chown -R node:node *
3835

39-
# ensure this container runs as the user "node"
36+
# Switch to non-root user
4037
USER node
4138

42-
# define the start up command of the container to run the server
43-
CMD ["node", "server/app.js"]
39+
# Define startup command
40+
CMD ["NODE_ENV=production", "node", "server/app.js"]
41+

docker-compose.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3'
2-
31
services:
42
bhima:
53
build: .
@@ -13,14 +11,15 @@ services:
1311
depends_on:
1412
- mysql
1513
- redis
14+
networks:
15+
- backend
16+
1617
mysql:
1718
image: mysql:8
18-
restart: always
19+
restart: unless-stopped
1920
command:
20-
- --default-authentication-plugin=mysql_native_password
21+
- --mysql-native-password=ON
2122
- --sql-mode=STRICT_ALL_TABLES,NO_UNSIGNED_SUBTRACTION
22-
- --character-set-server=utf8mb4
23-
- --collation-server=utf8mb4_unicode_ci
2423
volumes:
2524
- mysqldata:/var/lib/mysql/
2625
- "./temp/docker-build.sql:/docker-entrypoint-initdb.d/bhima.sql"
@@ -29,9 +28,18 @@ services:
2928
- MYSQL_USER=$DB_USER
3029
- MYSQL_PASSWORD=$DB_PASS
3130
- MYSQL_DATABASE=$DB_NAME
31+
networks:
32+
- backend
33+
3234
redis:
3335
image: redis:latest
34-
restart: always
36+
restart: unless-stopped
37+
networks:
38+
- backend
39+
40+
networks:
41+
backend:
3542

3643
volumes:
3744
mysqldata:
45+

0 commit comments

Comments
 (0)