-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from CirclesUBI/improve-docker
Improve docker setup
- Loading branch information
Showing
6 changed files
with
139 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build | ||
node_modules | ||
test |
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,45 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
CMD="$@" | ||
|
||
# Set default values | ||
POSTGRES_PORT=${POSTGRES_PORT:-5432} | ||
NODE_ENV=${NODE_ENV:-"production"} | ||
|
||
# Helper method to extract host and port from url | ||
parse_url() { | ||
# Extract the protocol | ||
proto="$(echo $1 | grep :// | sed -e's,^\(.*://\).*,\1,g')" | ||
# Remove the protocol | ||
url=$(echo $1 | sed -e s,$proto,,g) | ||
# Extract the host and port | ||
hostport=$(echo $url | cut -d/ -f1) | ||
# Extract host without port | ||
host="$(echo $hostport | sed -e 's,:.*,,g')" | ||
# Try to extract the port | ||
port="$(echo $hostport | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')" | ||
# Set port default when not given | ||
if [ -z "$port" ] | ||
then | ||
[ "$proto" = "https://" ] && port=443 || port=80 | ||
fi | ||
echo "$host:$port" | ||
} | ||
|
||
# Wait until graph node is ready | ||
./wait-for-it.sh "$(parse_url $GRAPH_NODE_ENDPOINT)" -t 60 | ||
|
||
# Wait until database is ready | ||
./wait-for-it.sh "$POSTGRES_HOST:$POSTGRES_PORT" -t 60 | ||
|
||
# Set DATABASE_URL env variable in correct format for application | ||
export DATABASE_URL=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DATABASE_API | ||
|
||
# Run migrations | ||
npm run db:migrate | ||
npm run db:seed | ||
|
||
# Finally execute start command | ||
exec $CMD |
This file was deleted.
Oops, something went wrong.
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,83 @@ | ||
#!/bin/sh | ||
|
||
# POSIX compatible clone of wait-for-it.sh | ||
# This copy is from https://github.com/eficode/wait-for/commits/master | ||
# at commit 8d9b4446 | ||
|
||
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() { | ||
echo "Wait $TIMEOUT seconds for $HOST:$PORT to be ready ..." | ||
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 "$@" |