-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] add docker and docker compose setup and changed database e…
…nviroment variable
- Loading branch information
Showing
6 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM node:8.11.1-alpine | ||
|
||
WORKDIR /usr/app | ||
|
||
COPY package.json . | ||
RUN npm install -g -s --no-progress yarn && yarn | ||
|
||
COPY . . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: '2' | ||
services: | ||
web: | ||
build: . | ||
command: sh -c './wait-for.sh mongodb:27017 && yarn start' | ||
volumes: | ||
- .:/usr/app/ | ||
- /usr/app/node_modules | ||
ports: | ||
- '8000:8000' | ||
depends_on: | ||
- mongodb | ||
environment: | ||
DATABASE_URI: mongodb://mongodb:27017/graphql | ||
mongodb: | ||
image: mongo:3.6.4-jessie | ||
ports: | ||
- '27017:27017' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/sh | ||
|
||
# Credit: https://github.com/vnegrisolo/wait-for | ||
|
||
|
||
log() { | ||
echo "[wait-for] [`date +'%Y%m%d%H%M%S'`] $@" | ||
} | ||
|
||
usage() { | ||
echo "Usage: `basename "$0"` [--timeout=15] <HOST>:<PORT> [<HOST_2>:<PORT_2>]" | ||
} | ||
|
||
unknown_arg() { | ||
log "[ERROR] unknown argument: '$@'" | ||
usage | ||
exit 2 | ||
} | ||
|
||
wait_for() { | ||
timeout=$1 && host=$2 && port=$3 | ||
log "wait '$host':'$port' up to '$timeout'" | ||
for i in `seq $timeout` ; do | ||
if nc -z "$host" "$port" > /dev/null 2>&1 ; then | ||
log "wait finish '$host:$port' [`expr $(date +%s) - $START`] seconds" | ||
exit 0 | ||
fi | ||
log "wait attempt '${host}:${port}' [$i]" | ||
sleep 1 | ||
done | ||
log "[ERROR] wait timeout of '$timeout' on '$host:$port'" | ||
exit 1 | ||
} | ||
|
||
trap 'kill $(jobs -p) &>/dev/null' EXIT | ||
|
||
START=$(date +%s) | ||
timeout=15 | ||
pids="" | ||
for i in $@ ; do | ||
case $i in | ||
--timeout=*) timeout="${i#*=}" ;; | ||
-t=*) timeout="${i#*=}" ;; | ||
*:* ) | ||
wait_for "$timeout" "${i%%:*}" "${i##*:}" & | ||
pids="$pids $!" | ||
;; | ||
*) unknown_arg "$i" ;; | ||
esac | ||
done | ||
|
||
status=0 | ||
for pid in $pids; do | ||
if ! wait $pid ; then | ||
status=1 | ||
fi | ||
done | ||
|
||
log "wait done with status=$status" | ||
exit $status |