diff --git a/README.md b/README.md index b755997..b495369 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,16 @@ The API backend for Kerckhoff.. Check out the project's [documentation](http://k # Local Development +Make sure your `.env` file is correct +``` +PYTHONPATH="./:$PYTHONPATH" +OAUTHLIB_RELAX_TOKEN_SCOPE=notnull +DATABASE_URL=postgres://postgres:example@postgres:5432/postgres +DJANGO_SECRET_KEY=password +``` + +Make sure your `.secrets` file is correct as well + Start the dev server for local development: ```bash docker-compose up @@ -73,3 +83,8 @@ git push origin master ``` You're now ready to continuously ship! ✨ 💅 🛳 + + +# Troubleshooting + +If you get this error: `/usr/bin/env: ‘python\r’: No such file or directory`, try changing the `manage.py` file to use LF line endings instead of CRLF. \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index eef733c..87f1532 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,6 +3,8 @@ version: "2" services: postgres: image: postgres:9.6 + environment: + POSTGRES_PASSWORD: example web: restart: always env_file: @@ -11,9 +13,7 @@ services: image: web build: ./ command: > - bash -c "python wait_for_postgres.py && - ./manage.py migrate && - ./manage.py runserver 0.0.0.0:8000" + bash -c "python wait_for_postgres.py && ./manage.py migrate && ./manage.py runserver 0.0.0.0:8000" volumes: - ./:/code ports: diff --git a/wait_for_postgres.py b/wait_for_postgres.py index 4ab45e2..a8292f8 100644 --- a/wait_for_postgres.py +++ b/wait_for_postgres.py @@ -5,12 +5,8 @@ check_timeout = os.getenv("POSTGRES_CHECK_TIMEOUT", 30) check_interval = os.getenv("POSTGRES_CHECK_INTERVAL", 1) interval_unit = "second" if check_interval == 1 else "seconds" -config = { - "dbname": os.getenv("POSTGRES_DB", "postgres"), - "user": os.getenv("POSTGRES_USER", "postgres"), - "password": os.getenv("POSTGRES_PASSWORD", ""), - "host": os.getenv("DATABASE_URL", "postgres") -} + +DATABASE_URL = os.getenv("DATABASE_URL") start_time = time() logger = logging.getLogger() @@ -18,10 +14,10 @@ logger.addHandler(logging.StreamHandler()) -def pg_isready(host, user, password, dbname): +def pg_isready(db_url): while time() - start_time < check_timeout: try: - conn = psycopg2.connect(**vars()) + conn = psycopg2.connect(db_url) logger.info("Postgres is ready! ✨ 💅") conn.close() return True @@ -33,4 +29,4 @@ def pg_isready(host, user, password, dbname): return False -pg_isready(**config) +pg_isready(DATABASE_URL) \ No newline at end of file