diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 000000000..00f56869a --- /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..ce6ae41ef --- /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 ${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" 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});