From db43974210cf1ea8dc16cef3f8b8d6d298317805 Mon Sep 17 00:00:00 2001 From: Code-Apprentice Date: Sat, 3 Sep 2022 12:08:33 -0700 Subject: [PATCH 1/7] Add volume for static files --- docker-compose.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 5e8bef0..59c164b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,9 @@ services: - db env_file: - .env + volumes: + - static_volume:/bbct/static + nginx: build: ./nginx ports: @@ -31,3 +34,4 @@ services: volumes: postgres_data: + static_volume: From 81b8843b61691b2756f285a9399723abcc42f7b0 Mon Sep 17 00:00:00 2001 From: Code-Apprentice Date: Fri, 9 Sep 2022 20:56:37 -0600 Subject: [PATCH 2/7] Mount volume to docker image to collect static files --- .gitignore | 1 + bbct/settings.py | 1 + docker-compose.yml | 3 +-- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5684672..5422a6e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /venv/ /.idea/ +/static/ .env *.iml *.sqlite3 diff --git a/bbct/settings.py b/bbct/settings.py index 6fe4094..3a14d3d 100644 --- a/bbct/settings.py +++ b/bbct/settings.py @@ -137,4 +137,5 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.2/howto/static-files/ +STATIC_ROOT = '/bbct/static/' STATIC_URL = '/static/' diff --git a/docker-compose.yml b/docker-compose.yml index 59c164b..256cb52 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,7 +11,7 @@ services: env_file: - .env volumes: - - static_volume:/bbct/static + - ./static:/bbct/static nginx: build: ./nginx @@ -34,4 +34,3 @@ services: volumes: postgres_data: - static_volume: From 80bd5b87d73b1a66ee78fcfe2eb41db5e52cf15d Mon Sep 17 00:00:00 2001 From: Code-Apprentice Date: Fri, 9 Sep 2022 21:02:31 -0600 Subject: [PATCH 3/7] Build static directory from BASE_DIR --- bbct/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bbct/settings.py b/bbct/settings.py index 3a14d3d..4104c9c 100644 --- a/bbct/settings.py +++ b/bbct/settings.py @@ -137,5 +137,5 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.2/howto/static-files/ -STATIC_ROOT = '/bbct/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATIC_URL = '/static/' From 99e0f835c7cfec2d9edbdaa188850fe408e134ab Mon Sep 17 00:00:00 2001 From: Code-Apprentice Date: Sun, 11 Sep 2022 21:29:03 -0600 Subject: [PATCH 4/7] Volume for static files --- docker-compose.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 256cb52..9731ae6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,7 +11,7 @@ services: env_file: - .env volumes: - - ./static:/bbct/static + - static_files:/bbct/static nginx: build: ./nginx @@ -19,6 +19,9 @@ services: - "8000:80" depends_on: - api + volumes: + - static_files:/static + db: image: postgres:13.0-alpine volumes: @@ -34,3 +37,4 @@ services: volumes: postgres_data: + static_files: From 1b12d168f293c9b8a7963db54532aba66a04367a Mon Sep 17 00:00:00 2001 From: Code-Apprentice Date: Sun, 11 Sep 2022 21:29:15 -0600 Subject: [PATCH 5/7] Run collecstatic in entrypoint.sh --- entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/entrypoint.sh b/entrypoint.sh index 3beeb55..608bf6d 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -12,5 +12,6 @@ then fi poetry run python manage.py migrate +poetry run python manage.py collectstatic exec "$@" From 99a05c79c9399865ac8b396c795b31578c8ed0a4 Mon Sep 17 00:00:00 2001 From: Code-Apprentice Date: Mon, 12 Sep 2022 00:16:32 -0600 Subject: [PATCH 6/7] Create /bbct/static directory with correct owner --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 91c528d..4db03bf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,8 @@ RUN apt install -y curl # create user RUN useradd -ms /bin/bash bbct +RUN mkdir -p /bbct/static +RUN chown -R bbct /bbct USER bbct # install poetry From 086f0e6ce070da16d023533e7232e22709e91fdc Mon Sep 17 00:00:00 2001 From: Code-Apprentice Date: Mon, 12 Sep 2022 00:16:44 -0600 Subject: [PATCH 7/7] Serve static files from nginx container --- nginx/nginx.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 836ed30..87d8e9b 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -6,6 +6,10 @@ server { listen 80; + location /static { + root /; + } + location / { proxy_pass http://bbct_api; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;