Skip to content

Commit ea475ec

Browse files
authored
Merge pull request #12 from SADiLaR/feature/environment
Feature: environment
2 parents 85ca134 + 1dd3f4b commit ea475ec

File tree

5 files changed

+44
-17
lines changed

5 files changed

+44
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ venv/
3030
ENV/
3131
env.bak/
3232
venv.bak/
33+
app/static_files/

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ WORKDIR /app
1010
# Install dependencies
1111
COPY requirements.txt /app/
1212

13-
RUN apt-get update
14-
RUN apt-get install graphviz graphviz-dev -y
13+
RUN apt-get update && apt-get -y upgrade
1514

1615
# Install dependencies
1716
RUN pip install --upgrade pip
1817
RUN pip install -r requirements.txt
1918

2019
# Copy project
2120
COPY ./app /app/
21+
COPY ./entrypoint.sh /
2222

2323
# Run the application
24-
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
24+
ENTRYPOINT ["bash", "/entrypoint.sh"]

app/app/settings.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
# Quick-start development settings - unsuitable for production
2020
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
2121

22-
# SECURITY WARNING: keep the secret key used in production secret!
23-
SECRET_KEY = "django-insecure-w!h85bp^$e8gm%c23r!0%9i7yzd=6w$s&ic+6!%306&kj8@k*5"
22+
SECRET_KEY = os.environ["SECRET_KEY"]
2423

2524
# SECURITY WARNING: don't run with debug turned on in production!
26-
DEBUG = True
25+
DEBUG = bool(os.getenv("DEBUG", ""))
2726

28-
ALLOWED_HOSTS = []
27+
ALLOWED_HOSTS = os.getenv("ALLOWED_HOSTS", "").split()
28+
USE_X_FORWARDED_HOST = bool(os.getenv("USE_X_FORWARDED_HOST", ""))
29+
CSRF_TRUSTED_ORIGINS = os.getenv("CSRF_TRUSTED_ORIGINS", "").split()
2930

3031
# Application definition
3132

@@ -35,16 +36,21 @@
3536
"django.contrib.contenttypes",
3637
"django.contrib.sessions",
3738
"django.contrib.messages",
39+
"whitenoise.runserver_nostatic",
3840
"django.contrib.staticfiles",
39-
"django_extensions",
4041
"users",
4142
"general",
4243
]
44+
if DEBUG:
45+
INSTALLED_APPS += [
46+
"django_extensions",
47+
]
4348

4449
AUTH_USER_MODEL = "users.CustomUser"
4550

4651
MIDDLEWARE = [
4752
"django.middleware.security.SecurityMiddleware",
53+
"whitenoise.middleware.WhiteNoiseMiddleware",
4854
"django.contrib.sessions.middleware.SessionMiddleware",
4955
"django.middleware.common.CommonMiddleware",
5056
"django.middleware.csrf.CsrfViewMiddleware",
@@ -82,11 +88,11 @@
8288
DATABASES = {
8389
"default": {
8490
"ENGINE": "django.db.backends.postgresql",
85-
"HOST": os.environ.get("DJANGO_DB_HOST"),
86-
"PORT": os.environ.get("DJANGO_DB_PORT"),
87-
"NAME": os.environ.get("DJANGO_DB_NAME"),
88-
"USER": os.environ.get("DJANGO_DB_USER"),
89-
"PASSWORD": os.environ.get("DJANGO_DB_PASSWORD"),
91+
"HOST": os.environ.get("DB_HOST"),
92+
"PORT": os.environ.get("DB_PORT"),
93+
"NAME": os.environ.get("DB_NAME"),
94+
"USER": os.environ.get("DB_USER"),
95+
"PASSWORD": os.environ.get("DB_PASSWORD"),
9096
}
9197
}
9298

@@ -122,11 +128,21 @@
122128
# Static files (CSS, JavaScript, Images)
123129
# https://docs.djangoproject.com/en/5.0/howto/static-files/
124130

125-
STATIC_URL = "static/"
131+
STATIC_URL = "/static/"
126132
STATICFILES_DIRS = [
127133
BASE_DIR / "static",
128134
]
129135

136+
STATIC_ROOT = BASE_DIR / "static_files"
137+
STORAGES = {
138+
"default": {
139+
"BACKEND": "django.core.files.storage.FileSystemStorage",
140+
},
141+
"staticfiles": {
142+
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
143+
},
144+
}
145+
130146
# Default primary key field type
131147
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
132148

entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -o pipefail
5+
set -x
6+
7+
python manage.py check --deploy --database default
8+
python manage.py migrate --no-input
9+
python manage.py collectstatic --no-input
10+
11+
gunicorn app.wsgi:application --bind 0.0.0.0:8000

requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
django==5.0.2
22
psycopg2-binary
3-
ruff
4-
pygraphviz
5-
django-extensions
3+
gunicorn
4+
whitenoise

0 commit comments

Comments
 (0)