From ce004c5e808b704abe2432e29e1b5ec754a8e32b Mon Sep 17 00:00:00 2001 From: Jonathan Perret Date: Mon, 15 Apr 2024 18:43:16 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F(common)=20remove=20Postgr?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don't need PostgreSQL. --- .github/workflows/oidc2fer.yml | 17 ------------- Dockerfile | 10 -------- Makefile | 28 +-------------------- docker-compose.yml | 16 ------------ env.d/development/postgresql.dist | 11 -------- src/backend/core/tests/test_models_users.py | 23 ----------------- 6 files changed, 1 insertion(+), 104 deletions(-) delete mode 100644 env.d/development/postgresql.dist delete mode 100644 src/backend/core/tests/test_models_users.py diff --git a/.github/workflows/oidc2fer.yml b/.github/workflows/oidc2fer.yml index 579d0d8..3d01143 100644 --- a/.github/workflows/oidc2fer.yml +++ b/.github/workflows/oidc2fer.yml @@ -88,28 +88,11 @@ jobs: run: working-directory: src/backend - services: - postgres: - image: postgres:16 - env: - POSTGRES_DB: oidc2fer - POSTGRES_USER: dinum - POSTGRES_PASSWORD: pass - ports: - - 5432:5432 - # needed because the postgres container does not provide a healthcheck - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 - env: DJANGO_CONFIGURATION: Test DJANGO_SETTINGS_MODULE: oidc2fer.settings DJANGO_SECRET_KEY: ThisIsAnExampleKeyForTestPurposeOnly OIDC_OP_JWKS_ENDPOINT: /endpoint-for-test-purpose-only - DB_HOST: localhost - DB_NAME: oidc2fer - DB_USER: dinum - DB_PASSWORD: pass - DB_PORT: 5432 steps: - name: Checkout repository diff --git a/Dockerfile b/Dockerfile index bc04492..20fbe62 100644 --- a/Dockerfile +++ b/Dockerfile @@ -93,11 +93,6 @@ FROM core as development # Switch back to the root user to install development dependencies USER root:root -# Install psql -RUN apt-get update && \ - apt-get install -y postgresql-client && \ - rm -rf /var/lib/apt/lists/* - # Uninstall oidc2fer and re-install it in editable mode along with development # dependencies RUN pip uninstall -y oidc2fer @@ -107,11 +102,6 @@ RUN pip install -e .[dev] ARG DOCKER_USER USER ${DOCKER_USER} -# Target database host (e.g. database engine following docker compose services -# name) & port -ENV DB_HOST=postgresql \ - DB_PORT=5432 - # Run django development server CMD python manage.py runserver 0.0.0.0:8000 diff --git a/Makefile b/Makefile index 675fe6f..199a501 100644 --- a/Makefile +++ b/Makefile @@ -28,11 +28,6 @@ RESET := \033[0m GREEN := \033[1;32m -# -- Database - -DB_HOST = postgresql -DB_PORT = 5432 - # -- Docker # Get the current user ID to use for docker run and docker exec commands DOCKER_UID = $(shell id -u) @@ -43,7 +38,6 @@ COMPOSE_EXEC = $(COMPOSE) exec COMPOSE_EXEC_APP = $(COMPOSE_EXEC) app-dev COMPOSE_RUN = $(COMPOSE) run --rm COMPOSE_RUN_APP = $(COMPOSE_RUN) app-dev -WAIT_DB = @$(COMPOSE_RUN) dockerize -wait tcp://$(DB_HOST):$(DB_PORT) -timeout 60s # -- Backend MANAGE = $(COMPOSE_RUN_APP) python manage.py @@ -63,8 +57,7 @@ data/static: create-env-files: ## Copy the dist env files to env files create-env-files: \ - env.d/development/common \ - env.d/development/postgresql + env.d/development/common .PHONY: create-env-files bootstrap: ## Prepare Docker images for the project @@ -93,8 +86,6 @@ logs: ## display app-dev logs (follow mode) run: ## start the wsgi (production) and development server @$(COMPOSE) up --force-recreate -d nginx @$(COMPOSE) up --force-recreate -d app-dev - @echo "Wait for postgresql to be up..." - @$(WAIT_DB) .PHONY: run status: ## an alias for "docker compose ps" @@ -144,20 +135,6 @@ test-back-parallel: ## run all back-end tests in parallel bin/pytest -n auto $${args:-${1}} .PHONY: test-back-parallel -makemigrations: ## run django makemigrations for the oidc2fer project. - @echo "$(BOLD)Running makemigrations$(RESET)" - @$(COMPOSE) up -d postgresql - @$(WAIT_DB) - @$(MANAGE) makemigrations -.PHONY: makemigrations - -migrate: ## run django migrations for the oidc2fer project. - @echo "$(BOLD)Running migrations$(RESET)" - @$(COMPOSE) up -d postgresql - @$(WAIT_DB) - @$(MANAGE) migrate -.PHONY: migrate - superuser: ## Create an admin superuser with password "admin" @echo "$(BOLD)Creating a Django superuser$(RESET)" @$(MANAGE) createsuperuser --email admin@example.com --password admin @@ -182,9 +159,6 @@ resetdb: ## flush database and create a superuser "admin" env.d/development/common: cp -n env.d/development/common.dist env.d/development/common -env.d/development/postgresql: - cp -n env.d/development/postgresql.dist env.d/development/postgresql - # -- Misc clean: ## restore repository state as it was freshly cloned git clean -idx diff --git a/docker-compose.yml b/docker-compose.yml index 1fdb41d..b650b96 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,4 @@ services: - postgresql: - image: postgres:16 - env_file: - - env.d/development/postgresql - ports: - - "15432:5432" - app-dev: build: context: . @@ -19,15 +12,12 @@ services: - DJANGO_CONFIGURATION=Development env_file: - env.d/development/common - - env.d/development/postgresql ports: - "8071:8000" volumes: - ./src/backend:/app - ./data/media:/data/media - ./data/static:/data/static - depends_on: - - postgresql app: build: @@ -41,11 +31,8 @@ services: - DJANGO_CONFIGURATION=Demo env_file: - env.d/development/common - - env.d/development/postgresql volumes: - ./data/media:/data/media - depends_on: - - postgresql nginx: image: nginx:1.25 @@ -57,6 +44,3 @@ services: - ./data/media:/data/media:ro depends_on: - app - - dockerize: - image: jwilder/dockerize diff --git a/env.d/development/postgresql.dist b/env.d/development/postgresql.dist deleted file mode 100644 index 1f10d48..0000000 --- a/env.d/development/postgresql.dist +++ /dev/null @@ -1,11 +0,0 @@ -# Postgresql db container configuration -POSTGRES_DB=oidc2fer -POSTGRES_USER=dinum -POSTGRES_PASSWORD=pass - -# App database configuration -DB_HOST=postgresql -DB_NAME=oidc2fer -DB_USER=dinum -DB_PASSWORD=pass -DB_PORT=5432 \ No newline at end of file diff --git a/src/backend/core/tests/test_models_users.py b/src/backend/core/tests/test_models_users.py deleted file mode 100644 index cfe9562..0000000 --- a/src/backend/core/tests/test_models_users.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -Unit tests for the User model -""" -from django.core.exceptions import ValidationError - -import pytest - -from core import factories - -pytestmark = pytest.mark.django_db - - -def test_models_users_str(): - """The str representation should be the email.""" - user = factories.UserFactory() - assert str(user) == user.email - - -def test_models_users_id_unique(): - """The "id" field should be unique.""" - user = factories.UserFactory() - with pytest.raises(ValidationError, match="User with this Id already exists."): - factories.UserFactory(id=user.id)