From 3820521d62fdb0aa466a95bba0189e66f448fe86 Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Wed, 6 Jul 2016 16:22:32 -0700 Subject: [PATCH] Dockerfile successfully building ping endpoint --- .dockerignore | 6 +++++ Dockerfile | 21 +++++++++++++----- packages/nylas-api/app.js | 46 +++++++++++++++++++++++---------------- 3 files changed, 49 insertions(+), 24 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..d80f4ce50 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git +.gitignore +README.md +Procfile* +*node_modules* +docs diff --git a/Dockerfile b/Dockerfile index be4deaf43..fa5e964b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,20 @@ +# Use the latest Node 6 base docker image # https://github.com/nodejs/docker-node FROM node:6 -RUN mkdir -p /usr/src/app -WORKDIR /usr/src/app -COPY package.json /usr/src/app/ + +# Copy everything (excluding what's in .dockerignore) into an empty dir +COPY . /home +WORKDIR /home + RUN npm install -COPY . /usr/src/app -EXPOSE 8080 + +# This will do an `npm install` for each of our modules and then link them +# all together. See more about Lerna here: https://github.com/lerna/lerna +RUN node_modules/.bin/lerna bootstrap + +# External services run on port 5100. Expose it. +EXPOSE 5100 + +# We use a start-aws command that automatically spawns the correct process +# based on environment variables (which changes instance to instance) CMD [ "npm", "run", "start-aws"] diff --git a/packages/nylas-api/app.js b/packages/nylas-api/app.js index 8bcb3359f..68ebaa377 100644 --- a/packages/nylas-api/app.js +++ b/packages/nylas-api/app.js @@ -31,30 +31,38 @@ const plugins = [Inert, Vision, HapiBasicAuth, HapiBoom, { }]; let sharedDb = null; -const {DatabaseConnector, SchedulerUtils} = require(`nylas-core`) -DatabaseConnector.forShared().then((db) => { - sharedDb = db; -}); const validate = (request, username, password, callback) => { - const {AccountToken} = sharedDb; + const {DatabaseConnector, SchedulerUtils} = require(`nylas-core`); - AccountToken.find({ - where: { - value: username, - }, - }).then((token) => { - if (!token) { - callback(null, false, {}); - return - } - token.getAccount().then((account) => { - if (!account) { + let getSharedDb = null; + if (sharedDb) { + getSharedDb = Promise.resolve(sharedDb) + } else { + getSharedDb = DatabaseConnector.forShared() + } + + getSharedDb.then((db) => { + sharedDb = db; + const {AccountToken} = db; + + AccountToken.find({ + where: { + value: username, + }, + }).then((token) => { + if (!token) { callback(null, false, {}); - return; + return } - SchedulerUtils.markAccountIsActive(account.id) - callback(null, true, account); + token.getAccount().then((account) => { + if (!account) { + callback(null, false, {}); + return; + } + SchedulerUtils.markAccountIsActive(account.id) + callback(null, true, account); + }); }); }); };