diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..edd1802 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.env +.git +.gitignore +node_modules \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a1b1bb3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +# 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 +# If you are building your code for production +# RUN npm ci --only=production + +# Bundle app source +COPY . . + +# Expose port 3000 outside container +EXPOSE 4200 +# 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..38713cc --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: '3.7' + +services: + # REST API running on Node JS container + app: + container_name: lafs-api + restart: always + build: . + ports: + - '3000:3000' + # Environment variables for database host and name + environment: + - DB_HOST=mongo + - DB_NAME=lafs-db + + # MongoDB 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 \ No newline at end of file diff --git a/server/datasources.development.js b/server/datasources.development.js index 05c14ba..5b7e15d 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, - url: process.env.DB_URL - } -}; + mongodb: { + connector: 'mongodb', + 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 + } + }; \ No newline at end of file