Skip to content

Commit 70c5687

Browse files
committed
update docker
1 parent 370bf62 commit 70c5687

File tree

5 files changed

+54
-19
lines changed

5 files changed

+54
-19
lines changed

.env.example

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@ TOKEN_ISSUER=api.dev.xyz.com
5454
TOKEN_AUDIENCE=xyz.com
5555

5656
# Caching
57-
CONTENT_CACHE_DURATION_MILLIS=600000
57+
CONTENT_CACHE_DURATION_MILLIS=600000
58+
59+
# Docker build
60+
COMPOSE_BAKE=true

.env.test.example

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,7 @@ TOKEN_ISSUER=api.dev.xyz.com
5252
TOKEN_AUDIENCE=xyz.com
5353

5454
# Caching
55-
CONTENT_CACHE_DURATION_MILLIS=5000
55+
CONTENT_CACHE_DURATION_MILLIS=5000
56+
57+
# Docker build
58+
COMPOSE_BAKE=true

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Here we are getting our node as Base image
2-
FROM node:20.10.0
2+
FROM node:20.11.0
33

44
# create user in the docker image
55
USER node

Dockerfile.test

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Here we are getting our node as Base image
2+
FROM node:20.11.0
3+
4+
# create user in the docker image
5+
USER node
6+
7+
# Creating a new directory for app files and setting path in the container
8+
RUN mkdir -p /home/node/app && chown -R node:node /home/node/app
9+
10+
# setting working directory in the container
11+
WORKDIR /home/node/app
12+
13+
# grant permission of node project directory to node user
14+
COPY --chown=node:node . .
15+
16+
# installing the dependencies into the container
17+
RUN npm install
18+
19+
# command to run within the container
20+
CMD [ "npm", "start" ]

docker-compose.yml

+25-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1-
version: '3.9'
2-
31
services:
2+
tester:
3+
# This defines the configuration options, including the context and dockerfile,
4+
# that will be applied when Compose builds the application image.
5+
build:
6+
# This defines the build context for the image build — in this case, the current project directory.
7+
context: .
8+
# This specifies the Dockerfile in your current project directory as the file
9+
dockerfile: Dockerfile.test
10+
image: blogs-tester:latest
11+
container_name: blogs-tester
12+
env_file: .env.test
13+
depends_on:
14+
- mongo
15+
- redis
416
app:
517
# This defines the configuration options, including the context and dockerfile,
618
# that will be applied when Compose builds the application image.
@@ -9,26 +21,23 @@ services:
921
context: .
1022
# This specifies the Dockerfile in your current project directory as the file
1123
dockerfile: Dockerfile
12-
image: app
13-
container_name: app
24+
image: blogs-app:latest
25+
container_name: blogs-app
1426
# This defines the restart policy. The default is no,
1527
# but we have set the container to restart unless it is stopped.
1628
restart: unless-stopped
1729
env_file: .env
1830
ports:
1931
# This maps port from .env on the host to same port number on the container.
20-
- '$PORT:$PORT'
21-
links:
22-
- mongo
23-
- redis
32+
- '${PORT}:${PORT}'
2433
depends_on:
2534
- mongo
2635
- redis
2736

2837
mongo:
2938
# To create this service, Compose will pull the mongo
3039
image: mongo:7.0.4
31-
container_name: mongo
40+
container_name: blogs-mongo
3241
restart: unless-stopped
3342
# This tells Compose that we would like to add environment variables
3443
# from a file called .env, located in our build context.
@@ -38,11 +47,11 @@ services:
3847
# a root user in the admin authentication database and ensure that authentication is enabled
3948
# when the container starts. We have set MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD
4049
# using the values from our .env file, which we pass to the db service using the env_file option.
41-
- MONGO_INITDB_ROOT_USERNAME=$DB_ADMIN
42-
- MONGO_INITDB_ROOT_PASSWORD=$DB_ADMIN_PWD
43-
- MONGO_INITDB_DATABASE=$DB_NAME
50+
- MONGO_INITDB_ROOT_USERNAME=${DB_ADMIN}
51+
- MONGO_INITDB_ROOT_PASSWORD=${DB_ADMIN_PWD}
52+
- MONGO_INITDB_DATABASE=${DB_NAME}
4453
ports:
45-
- '$DB_PORT:27017'
54+
- '${DB_PORT}:27017'
4655
volumes:
4756
- ./addons/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
4857
# The named volume dbdata will persist the data stored in Mongo’s default data directory, /data/db.
@@ -51,12 +60,12 @@ services:
5160

5261
redis:
5362
image: redis:7.2.3
54-
container_name: redis
63+
container_name: blogs-redis
5564
restart: unless-stopped
5665
env_file: .env
5766
ports:
58-
- '$REDIS_PORT:6379'
59-
command: redis-server --save 20 1 --loglevel warning --requirepass $REDIS_PASSWORD
67+
- '${REDIS_PORT}:6379'
68+
command: redis-server --save 20 1 --loglevel warning --requirepass ${REDIS_PASSWORD}
6069
volumes:
6170
- cache:/data/cache
6271

0 commit comments

Comments
 (0)