-
Notifications
You must be signed in to change notification settings - Fork 24
Dockerize Webapp #335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dockerize Webapp #335
Changes from all commits
4c7a2d9
bc3ded1
333e213
dca316b
86f79c3
2228ac7
16cc5d8
ff98f6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,15 @@ | ||
| FROM node:10 | ||
| FROM node:10-slim | ||
|
|
||
| # Create app directory | ||
| WORKDIR /usr/src/app | ||
|
|
||
| # 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 ./ | ||
| # From: https://stackoverflow.com/a/52092711 | ||
| # Create and define the node_modules's cache directory. | ||
| RUN mkdir /usr/src/cache | ||
| WORKDIR /usr/src/cache | ||
|
|
||
| # Install the application's dependencies into the node_modules's cache directory. | ||
| COPY package.json ./ | ||
| COPY package-lock.json ./ | ||
| RUN npm install | ||
| # If you are building your code for production | ||
| # RUN npm ci --only=production | ||
|
|
||
| # Bundle app source | ||
| COPY . . | ||
|
|
||
| EXPOSE 8080 | ||
| CMD [ "npm", "start" ] | ||
| # Create and define the application's working directory. | ||
| RUN mkdir /usr/src/app | ||
| WORKDIR /usr/src/app |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| let config = { | ||
| protocol: 'http', | ||
| hostname: `localhost:8080`, | ||
| mongoUri: 'mongodb://mongo:27017/hellogov', | ||
| mongoOptions: {} | ||
| }; | ||
|
|
||
| module.exports = config; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| let config = { | ||
| protocol: 'http', | ||
| hostname: `localhost:8080` | ||
| hostname: 'localhost:8080', | ||
| mongoUri: 'mongodb://localhost:27017/hellogov', | ||
| mongoOptions: {} | ||
| }; | ||
|
|
||
| module.exports = config; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Copy container-built node_modules. | ||
| # From: https://stackoverflow.com/a/52092711 | ||
|
|
||
| cp -r /usr/src/cache/node_modules/. /usr/src/app/node_modules/ | ||
| # exec npm run build | ||
| exec npm run start-docker | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,33 +23,18 @@ var routes = require('./app/routes'); | |
|
|
||
| var app = express(); | ||
|
|
||
| const currentEnv = app.get('env'); | ||
| const localMongoUri = `mongodb://localhost:27017/hellogov`; | ||
| const mongoUri = `mongodb://${config.dbUser}:${config.dbPassword}@${config.db}-shard-00-00-5sypa.mongodb.net:27017,${config.db}-shard-00-01-5sypa.mongodb.net:27017,${config.db}-shard-00-02-5sypa.mongodb.net:27017/${config.db}-${config.dbStage}?ssl=true&replicaSet=helloGov-shard-0&authSource=admin&retryWrites=true`; | ||
|
|
||
| if (currentEnv === 'development') { | ||
| mongoose.connect(localMongoUri); | ||
| } else { | ||
| mongoose.connect(mongoUri, { useNewUrlParser: true }); | ||
| } | ||
| mongoose.connect(config.mongoUri, config.mongoOptions); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😂 |
||
| mongoose.connection.on('error', function (err) { | ||
| console.log('Mongo connection error', err.message); | ||
| }); | ||
| mongoose.connection.once('open', function callback() { | ||
| console.log('Connected to MongoDB'); | ||
| }); | ||
|
|
||
| if (currentEnv === 'production') { | ||
| var sessionStore = new MongoStore({ | ||
| url: `${mongoUri}`, | ||
| touchAfter: 0 | ||
| }); | ||
| } else { | ||
| var sessionStore = new MongoStore({ | ||
| url: localMongoUri, | ||
| touchAfter: 0 | ||
| }); | ||
| } | ||
| var sessionStore = new MongoStore({ | ||
| url: config.mongoUri, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you |
||
| touchAfter: 0 | ||
| }); | ||
|
|
||
| app.use(bodyParser.json()); | ||
| app.use(bodyParser.urlencoded({ extended: true })); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| "seed": "mongoimport -c users --uri mongodb://localhost:27017/hellogov --drop --file conf/seeds.json", | ||
| "start": "NODE_ENV=production node index.js", | ||
| "start-dev": "NODE_ENV=development nodemon index.js", | ||
| "start-docker": "NODE_ENV=dev-docker nodemon index.js", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok here is the watch |
||
| "stop-db": "pgrep mongod | xargs kill -2", | ||
| "start-db": "mongod --port 27017 --dbpath /data/db --fork --logpath /usr/local/var/log/mongodb/mongod.log", | ||
| "restart-db": "npm run stop-db && npm run start-db", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does using the entrypoint allow you to watch/rebuild during local development?