From a4e4d8cfdddc126aedb3f6912db70ecadb7f02d9 Mon Sep 17 00:00:00 2001 From: "Claudio Maggioni (maggicl)" Date: Sun, 28 Apr 2019 16:04:26 +0200 Subject: [PATCH] Fixed static files for admin --- .gitignore | 3 +++ Dockerfile | 6 ++++-- arrowcounter/settings.py | 2 ++ manage.py | 28 +++++++++++++++++++--------- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 3633aee..86cd900 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +/static/ +!/static/.gitkeep + ### OSX ### .DS_Store .AppleDouble diff --git a/Dockerfile b/Dockerfile index 6ea5f86..e4d9698 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ FROM alpine:3.8 MAINTAINER Claudio Maggioni (praticamentetilde) -RUN addgroup -S app && adduser -S -G app app +RUN addgroup -S app && adduser -S -G app app # Install required packages and remove the apt packages cache when done RUN apk update && apk add \ @@ -26,7 +26,7 @@ RUN apk update && apk add \ uwsgi-python3 \ git \ python3 \ - python3-dev + python3-dev # COPY requirements.txt and RUN pip install BEFORE adding the rest of your # code, this will cause Docker's caching mechanism to prevent re-installing @@ -40,6 +40,8 @@ COPY . /home/app/code/ RUN chown -R app: /home/app +RUN python3 /home/app/code/manage.py collectstatic --no-input + EXPOSE 8000 CMD ["/usr/sbin/uwsgi", "--ini", "/home/app/code/uwsgi.ini", "--plugin", "python3"] USER app diff --git a/arrowcounter/settings.py b/arrowcounter/settings.py index e0dff80..c134c24 100644 --- a/arrowcounter/settings.py +++ b/arrowcounter/settings.py @@ -37,6 +37,8 @@ LOGOUT_REDIRECT_URL = "/" ITEMS_PER_PAGE = 30 +STATIC_ROOT = "static/" + # Application definition INSTALLED_APPS = [ diff --git a/manage.py b/manage.py index 4b87bae..18a1f63 100755 --- a/manage.py +++ b/manage.py @@ -6,16 +6,26 @@ from os import path if __name__ == '__main__': env_path = path.join(path.dirname(path.realpath(__file__)), '.env') - load_dotenv(verbose=True,dotenv_path=env_path) + if not os.path.exists(env_path) and len(sys.argv) >= 2 and len(sys.argv) <= 3 \ + and sys.argv[1] == 'collectstatic': + os.environ['POSTGRES_DB'] = '' + os.environ['POSTGRES_HOST'] = '' + os.environ['POSTGRES_USER'] = '' + os.environ['POSTGRES_PASSWORD'] = '' + os.environ['DEBUG'] = 'true' + os.environ['ALLOWED_HOSTS'] = '' + os.environ['SECURITY_KEY'] = 'dummy-value' + else: + load_dotenv(verbose=True,dotenv_path=env_path) - check_env_vars = ['POSTGRES_DB', 'POSTGRES_HOST', 'POSTGRES_PASSWORD', - 'POSTGRES_USER', 'DEBUG', 'ALLOWED_HOSTS'] - - for key in check_env_vars: - if key not in os.environ: - sys.stderr.write('The mandatory environment ' \ - 'variable ' + key + ' is not set\n') - sys.exit(1) + check_env_vars = ['POSTGRES_DB', 'POSTGRES_HOST', 'POSTGRES_PASSWORD', + 'POSTGRES_USER', 'DEBUG', 'ALLOWED_HOSTS', 'SECURITY_KEY'] + + for key in check_env_vars: + if key not in os.environ: + sys.stderr.write('The mandatory environment ' \ + 'variable ' + key + ' is not set\n') + sys.exit(1) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'arrowcounter.settings') try: