diff --git a/.env.docker b/.env.docker deleted file mode 100644 index 7ebc505a..00000000 --- a/.env.docker +++ /dev/null @@ -1,7 +0,0 @@ -## Docker database -DATABASE_URL=postgres://my_db_user:my_db_password@postgres:5432/my_db_name - -## GENERAL SETTINGS -DEBUG=True -SECRET_KEY=local -ALLOWED_HOSTS=127.0.0.1, localhost, 0.0.0.0 diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..98d825d9 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ + +## Docker database +POSTGRES_DB= +HOST= +POSTGRES_USER= +POSTGRES_PASSWORD= diff --git a/.gitignore b/.gitignore index 65bdf3b5..9d8d910a 100644 --- a/.gitignore +++ b/.gitignore @@ -112,5 +112,4 @@ static *.sqlite3 # IDE -.idea -.env.docker +.idea \ No newline at end of file diff --git a/api_volontaria/.env.example b/api_volontaria/.env.example index 45722b99..97263dc8 100644 --- a/api_volontaria/.env.example +++ b/api_volontaria/.env.example @@ -1,4 +1,5 @@ ## GENERAL SETTINGS DEBUG=True SECRET_KEY=local -ALLOWED_HOSTS=127.0.0.1, localhost, +ALLOWED_HOSTS=127.0.0.1 localhost +DATABASE_URL=postgres://my_db_user:my_db_password@postgres:5432/my_db_name diff --git a/docker-compose.yml b/docker-compose.yml index 3718f22a..5a36bb75 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,14 +4,14 @@ services: postgres: image: postgres:latest environment: - POSTGRES_DB: my_db_name - POSTGRES_USER: my_db_user - POSTGRES_PASSWORD: my_db_password + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} web: restart: always - env_file: .env.docker + env_file: .env environment: - - DJANGO_SECRET_KEY=local + - DJANGO_SECRET_KEY=${SECRET_KEY} image: web build: ./ command: > @@ -31,4 +31,4 @@ services: volumes: - ./:/code ports: - - "8001:8001" + - "8010:8010" diff --git a/docs/getting_started/docker.md b/docs/getting_started/docker.md index fab46736..9a5bd195 100644 --- a/docs/getting_started/docker.md +++ b/docs/getting_started/docker.md @@ -35,7 +35,7 @@ docker-compose run api python source/apiVolontaria/manage.py createsuperuser ## Configurations -If you want to modify some settings of your Docker image you can just overwrite your `.env.docker` file with the +If you want to modify some settings of your Docker image you can just overwrite your `.env` file with the ENV variable that you want. Differents Django settings are based on ENV variables as you can see in `source/apiVolontaria/apiVolontaria/settings.py` diff --git a/wait_for_postgres.py b/wait_for_postgres.py index a692f417..e91e591b 100644 --- a/wait_for_postgres.py +++ b/wait_for_postgres.py @@ -10,7 +10,7 @@ "dbname": os.getenv("POSTGRES_DB", "postgres"), "user": os.getenv("POSTGRES_USER", "postgres"), "password": os.getenv("POSTGRES_PASSWORD", ""), - "host": os.getenv("DATABASE_URL", "postgres") + "host": os.getenv("HOST", "postgres") } start_time = time() @@ -22,14 +22,14 @@ def pg_isready(host, user, password, dbname): while time() - start_time < check_timeout: try: - conn = psycopg2.connect(**vars()) + conn = psycopg2.connect(**config) logger.info("Postgres is ready! ✨ 💅") conn.close() return True except psycopg2.OperationalError: logger.info( f"Postgres isn't ready. Waiting for {check_interval} " - f"{interval_unit}..." + f"{interval_unit}... using {config}" ) sleep(check_interval)