forked from hackforla/peopledepot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scripts and instructions for running the backend in a virtual env The breaking change for devs is they have to move their `.env.dev` for `app/.env.docker` in order for their project to continue functioning. --------- Co-authored-by: Fang Yi Liu <fangyiliu@gmail.com>
- Loading branch information
1 parent
91f0f5e
commit ec46527
Showing
14 changed files
with
622 additions
and
49 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -12,6 +12,9 @@ app/htmlcov | |
|
||
### dotenv ### | ||
.env.dev | ||
.env.docker | ||
.env.local | ||
.env.test | ||
.env | ||
|
||
### Vim ### | ||
|
Large diffs are not rendered by default.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.env.dev | ||
.env.docker | ||
.dockerignore | ||
Dockerfile | ||
app/.coverage | ||
|
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,40 @@ | ||
DEBUG=1 | ||
SECRET_KEY=foo | ||
DJANGO_PORT=8000 | ||
DJANGO_ALLOWED_HOSTS="localhost 127.0.0.1 [::1]" | ||
DJANGO_SUPERUSER_USERNAME=admin1111 | ||
DJANGO_SUPERUSER_EMAIL=admin@admin.com | ||
DJANGO_SUPERUSER_PASSWORD=admin | ||
|
||
# postgres settings for docker | ||
SQL_ENGINE=django.db.backends.postgresql | ||
SQL_DATABASE=people_depot_dev | ||
SQL_USER=people_depot | ||
SQL_PASSWORD=people_depot | ||
SQL_HOST=db | ||
SQL_PORT=5432 | ||
DATABASE=postgres | ||
|
||
# postgres settings for local development | ||
# SQL_ENGINE=django.db.backends.postgresql | ||
# SQL_DATABASE=postgres | ||
# SQL_USER= | ||
# SQL_PASSWORD= | ||
# SQL_HOST=localhost | ||
# SQL_PORT=5432 | ||
# DATABASE=postgres | ||
|
||
# sqlite settings for local development | ||
# SQL_ENGINE= | ||
# SQL_DATABASE= | ||
# SQL_USER= | ||
# SQL_PASSWORD= | ||
# SQL_HOST= | ||
# SQL_PORT= | ||
# DATABASE= | ||
|
||
COGNITO_DOMAIN=peopledepot | ||
COGNITO_AWS_REGION=us-west-2 | ||
COGNITO_USER_POOL=us-west-2_Fn4rkZpuB | ||
|
||
PEOPLE_DEPOT_API_SECRET=people-depot-api-secret |
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
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
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,42 @@ | ||
# Run backend in venv | ||
|
||
If you have a requirement to run on your local machine or you are unable to get it to work on | ||
Docker, do the following steps. WARNING: If you run into issues you will get limited support. | ||
|
||
Run these commands from the `app` directory: | ||
|
||
1. Copy `.env.docker-example` to `.env.local` | ||
1. Inspect `.env.local` and change values as appropriate. The file includes instructions on how to use local `postgres` and `sqlite` for the database. `sqlite` has no set up. It uses a file `db.sqlite3`. If it is not there, it automatically creates it. | ||
1. **Mac only**: If you have a Mac, the python command may not be found and scripts will fail. Try to run python using the "python" command from the terminal. If you get an error that the python command is | ||
not found, type: `alias python="python3"` | ||
1. Run these commands from the terminal in the project root. | ||
|
||
```bash | ||
cd app | ||
|
||
# copy the env file | ||
cp .env.docker-example .env.local | ||
|
||
# create a virtual environment | ||
python -m venv venv | ||
|
||
# activate (enter) the virtual environment | ||
source venv/bin/activate | ||
# install dependencies | ||
pip install -r requirements.txt | ||
|
||
# start local server | ||
../scripts/start-local.sh | ||
# start server with alternate port | ||
# DJANGO_PORT=8001 ../scripts/start-local.sh | ||
|
||
# browse to http://localhost:8000 (or 8001) to see the app | ||
|
||
# Ctrl-C to stop the server | ||
|
||
# deactivate (exit) the virtual environment | ||
# to return to the system global environment | ||
deactivate | ||
``` | ||
|
||
**TIP**: Look up `direnv` for a useful method to automatically enter and exit virtual environments based on the current directory. |
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,27 @@ | ||
#!/bin/bash | ||
echo SQL USER "$SQL_USER" | ||
export file=$1 | ||
echo "file = $file / $1 / $2" | ||
if [ "$file" == "" ] | ||
then | ||
echo "File not specified. Using .env.local" | ||
file=".env.local" | ||
fi | ||
|
||
echo "Loading environment variables from $file" | ||
|
||
if [ ! -f "$file" ] | ||
then | ||
echo "File $file not found" | ||
echo "If executing locally, copy .env.example.dev to $file and edit as needed" | ||
return 1 | ||
fi | ||
while IFS= read -r line; do | ||
if [[ -n "$line" ]]; then | ||
export export_command="export $line" | ||
echo "export_command = $export_command" | ||
eval "$export_command" | ||
fi | ||
done < <(grep -v '^#' "$file") | ||
echo Super user "$DJANGO_SUPERUSER_USERNAME" | ||
echo SQL USER "$SQL_USER" |
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,70 @@ | ||
#!/bin/bash | ||
# Called by start-dev.sh and start-docker.sh, which sets | ||
# - DATABASE_HOST | ||
# - DJANGO_SUPERUSER | ||
# - DJANGO_SUPERUSER_PASSWORD | ||
# - DJANGO_SUPERUSER_EMAIL | ||
if [[ $PWD != *"app"* ]]; then | ||
cd app || { | ||
echo "ERROR: cd app failed" | ||
return 1 | ||
} | ||
fi | ||
|
||
SCRIPT_DIR="$(dirname "$0")" | ||
"$SCRIPT_DIR"/loadenv.sh || { | ||
echo "ERROR: loadenv.sh failed" | ||
return 1 | ||
} | ||
echo Admin user = "$DJANGO_SUPERUSER" email = "$DJANGO_SUPERUSER_EMAIL" | ||
if [[ $1 != "" ]]; then | ||
port=$1 | ||
elif [[ "$DJANGO_PORT" != "" ]]; then | ||
port=$DJANGO_PORT | ||
else | ||
port=8000 | ||
fi | ||
echo Port is "$port" | ||
|
||
echo | ||
echo --- Executing python manage.py makemigrations --- | ||
echo | ||
python manage.py makemigrations || { | ||
echo "ERROR: python manage.py makemigrations failed" | ||
return 1 | ||
} | ||
|
||
|
||
echo | ||
echo --- Executing python manage.py migrate --- | ||
echo | ||
python manage.py migrate || { | ||
echo "ERROR: python manage.py migrate failed" | ||
return 1 | ||
} | ||
|
||
echo | ||
echo --- Executing python manage.py shell to check if "$DJANGO_SUPERUSER_USERNAME" exists | ||
echo | ||
python manage.py shell -c "from core.models import User; exists = (User.objects.filter(username='$DJANGO_SUPERUSER_USERNAME').exists()); sys.exit(0 if exists else 1)" | ||
|
||
superuser_exists=$? | ||
|
||
if [ $superuser_exists -eq 1 ]; then | ||
echo | ||
echo --- Executing python manage.py createsuperuser --- | ||
echo | ||
if ! python manage.py createsuperuser --username "$DJANGO_SUPERUSER_USERNAME" --email "$DJANGO_SUPERUSER_EMAIL" --no-input; | ||
then | ||
echo "ERROR: python manage.py createsuperuser failed" | ||
return 1 | ||
fi | ||
else | ||
echo --- INFO: Skipping python manage.py createsuperuser - super user "$DJANGO_SUPERUSER_USERNAME" already exists. | ||
fi | ||
|
||
echo | ||
echo --- All prep steps successful! Executing python manage.py runserver | ||
echo | ||
|
||
python manage.py runserver 0.0.0.0:"$port" |