From aa956347d2da70000ebc9ba61199162c5b0990d3 Mon Sep 17 00:00:00 2001 From: williben-snhu Date: Mon, 23 May 2022 11:42:19 -0500 Subject: [PATCH] Adding everything from Module 2 --- .dockerignore | 5 +++++ Dockerfile | 24 ++++++++++++++++++++++++ docker-compose.yml | 29 +++++++++++++++++++++++++++++ server/datasources.development.js | 10 +++++----- 4 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..952ff10 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.env +.git +.gitignore +node_modules +npm-debug.log \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..02cbedf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +#using Node v10 +FROM node:10 + +#Create app directory +WORKDIR /usr/src/lafs + +#Install app dependencies +#A wildcard is used to ensure both package.json AND package-lock.json are copied +#where available (npm@5+) +COPY package*.json ./ + +#RUN npm install -g @angular/cli@v6-lts + +RUN npm install +#If you are building your code for production +#RUN npm ci --only=production + +#Bundle app source +COPY . . + +#Expose port 3000 outside container +EXPOSE 3000 +#Command used to start application +CMD ["node","server/server.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b4d8fea --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,29 @@ +version: '3.7' +services: +# REST API running on Node JS container + app: + container_name: lafs-api + restart: always + build: . + ports: + - '3000:3000' + depends_on: [mongo] + # link this container to the Mongo DB container + links: + - mongo + # pass in environment variables for database host and name + environment: + - DB_HOST=mongo + - DB_NAME=lafs-db +# Mongo DB storage container + mongo: + container_name: lafs-db + image: 'mongo:4' + ports: + - '27017:27017' +# Attach the external network to these containers +networks: + default: + external: + name: lafs-net + diff --git a/server/datasources.development.js b/server/datasources.development.js index 05c14ba..f3266e4 100644 --- a/server/datasources.development.js +++ b/server/datasources.development.js @@ -1,11 +1,11 @@ module.exports = { mongodb: { connector: 'mongodb', - hostname: process.env.DB_HOST, - port: process.env.DB_PORT, - user: process.env.DB_USER, - password: process.env.DB_PASSWORD, - database: process.env.DB_NAME, + hostname: process.env.DB_HOST || 'localhost', + port: process.env.DB_PORT || 27017, + user: process.env.DB_USER|| '', + password: process.env.DB_PASSWORD || '', + database: process.env.DB_NAME || 'lafs', url: process.env.DB_URL } };