Skip to content

Commit

Permalink
backend: allow customizing admin url
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Aug 1, 2024
1 parent 44b9328 commit 91329d0
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ TRCUSTOMS_PORT=8000
SECRET_KEY=change_me
DEBUG=1
HOST_SITE=http://localhost/
ADMIN_DIR=admin

USE_AWS_STORAGE=0

Expand Down
1 change: 1 addition & 0 deletions backend/trcustoms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def get_bool_setting(name: str, **kwargs) -> bool:
]
STATIC_ROOT = BASE_DIR / "django_static"

ADMIN_DIR = get_setting("ADMIN_DIR")
MEDIA_URL = "/uploads/"
MEDIA_ROOT = BASE_DIR / "uploads"

Expand Down
2 changes: 1 addition & 1 deletion backend/trcustoms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
urlpatterns = [
path("api/auth/token/", TokenObtainPairView.as_view()),
path("api/auth/token/refresh/", TokenRefreshView.as_view()),
path("admin/", admin.site.urls),
path(settings.ADMIN_DIR + "/", admin.site.urls),
path("api/", include(router.urls)),
path("api/level_genres/", GenreListView.as_view()),
path("api/level_genres/<int:pk>/", GenreDetailView.as_view()),
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ x-backend-environment: &base-backend-environment
- DEBUG=0
- DEBUG_SQL=0
- HOST_SITE=${HOST_SITE}
- ADMIN_DIR=${ADMIN_DIR}
- POSTGRES_DB=trcustoms
- POSTGRES_USER=root
- POSTGRES_PASSWORD=root
Expand Down Expand Up @@ -85,6 +86,7 @@ services:
- BUILD_DATE=${BUILD_DATE}
- BUILD_VERSION=${BUILD_VERSION}
- HOST_SITE=${HOST_SITE}
- ADMIN_DIR=${ADMIN_DIR}
networks:
- trcustoms
ports:
Expand Down
6 changes: 4 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ x-backend-environment: &base-backend-environment
- DEBUG=${DEBUG}
- DEBUG_SQL=${DEBUG_SQL}
- HOST_SITE=${HOST_SITE}
- ADMIN_DIR=${ADMIN_DIR}
- POSTGRES_DB=trcustoms
- POSTGRES_USER=root
- POSTGRES_PASSWORD=root
Expand Down Expand Up @@ -101,13 +102,13 @@ services:
trcustoms-nginx:
<<: *base-trcustoms
image: nginx
environment: *base-backend-environment
volumes:
- ./services/nginx/nginx_prerender_map.conf:/etc/nginx/nginx_prerender_map.conf:ro
- ./services/nginx/nginx_prerender_server.conf:/etc/nginx/nginx_prerender_server.conf:ro
- ./services/nginx/nginx_dev.conf:/etc/nginx/nginx.conf:ro
- ./services/nginx/nginx_dev.conf.template:/etc/nginx/nginx.conf.template:ro
- ./backend/volumes/uploads/:/app/uploads/
- ./backend/volumes/django_static/:/app/django_static/
command: ["nginx", "-g", "daemon off;"]
networks:
- trcustoms
ports:
Expand All @@ -117,6 +118,7 @@ services:
target: 8000
depends_on:
- trcustoms
command: /bin/bash -c 'envsubst "\$${ADMIN_DIR}" < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf && nginx -g "daemon off;"'

trcustoms-prerender:
<<: *base-trcustoms-backend
Expand Down
4 changes: 3 additions & 1 deletion services/nginx/Dockerfile_prod
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ RUN npm run build
# The second stage
# Copy React static files and start nginx
FROM nginx:stable-alpine
ARG ADMIN_DIR
COPY services/nginx/nginx_prerender_map.conf /etc/nginx/nginx_prerender_map.conf
COPY services/nginx/nginx_prerender_server.conf /etc/nginx/nginx_prerender_server.conf
COPY services/nginx/nginx_prod.conf /etc/nginx/nginx.conf
COPY services/nginx/nginx_prod.conf.template /etc/nginx/nginx.conf.template
RUN envsubst '${ADMIN_DIR}' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf
COPY --from=build /app/frontend/build /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ http {
proxy_pass http://trcustoms-frontend:3000;
}

location ~ ^/(admin|api|uploads|django_static)(/.*)?$ {
location ~ ^/(${ADMIN_DIR}|api|uploads|django_static)(/.*)?$ {
proxy_pass http://trcustoms:8000;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ http {
try_files $uri $uri/ /index.html;
}

location ~ ^/(admin|api)(/.*)?$ {
location ~ ^/(${ADMIN_DIR}|api)(/.*)?$ {
proxy_pass http://trcustoms:8000;
}

Expand Down

0 comments on commit 91329d0

Please sign in to comment.