Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
- uses: actions/checkout@v2
- name: Build the project
run: |
echo "ENV=dev" > .env
docker-compose up -d --build backend
docker-compose exec -T backend pip install -r requirements-dev.txt
- name: Lint the code
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ RUN pip install --upgrade --no-cache-dir --requirement $REQUIREMENTS --disable-p

COPY . /app

RUN mkdir -p /var/www/static \
&& ENV=docker ./manage.py collectstatic --noinput
RUN mkdir -p /var/www/static

EXPOSE 80
CMD ./cmd.sh
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
.PHONY: help start test shell loaddata
.PHONY: help start stop test shell flush loaddata
.DEFAULT_GOAL := help

help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort -k 1,1 | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

start: ## Start the development server
@docker-compose up -d --build
@make loaddata

stop: ## Stop the development server
@docker-compose stop

test: ## Test the project
@docker-compose exec backend sh -c "black --check . && flake8 && pytest --no-cov-on-fail --cov --create-db"
@docker-compose exec backend sh -c "black --check . && flake8 && pytest --no-cov-on-fail --cov"

shell: ## Shell into the backend
@docker-compose exec backend bash

loaddata: ## Loads test data into the database
flush: ## Flush database contents
@docker-compose exec backend ./manage.py flush --no-input

loaddata: flush ## Loads test data into the database
@docker-compose exec backend ./manage.py loaddata timed/fixtures/test_data.json
5 changes: 4 additions & 1 deletion cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ sed -i \
-e 's/harakiri = .*/harakiri = '"${UWSGI_HARAKIRI}"'/g' "${UWSGI_INI}" \
-e 's/processes = .*/processes = '"${UWSGI_PROCESSES}"'/g' "${UWSGI_INI}"

wait-for-it.sh "${DJANGO_DATABASE_HOST}":"${DJANGO_DATABASE_PORT}" -t "${WAITFORIT_TIMEOUT}" -- ./manage.py migrate --no-input && uwsgi
wait-for-it.sh "${DJANGO_DATABASE_HOST}":"${DJANGO_DATABASE_PORT}" -t "${WAITFORIT_TIMEOUT}" -- \
./manage.py migrate --no-input && \
./manage.py collectstatic --noinput && \
uwsgi
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ services:
environment:
- DJANGO_DATABASE_HOST=db
- DJANGO_DATABASE_PORT=5432
- ENV=docker
- STATIC_ROOT=/var/www/static
networks:
- timed.local
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ django==3.1.7
# might remove this once we find out how the jsonapi extras_require work
django-filter==2.4.0
django-multiselectfield==0.1.12
django-prometheus==2.1.0
djangorestframework==3.12.4
djangorestframework-jsonapi[django-filter]==3.1.0
mozilla-django-oidc==1.2.4
Expand Down
8 changes: 6 additions & 2 deletions timed/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def default(default_dev=env.NOTSET, default_prod=env.NOTSET):
DATABASES = {
"default": {
"ENGINE": env.str(
"DJANGO_DATABASE_ENGINE", default="django.db.backends.postgresql"
"DJANGO_DATABASE_ENGINE", default="django_prometheus.db.backends.postgresql"
),
"NAME": env.str("DJANGO_DATABASE_NAME", default="timed"),
"USER": env.str("DJANGO_DATABASE_USER", default="timed"),
Expand Down Expand Up @@ -61,6 +61,7 @@ def default(default_dev=env.NOTSET, default_prod=env.NOTSET):
"django_filters",
"djmoney",
"mozilla_django_oidc",
"django_prometheus",
"timed.employment",
"timed.projects",
"timed.tracking",
Expand All @@ -70,13 +71,15 @@ def default(default_dev=env.NOTSET, default_prod=env.NOTSET):
]

MIDDLEWARE = [
"django_prometheus.middleware.PrometheusBeforeMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django_prometheus.middleware.PrometheusAfterMiddleware",
]

ROOT_URLCONF = "timed.urls"
Expand Down Expand Up @@ -148,7 +151,8 @@ def default(default_dev=env.NOTSET, default_prod=env.NOTSET):
CACHES = {
"default": {
"BACKEND": env.str(
"CACHE_BACKEND", default="django.core.cache.backends.locmem.LocMemCache"
"CACHE_BACKEND",
default="django_prometheus.cache.backends.locmem.LocMemCache",
),
"LOCATION": env.str("CACHE_LOCATION", ""),
}
Expand Down
1 change: 1 addition & 0 deletions timed/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
re_path(r"^api/v1/", include("timed.reports.urls")),
re_path(r"^api/v1/", include("timed.subscription.urls")),
re_path(r"^oidc/", include("mozilla_django_oidc.urls")),
re_path(r"^prometheus/", include("django_prometheus.urls")),
]