Skip to content

Commit

Permalink
Customize swagger with Safe logo
Browse files Browse the repository at this point in the history
- Add configuration for templates and static files
- Add collect static to Dockerfile
- Don't rebuild docker image unless dependencies change
  • Loading branch information
Uxio0 committed Sep 20, 2022
1 parent 09dfa28 commit 7ebd551
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ENV PYTHONUSERBASE=/python-deps
ENV PATH="${PATH}:${PYTHONUSERBASE}/bin"

WORKDIR /app
COPY . .
COPY requirements.txt ./

RUN set ex \
&& buildDeps=" \
Expand All @@ -27,4 +27,6 @@ RUN set ex \
&& rm -rf /var/lib/apt/lists/* \
&& chmod +x /usr/bin/tini

COPY . .
RUN DEFAULT_FILE_STORAGE=django.core.files.storage.FileSystemStorage python src/manage.py collectstatic --noinput
ENTRYPOINT ["/usr/bin/tini", "--", "./docker-entrypoint.sh"]
11 changes: 8 additions & 3 deletions src/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"DIRS": [
"templates/",
],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
Expand Down Expand Up @@ -178,9 +180,12 @@

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = "static/"
STATIC_ROOT = "staticfiles"
STATIC_URL = "static/"

STATICFILES_DIRS = [
"static",
]

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
Expand Down
25 changes: 25 additions & 0 deletions src/templates/drf-yasg/swagger-ui.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends "drf-yasg/swagger-ui.html" %}
{% load static %}

{% block favicon %}
<link rel="icon" type="image/png" href="{% static 'safe/favicon.png' %}"/>
{% endblock %}

{% block main_styles %}
<link rel="stylesheet" type="text/css" href="{% static 'drf-yasg/style.css' %}"/>
<link rel="stylesheet" type="text/css" href="{% static 'drf-yasg/swagger-ui-dist/swagger-ui.css' %}">
<style>
.swagger-ui .topbar {background-color: black;}
.swagger-ui .topbar .download-url-wrapper .download-url-button {background-color: #008c73;}
.swagger-ui .topbar .download-url-wrapper input[type=text] {border: 2px solid #008c73;}

.topbar-wrapper img[alt="Swagger UI"], .topbar-wrapper span {
visibility: collapse;
}

.topbar-wrapper .link:before {
content: url("{% static 'safe/logo.png' %}");
}

</style>
{% endblock %}
Empty file added static/.gitignore
Empty file.
Binary file added static/safe/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/safe/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7ebd551

Please sign in to comment.