diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7419b23..b957134 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -72,6 +72,8 @@ jobs: with: context: . push: true + build-args: | + GIT_SHA=${{ github.sha }} tags: | ${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }} ${{ env.IMAGE_NAME }}:${{ github.sha }} diff --git a/Dockerfile b/Dockerfile index 1288e06..726748d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,6 +53,11 @@ RUN sed -i '/pt_BR.UTF-8/s/^# //g' /etc/locale.gen && \ # Copy the virtual environment from builder COPY --from=builder /app/.venv /app/.venv +# Changes every commit; placed here so it doesn't invalidate the apt-get/locale +# layers above on every build. +ARG GIT_SHA="" +ENV GIT_SHA=${GIT_SHA} + # Copy project COPY . /app/ diff --git a/compose.yaml b/compose.yaml index 55b2c06..1aa4d8f 100644 --- a/compose.yaml +++ b/compose.yaml @@ -20,6 +20,8 @@ services: - ${SOCKET_DIR}:/run/sockets env_file: - .env + environment: + - IMAGE_TAG=${IMAGE_TAG:-latest} depends_on: - db restart: unless-stopped diff --git a/config/settings.py b/config/settings.py index 3816536..0bb2549 100644 --- a/config/settings.py +++ b/config/settings.py @@ -1,5 +1,6 @@ from pathlib import Path import os +import tomllib from dotenv import load_dotenv, find_dotenv from django.contrib.messages import constants as messages @@ -10,6 +11,15 @@ BUILD_ENV = os.getenv("BUILD_ENV", default="local") +with open(BASE_DIR / "pyproject.toml", "rb") as f: + APP_VERSION = tomllib.load(f)["project"]["version"] + +# Set at image build time (see Dockerfile / .github/workflows/main.yml); empty outside CI builds. +GIT_SHA = os.getenv("GIT_SHA", "")[:7] + +# Which image tag this container was deployed from (set via compose.yaml); "dev" or "latest". +IMAGE_TAG = os.getenv("IMAGE_TAG", "latest") + # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = os.getenv("SECRET_KEY") @@ -81,6 +91,7 @@ "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", + "presente.context_processors.app_info", ], }, }, diff --git a/presente/context_processors.py b/presente/context_processors.py new file mode 100644 index 0000000..86dc958 --- /dev/null +++ b/presente/context_processors.py @@ -0,0 +1,9 @@ +from django.conf import settings + + +def app_info(request): + return { + "app_version": settings.APP_VERSION, + "git_sha": settings.GIT_SHA, + "is_dev_build": settings.IMAGE_TAG == "dev", + } diff --git a/pyproject.toml b/pyproject.toml index 47d04fc..6615b8e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "presente" -version = "0.1.0" +version = "1.0.0" description = "Sistema open source para gerenciamento de presença em atividades extra-classe do IFRN." readme = "README.md" requires-python = ">=3.11" diff --git a/templates/presente/private_base.html b/templates/presente/private_base.html index b40e5f3..232faa4 100644 --- a/templates/presente/private_base.html +++ b/templates/presente/private_base.html @@ -136,8 +136,9 @@