Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
✨ Generate the nginx server configuration during setup
Browse files Browse the repository at this point in the history
  • Loading branch information
jamieconnolly committed Nov 21, 2017
1 parent 0f530ee commit dd00700
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 7 additions & 2 deletions libexec/handles-setup
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ elif [ -f "Rakefile" ] && bundle exec rake -T setup &>/dev/null; then
exec bundle exec rake setup
fi

PROJECT_NAME="${PWD/#${PROJECT_HOME:?}\//}"
PROJECT_NAME="${PWD#${PROJECT_HOME:?}\/}"

if [ -f ".env.example" ]; then
echo "==> Copying environment file…"
cp .env.example .env
fi

if [ -f "nginx.conf.erb" ]; then
echo "==> Generating nginx server configuration file…"
handles-setup-nginx-conf "${PROJECT_NAME//\//-}"
fi

if [ -f "manage.py" ]; then
echo "==> Preparing database…"
echo "==> Setting up database…"
handles-setup-postgres-db "${PROJECT_NAME%/*}"
pipenv run python manage.py migrate
fi
Expand Down
12 changes: 6 additions & 6 deletions libexec/handles-setup-nginx-conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Usage: handles setup-nginx-conf <server_name> [<input_file>]
# Usage: handles setup-nginx-conf <project_name> [<input_file>]
# Summary: Generate an nginx server configuration file
# Hidden: true

Expand All @@ -9,9 +9,9 @@ cd "$(git rev-parse --show-toplevel 2>/dev/null)"

INPUT_FILE="${2-"nginx.conf.erb"}"
OUTPUT_FILE="${PWD}/${INPUT_FILE//.erb}"
SERVER_NAME="$1"
PROJECT_NAME="$1"

if [ -z "$SERVER_NAME" ] || [ -z "$INPUT_FILE" ]; then
if [ -z "$PROJECT_NAME" ] || [ -z "$INPUT_FILE" ]; then
handles help setup-nginx-conf >&2
exit 1
elif [ ! -f "$INPUT_FILE" ] || [[ "$INPUT_FILE" != *.erb ]]; then
Expand All @@ -36,8 +36,8 @@ fi

if [ "$(uname -s)" = "Darwin" ]; then
BREWFILE=(
"brew 'launch_socket_server'"
"brew 'launchdns', restart_service: true"
'brew "launch_socket_server"'
'brew "launchdns", restart_service: true'
)
PREFIX="$(brew --prefix)"

Expand All @@ -62,7 +62,7 @@ if [ "$(uname -s)" = "Darwin" ]; then
fi
fi

SERVER_FILE="${PREFIX}/etc/nginx/servers/${SERVER_NAME}.conf"
SERVER_FILE="${PREFIX}/etc/nginx/servers/${PROJECT_NAME}.conf"
if ! ln -sf "$OUTPUT_FILE" "$SERVER_FILE" &>/dev/null; then
echo "!!! Error: failed to symlink ${OUTPUT_FILE} to ${SERVER_FILE}" >&2
exit 1
Expand Down

0 comments on commit dd00700

Please sign in to comment.