-
Notifications
You must be signed in to change notification settings - Fork 63
edits for tutorial draft #1
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -5,3 +5,5 @@ Dockerfile | |
| .git | ||
| README.md | ||
| .gitignore | ||
| .env | ||
| db-init.js | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,4 +76,5 @@ typings/ | |
| .fusebox/ | ||
|
|
||
| #DynamoDB Local files | ||
| .dynamodb/ | ||
| .dynamodb/ | ||
| db-init.js | ||
|
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. See above comment. |
||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| const mongoose = require('mongoose'); | ||
|
|
||
| const { | ||
| MONGO_USERNAME, | ||
| MONGO_PASSWORD, | ||
| MONGO_HOSTNAME, | ||
| MONGO_PORT, | ||
| MONGO_DB | ||
| } = process.env; | ||
|
|
||
| const options = { | ||
| useNewUrlParser: true, | ||
| reconnectTries: Number.MAX_VALUE, | ||
| reconnectInterval: 500, | ||
| connectTimeoutMS: 10000, | ||
| }; | ||
|
|
||
| const url = `mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOSTNAME}:${MONGO_PORT}/${MONGO_DB}?authSource=admin`; | ||
|
|
||
| mongoose.connect(url, options).then( function() { | ||
| console.log("MongoDB is connected"); | ||
| }) | ||
| .catch( function(err) { | ||
| console.log(err); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,5 +18,8 @@ | |
| "ejs": "^2.6.1", | ||
| "express": "^4.16.4", | ||
| "mongoose": "^5.4.10" | ||
| }, | ||
| "devDependencies": { | ||
| "nodemon": "^1.18.10" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| #!/bin/sh | ||
|
|
||
|
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. Would maybe add a comment in the script linking out to the original on GH. |
||
| TIMEOUT=15 | ||
| QUIET=0 | ||
|
|
||
| echoerr() { | ||
| if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi | ||
| } | ||
|
|
||
| usage() { | ||
| exitcode="$1" | ||
| cat << USAGE >&2 | ||
| Usage: | ||
| $cmdname host:port [-t timeout] [-- command args] | ||
| -q | --quiet Do not output any status messages | ||
| -t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout | ||
| -- COMMAND ARGS Execute command with args after the test finishes | ||
| USAGE | ||
| exit "$exitcode" | ||
| } | ||
|
|
||
| wait_for() { | ||
| for i in `seq $TIMEOUT` ; do | ||
| nc -z "$HOST" "$PORT" > /dev/null 2>&1 | ||
|
|
||
| result=$? | ||
| if [ $result -eq 0 ] ; then | ||
| if [ $# -gt 0 ] ; then | ||
| exec "$@" | ||
| fi | ||
| exit 0 | ||
| fi | ||
| sleep 1 | ||
| done | ||
| echo "Operation timed out" >&2 | ||
| exit 1 | ||
| } | ||
|
|
||
| while [ $# -gt 0 ] | ||
| do | ||
| case "$1" in | ||
| *:* ) | ||
| HOST=$(printf "%s\n" "$1"| cut -d : -f 1) | ||
| PORT=$(printf "%s\n" "$1"| cut -d : -f 2) | ||
| shift 1 | ||
| ;; | ||
| -q | --quiet) | ||
| QUIET=1 | ||
| shift 1 | ||
| ;; | ||
| -t) | ||
| TIMEOUT="$2" | ||
| if [ "$TIMEOUT" = "" ]; then break; fi | ||
| shift 2 | ||
| ;; | ||
| --timeout=*) | ||
| TIMEOUT="${1#*=}" | ||
| shift 1 | ||
| ;; | ||
| --) | ||
| shift | ||
| break | ||
| ;; | ||
| --help) | ||
| usage 0 | ||
| ;; | ||
| *) | ||
| echoerr "Unknown argument: $1" | ||
| usage 1 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| if [ "$HOST" = "" -o "$PORT" = "" ]; then | ||
| echoerr "Error: you need to provide a host and port to test." | ||
| usage 2 | ||
| fi | ||
|
|
||
| wait_for "$@" | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| version: '3' | ||
|
|
||
| services: | ||
| nodejs: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile | ||
| image: nodejs | ||
| container_name: nodejs | ||
| restart: unless-stopped | ||
| env_file: .env | ||
| environment: | ||
| - MONGO_USERNAME=$MONGO_USERNAME | ||
| - MONGO_PASSWORD=$MONGO_PASSWORD | ||
| - MONGO_HOSTNAME=$MONGO_HOSTNAME | ||
| - MONGO_PORT=$MONGO_PORT | ||
| - MONGO_DB=$MONGO_DB | ||
|
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. Would set the |
||
| ports: | ||
| - "80:8080" | ||
| volumes: | ||
| - ./app:/home/node/app | ||
| - node_modules:/home/node/app/node_modules | ||
| depends_on: | ||
| - db | ||
| networks: | ||
| - app-network | ||
| command: ./wait-for.sh db:27017 -- /home/node/app/node_modules/.bin/nodemon app.js | ||
|
|
||
| db: | ||
| image: mongo | ||
| container_name: db | ||
| restart: unless-stopped | ||
| environment: | ||
| - MONGO_INITDB_ROOT_USERNAME=user | ||
|
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. Would avoid checking these (even more) sensitive parameters into version control. Would create a separate |
||
| - MONGO_INITDB_ROOT_PASSWORD=password | ||
| - MONGO_INITDB_DATABASE=admin | ||
| volumes: | ||
| - ./db-init.js:/docker-entrypoint-initdb.d/db-init.js | ||
| - dbdata:/data/db | ||
| networks: | ||
| - app-network | ||
|
|
||
| networks: | ||
| app-network: | ||
| driver: bridge | ||
|
|
||
| volumes: | ||
| dbdata: | ||
| node_modules: | ||
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.
Would check
db-init.jsinto version control (since it is code that gets executed), and modify the script so it pulls config/sensitive info from the already configured.envfile. All config should be centralized and removed from code (and all code that is run should be checked in to VC).