Skip to content

Commit

Permalink
Set up docker compose in production (#795)
Browse files Browse the repository at this point in the history
resolves: #792

Signed-off-by: Lan Xia <[email protected]>
  • Loading branch information
llxia authored May 4, 2023
1 parent aaa9210 commit 7d3f3a5
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 98 deletions.
3 changes: 0 additions & 3 deletions .docker.env

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ __pycache__/
GitHubData/
JenkinsData/
JenkinsDataWithFeedback/
mongo
TempData/
deployenv/
*.joblib
Expand Down
11 changes: 6 additions & 5 deletions TestResultSummaryService/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ let db;
: `${encodeURIComponent(config.user)}:${encodeURIComponent(
config.password
)}@`;
const hostname =
process.env.MONGO_CONTAINER_NAME !== undefined
? process.env.MONGO_CONTAINER_NAME
: 'localhost';
url = 'mongodb://' + credential + hostname + ':27017/exampleDb';
const { MONGO_CONTAINER_NAME = 'localhost' } = process.env;
url =
'mongodb://' +
credential +
MONGO_CONTAINER_NAME +
':27017/exampleDb';
}

const dbConnect = await MongoClient.connect(url, {
Expand Down
2 changes: 1 addition & 1 deletion TestResultSummaryService/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16
FROM node:18

WORKDIR /usr/src/app

Expand Down
6 changes: 4 additions & 2 deletions TestResultSummaryService/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ Plugins can be added. Please refer [Plugins ReadMe](./plugins/README.md) for imp
- step 3: run command `sudo chmod u+x exportMongo.sh` to grant cron access to shell scipt
## Docker
## Docker Compose
Go to top directory, run command `docker-compose --env-file .docker.env up --build`, TRSS will be up at http://localhost:3000
Go to top directory, run command `npm run docker` or run with the sample data `npm run docker-data`, TRSS will be up at http://localhost:4000
To shut it down, run command `npm run docker-down`.
Using Docker is a good way to test and development locally. For more details, please see a [recorded demonstration](https://youtu.be/9Adwk2qkL1A) of running TRSS locally in Docker.
Expand Down
2 changes: 1 addition & 1 deletion TestResultSummaryService/data/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mongo:4.0.9
FROM mongo:6.0.1

COPY sampleData.gz /sampleData.gz
CMD mongorestore --host=mongo --archive=/sampleData.gz --db exampleDb --gzip --stopOnError
37 changes: 0 additions & 37 deletions TestResultSummaryService/nginx.conf

This file was deleted.

5 changes: 5 additions & 0 deletions TestResultSummaryService/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM nginx

COPY nginx.conf /etc/nginx/nginx.conf

ENTRYPOINT nginx -g 'daemon off;'
22 changes: 22 additions & 0 deletions TestResultSummaryService/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
events {}
http {
# Silence the nginx logs
access_log off;

server {
listen 4000;

#resolver 10.89.0.1; # for podman only
resolver 127.0.0.11; # for docker only
set $server "server";
set $client "client";

location /api/ {
proxy_pass http://$server:3001;
}
location / {
proxy_pass http://$client:3000;
}

}
}
13 changes: 13 additions & 0 deletions TestResultSummaryService/nginx/nginx_prod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
events {}
http {
# Silence the nginx logs
access_log off;

server {
listen 80;

location / {
proxy_pass http://localhost:4000;
}
}
}
6 changes: 3 additions & 3 deletions TestResultSummaryService/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified! Configure in package.json\" && exit 1",
"startFrontend": "nodemon frontend.js --configFile=./trssConf.json",
"startBackend": "nodemon --max-old-space-size=4096 backend.js --configFile=./trssConf.json",
"start": "npm-run-all --parallel startFrontend startBackend",
"start-frontend": "nodemon frontend.js --configFile=./trssConf.json",
"start-backend": "nodemon --max-old-space-size=4096 backend.js --configFile=./trssConf.json",
"start": "npm-run-all --parallel start-frontend start-backend",
"prettier": "npx prettier --write ."
},
"repository": "",
Expand Down
64 changes: 22 additions & 42 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,35 @@ version: "3"

services:
mongo:
container_name: "${MONGO_CONTAINER_NAME}"
image: mongo:4.0.9
ports:
- "27017:27017"
networks:
- trss-app
profiles:
- prod
image: mongo:6.0.1
volumes:
- mongo-data:/data/db
- ./mongo/data:/data/db
mongo-seed:
profiles:
- data
build: TestResultSummaryService/data
depends_on:
- mongo
links:
- mongo
networks:
- trss-app
service:
server:
profiles:
- prod
build: TestResultSummaryService
container_name: "${SERVICE_CONTAINER_NAME}"
depends_on:
- mongo
ports:
- "3001:3001"
networks:
- trss-app
environment:
- MONGO_CONTAINER_NAME=${MONGO_CONTAINER_NAME}
volumes:
- ./TestResultSummaryService:/usr/src/app
environment:
MONGO_CONTAINER_NAME: mongo
client:
build: test-result-summary-client
container_name: "${CLIENT_CONTAINER_NAME}"
stdin_open: true
depends_on:
- service
build:
context: test-result-summary-client
args:
REACT_APP_CONNECT_ADOPTIUM_API: ${REACT_APP_CONNECT_ADOPTIUM_API}
ports:
- "3000:3000"
networks:
- trss-app
environment:
- SERVICE_CONTAINER_NAME=${SERVICE_CONTAINER_NAME}
# volumes:
# - ./test-result-summary-client:/usr/src/app

networks:
trss-app:
driver: bridge

volumes:
mongo-data:
driver: local

- 3000:3000
nginx:
profiles:
- prod
build: TestResultSummaryService/nginx
ports:
- 4000:4000
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "TRSS",
"version": "0.1.0",
"description": "TestResultSummaryService",
"main": "app.js",
"scripts": {
"docker": "docker compose --profile prod up --build",
"docker-data": "docker compose --profile prod --profile data up --build",
"docker-down": "docker compose down",
"docker-ui": "REACT_APP_CONNECT_ADOPTIUM_API=enable docker compose up --build"
},
"author": "",
"license": "Apache License Version 2.0",
"readmeFilename": "README.md"
}
2 changes: 2 additions & 0 deletions test-result-summary-client/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Dockerfile
build
node_modules
npm-debug.log
17 changes: 13 additions & 4 deletions test-result-summary-client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
FROM node:16
FROM node:18

WORKDIR /usr/src/app

COPY . .
# Install serve first as it has no dependencies.
RUN npm install -g serve

# Only copy the npm related dependencies as they change rarely.
COPY package.json package-lock.json .
RUN sed -i 's/localhost/service/g' package.json
RUN npm ci --legacy-peer-deps

RUN npm ci
# Copy the rest of the app and build it.
COPY . .
ARG REACT_APP_CONNECT_ADOPTIUM_API
ENV REACT_APP_CONNECT_ADOPTIUM_API=$REACT_APP_CONNECT_ADOPTIUM_API
RUN npm run build

WORKDIR /usr/src/app/build
EXPOSE 3000
CMD npm start
ENTRYPOINT ["serve", "--single"]

0 comments on commit 7d3f3a5

Please sign in to comment.