Skip to content

Commit

Permalink
[NRPTI-1115] DEV FEATURE** Create Dockerfiles and docker-compose (#1118)
Browse files Browse the repository at this point in the history
* Added Dockerfiles for API and Database

* changed 'as' to 'AS'
  • Loading branch information
LocalNewsTV authored Oct 4, 2023
1 parent 9bd2658 commit dc38bbf
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
28 changes: 28 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
52 changes: 52 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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 ${MONGO_USERNAME:-nrpti-admin} -p ${MONGO_PASSWORD:-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"
23 changes: 23 additions & 0 deletions mongoSeed/init/create-db.js
Original file line number Diff line number Diff line change
@@ -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});

0 comments on commit dc38bbf

Please sign in to comment.