From 34cf775e735ae26a90c67db4516137893c3c9162 Mon Sep 17 00:00:00 2001 From: LocalNewsTV Date: Tue, 26 Sep 2023 16:48:16 -0700 Subject: [PATCH 1/2] Added Dockerfiles for DB/API --- api/Dockerfile | 28 ++++++++++++++++++++ docker-compose.yaml | 52 +++++++++++++++++++++++++++++++++++++ mongoSeed/init/create-db.js | 23 ++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 api/Dockerfile create mode 100644 docker-compose.yaml create mode 100644 mongoSeed/init/create-db.js diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 000000000..62c3267d0 --- /dev/null +++ b/api/Dockerfile @@ -0,0 +1,28 @@ +FROM node:18.15.0-alpine AS base + +# Directory used in container +WORKDIR /usr/api/ + +# Copy everything +COPY . . + +################## +### PROD IMAGE ### +################## +FROM node:18.15.0-alpine as prod +ENV NODE_ENV=production + +# Add curl for health check +RUN apk --update --no-cache add curl + +# Directory used in container +WORKDIR /usr/api/ + +# Install packages. Needed even for compiled build. +COPY package.json . +RUN yarn + +# Copy compiled build from base +COPY --from=base /usr/api . + +CMD [ "node", "app.js" ] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 000000000..01c631cbf --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,52 @@ +version: "3.7" +services: + ############################################################################################# + ### Mongo ### + ############################################################################################# + mongo: + image: mongo:3.6 + container_name: nrpti-mongo + tty: true + restart: always + volumes: + - ./mongoSeed/init:/docker-entrypoint-initdb.d + ports: + - 27017:27017 + networks: + - nrpti + healthcheck: + test: echo 'db.runCommand({serverStatus:1}).ok' | mongo admin -u nrpti-admin -p nrpti-admin --quiet | grep 1 + interval: 20s + timeout: 30s + retries: 5 + start_period: 120s + ############################################################################################# + ### API ### + ############################################################################################# + api: + container_name: nrpti-api + build: + context: ./api + dockerfile: Dockerfile + networks: + - nrpti + environment: + - MONGODB_SERVICE_HOST=mongo + ports: + - 3000:3000 + # healthcheck: + # test: curl localhost:${PORT:-3000}/api/health | grep 'API is healthy and ready' + # interval: 20s + # timeout: 30s + # retries: 5 + # start_period: 20s + depends_on: + mongo: + condition: service_healthy + +############################################################################################# +### Network ### +############################################################################################# +networks: + nrpti: + driver: "bridge" diff --git a/mongoSeed/init/create-db.js b/mongoSeed/init/create-db.js new file mode 100644 index 000000000..7791ab249 --- /dev/null +++ b/mongoSeed/init/create-db.js @@ -0,0 +1,23 @@ +/** + * @desc Seed data for initialization of NRPTI Development Database + * @author LocalNewsTV + */ + +const db = new Mongo().getDB('nrpti-dev'); + +db.createUser({ + user: "nrpti-admin", + pwd: "nrpti-admin", + roles: [{ + role: 'readWrite', + db: 'nrpti-dev', + }], +}); + +db.createCollection("audit", {capped: false}); +db.createCollection("description_summary_subset", {capped: false}); +db.createCollection("location_subset", {capped: false}); +db.createCollection("migrations", {capped: false}); +db.createCollection("nrpti", {capped: false}); +db.createCollection("record_name_subset", {capped: false}); +db.createCollection("redacted_record_subset", {capped: false}); From ceb06da4079854fa0f61f6e48d621285456bd328 Mon Sep 17 00:00:00 2001 From: LocalNewsTV Date: Tue, 3 Oct 2023 08:14:09 -0700 Subject: [PATCH 2/2] Updated docker-compose environment --- docker-compose.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 01c631cbf..bef05cb5a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -8,6 +8,10 @@ services: container_name: nrpti-mongo tty: true restart: always + environment: + - MONGO_INITDB_ROOT_USERNAME=${MONGO_USERNAME:-nrpti-admin} + - MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASSWORD:-nrpti-admin} + - MONGO_DATABASE_NAME=${MONGO_DATABASE:-nrpti-dev} volumes: - ./mongoSeed/init:/docker-entrypoint-initdb.d ports: @@ -15,7 +19,7 @@ services: networks: - nrpti healthcheck: - test: echo 'db.runCommand({serverStatus:1}).ok' | mongo admin -u nrpti-admin -p nrpti-admin --quiet | grep 1 + test: echo 'db.runCommand({serverStatus:1}).ok' | mongo admin -u ${MONGO_USERNAME:-nrpti-admin} -p ${MONGO_PASSWORD:-nrpti-admin} --quiet | grep 1 interval: 20s timeout: 30s retries: 5