From dd74865af89513b65acecc01d95893570e376036 Mon Sep 17 00:00:00 2001 From: Bart Reunes Date: Tue, 27 Aug 2024 12:09:52 +0200 Subject: [PATCH 01/12] adding a new compose setup, leveraged by gotask --- .env | 2 - .env.dist | 31 ++++++++ .gitignore | 3 +- Dockerfile | 18 ++--- Makefile | 25 ------ README.md | 126 +++++++----------------------- Taskfile.dist.yml | 109 ++++++++++++++++++++++++++ compose.dev.yaml | 31 ++++++++ compose.fixed-ports.mixin.yaml | 9 +++ compose.traefik.mixin.yaml | 15 ++++ compose.yaml | 60 ++++++++++++++ docker-compose.yml | 15 ---- scripts/docker/Dockerfile | 9 --- scripts/docker/docker-compose.yml | 15 ---- 14 files changed, 291 insertions(+), 177 deletions(-) delete mode 100644 .env create mode 100644 .env.dist delete mode 100644 Makefile create mode 100644 Taskfile.dist.yml create mode 100644 compose.dev.yaml create mode 100644 compose.fixed-ports.mixin.yaml create mode 100644 compose.traefik.mixin.yaml create mode 100644 compose.yaml delete mode 100644 docker-compose.yml delete mode 100644 scripts/docker/Dockerfile delete mode 100644 scripts/docker/docker-compose.yml diff --git a/.env b/.env deleted file mode 100644 index d49a909..0000000 --- a/.env +++ /dev/null @@ -1,2 +0,0 @@ -PYTHONDONTWRITEBYTECODE=1 -PYTHONUNBUFFERED=1 \ No newline at end of file diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..9c9f228 --- /dev/null +++ b/.env.dist @@ -0,0 +1,31 @@ +# Docker Compose +PROJECT_DOMAIN_SUFFIX=localhost + +COMPOSE_PROJECT_NAME=ninetofiver +COMPOSE_FILE=compose.yaml,compose.dev.yaml,compose.traefik.mixin.yaml +#COMPOSE_FILE=compose.yaml,compose.dev.yaml,compose.fixed-ports.mixin.yaml +COMPOSE_PATH_SEPARATOR=, + +MYSQL_EXPOSED_PORT=3306 +NINETOFIVER_EXPOSED_PORT=8888 + +MYSQL_DATABASE=ninetofiver-database +MYSQL_USER=ninetofiver-user +MYSQL_PASSWORD=ninetofiver-password + +SUPERUSER_EMAIL=admin@example.com +SUPERUSER_USERNAME=admin +SUPERUSER_PASSWORD=admin + +API_APPLICATION_NAME=application +API_APPLICATION_CLIENT_ID=application-id +API_APPLICATION_CLIENT_SECRET=application-secret + +# Application +DJANGO_SETTINGS_MODULE=ninetofiver.settings +DJANGO_CONFIGURATION=Dev + +CFG_FILE_PATH=/etc/925r/config.yml + +PYTHONDONTWRITEBYTECODE=1 +PYTHONUNBUFFERED=1 diff --git a/.gitignore b/.gitignore index 957caf8..9857393 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,8 @@ docs/_build/ !/media/.gitkeep *.log .tox/ -.env .coverage /scripts/docker/mysql-init/ test_results.html + +/.env diff --git a/Dockerfile b/Dockerfile index 3f239fb..61abdba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,17 @@ -# Pull base image -FROM python:3.8-slim-buster as builder +FROM python:3.8-slim-buster AS builder # install python project dependencies pre-requisites -RUN apt-get update && \ - apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev && \ - apt-get install -y gcc default-libmysqlclient-dev - -# Set environment variables -COPY requirements.txt requirements.txt +RUN apt-get update \ + && apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev \ + && apt-get install -y gcc default-libmysqlclient-dev # Install pipenv RUN set -ex && pip install --upgrade pip # Install dependencies +COPY requirements.txt requirements.txt RUN set -ex && pip install -r requirements.txt -FROM builder as final +FROM builder AS final WORKDIR /code COPY . /app/ - -RUN set -ex && bash -c "eval $(grep 'PYTHONDONTWRITEBYTECODE' .env)" -RUN set -ex && bash -c "eval $(grep 'PYTHONUNBUFFERED' .env)" \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 896c9a1..0000000 --- a/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -.PHONY: help -help: ## Show this help - @egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' - -.PHONY: build -build: ## Build project with docker compose - docker-compose build - - -.PHONY: up -up: ## Run project with docker compose - docker-compose up --build --remove-orphans web - - -.PHONY: down -down: ## Reset project containers with docker compose - docker-compose down - -.PHONY: clean -clean: ## Clean Reset project containers with docker compose - docker-compose down -v --remove-orphans - -.PHONY: test -test: ## Run project tests and coverage with tox runner - docker-compose run --rm web tox diff --git a/README.md b/README.md index c989d0d..c7466af 100644 --- a/README.md +++ b/README.md @@ -7,112 +7,48 @@ ninetofiver [![License](https://img.shields.io/github/license/kalmanolah/925r.svg)](https://shields.io) ninetofiver (or 925r) is a free and open source time and leave tracking application. + +## Dependencies -## Installation +- [Taskfile](https://taskfile.dev/) +- [Docker Compose plugin](https://docs.docker.com/compose/) -Install build dependencies: - -```bash -apt-get install -y python-dev default-libmysqlclient-dev libldap2-dev libsasl2-dev libssl-dev -``` -or -```bash -sudo dnf install -y mysql-devel openldap-devel -``` - -You'll need [pipenv](https://docs.pipenv.org/). Installing it is super simple: - -```bash -pip install pipenv -``` - -After that, installing the application is smooth sailing: - -```bash -pipenv install -``` - -Once your pipenv is set up, you can use `pipenv shell` to get a shell, or -just prefix additional commands with `pipenv run`. +The Taskfile and Docker Compose setup hides a bit of the setup. +If you want to walk the manual path, check the files `.env.dist`, `Taskfile.dist.yml` and `Dockerfile`. ## Usage -**For usage with Docker, see latter section named _Local Development (with Docker)_.** -1. Run `python manage.py migrate` to create the models. -2. Run `python manage.py createsuperuser` to create an admin user -### Running (development) +1. Run `task prepare` and check if the values in the .env file are correct for your environment +2. Run `task start` to start the application at `http://localhost:8000`. +3. Run `task app:migrate` to create the models +4. Run `task app:create-superuser` to create an admin user (interactively) +5. Run `task app:generate-data` to fill the database with test data (see below for more information) -Running the command below starts a development server at -`http://127.0.0.1:8000`. +For more tasks, check `task --list-all`. + +## First steps -```bash -python manage.py runserver -``` - -### Running (production) +### Set up an application for YaYata -Running the command below starts a server using the production configuration -at `http://127.0.0.1:8000`. +Before you can set up YaYata, you need to register an application in ninetofiver. -Note: The `insecure` flag is used to allow the server to serve static files. - -```bash -python manage.py runserver --configuration=Prod --insecure -``` - -## Local Development (with Docker) - -To build, run and test and more ... use magic of make help to play with this project. -Make sure you have installed docker and docker compose. -```shell -make help -``` -and you receive below list: -```text -build Build project with docker compose -clean Clean Reset project containers with docker compose -down Reset project containers with docker compose -help Show this help -test Run project tests and coverage with tox runner -up Run project with docker compose -``` -### How to run local environment with test data. -Build and run docker containers. -```shell -make build -make up -``` -Exec initial migration. After _exec_ should be your 925r container name. -```shell -docker exec 925r-web python manage.py migrate -``` -Interactively create a new superuser. -```shell -docker exec -it 925r-web python manage.py createsuperuser -``` - -If you are running YaYata too (in debug mode), then you could need to change 925r port from -8888 to something else, because YaYata runs webpack on the port 8888. - -### Next steps -If you want to work with YaYata you need to set up an application. 1. Log in. 2. In the right top corner, navigate to **Your Account -> Your applications -> New application**. 3. Fill **Name** and **Client id**. 4. Set **Client type = Public**. 5. Set **Authorization grant type = Resource owner password-based**. -Now you can log in YaYata with root account, or you can create a new test user. -You are all set to work with Admin interface, if you want some test data filled, see next section. +Now you can log in to YaYata with the root account, or you can create a new test user. -## Example/Test data -You can use django command `create_test_data` to fill database with test data. -You can specify the ammount of data to be created by one optional argument -(`small`, `normal` or `extensive`) with `normal` being the default ammount when not specified. +### Add example data + +You can run `task app:generate-data` to fill the database with test data. +You can specify the amount of data to be created by one optional argument `AMOUNT`. Possible values are +(`small`, `normal` or `extensive`) with `normal` being the default. It can run a few minutes depending on resources. For this reason there is a `-t` option, so you can see what is happening at the moment. ```shell -docker exec -t 925r-web python manage.py create_test_data extensive +task app:generate-data AMOUNT=extensive -- -t ``` ## Configuration @@ -135,33 +71,27 @@ could use the following configuration: SECRET_KEY: mae3fo4dooJaiteth2emeaNga1biey9ia8FaiQuooYoac8phohee7r ``` -## Testing +## Test Run the test suite: ```bash -tox +task test ``` Generate dummy data for testing (only in DEBUG mode): ```bash -python manage.py create_test_data # fills almost all tables +task app:generate-data # fills almost all tables ``` -Clean all database: +Clean the complete database: ```bash -python manage.py flush +task app:flush-database # or delete db.sqlite3 file in root directory ``` -Other commands for testing: -```bash -python manage.py help -# [ninetofiver] -``` - ## License See [LICENSE](LICENSE) diff --git a/Taskfile.dist.yml b/Taskfile.dist.yml new file mode 100644 index 0000000..363db0b --- /dev/null +++ b/Taskfile.dist.yml @@ -0,0 +1,109 @@ +version: '3' + +env: + COMPOSE: docker compose + +dotenv: ['.env'] # first file takes precedence + +tasks: + default: + cmds: + - "'{{.TASK_EXE}}' --list" + + .env: + desc: Initiate the .env file + cmds: + - cp "{{.TASK}}.dist" "{{.TASK}}" + generates: + - "{{.TASK}}" + status: + - test -f "{{.TASK}}" + silent: true + + prepare: + desc: Prepare your setup + deps: [.env] + + build: + desc: Build your services + deps: [prepare] + cmds: + - | + {{.COMPOSE}} build --no-cache + + start: + desc: Start all services + deps: [prepare] + cmds: + - | + {{.COMPOSE}} up --detach --remove-orphans {{.CLI_ARGS}} + + stop: + desc: Stop all services + deps: [prepare] + cmds: + - | + {{.COMPOSE}} down {{.CLI_ARGS}} + + compose:service:*:exec:*: + desc: Open a terminal inside a service + deps: [prepare] + vars: + SERVICE: '{{index .MATCH 0}}' + COMMAND: '{{index .MATCH 1 | default "sh"}}' + cmds: + - | + {{.COMPOSE}} exec --interactive --tty "{{.SERVICE}}" {{.COMMAND}} && exit 0 + + app:migrate: + desc: Execute the initial migration + deps: [prepare] + cmds: + - | + {{.COMPOSE}} exec --interactive --tty ninetofiver python manage.py migrate + + app:create-superuser: + desc: Create a new superuser (interactively) + deps: [prepare] + cmds: + - | + {{.COMPOSE}} exec --interactive --tty ninetofiver python manage.py createsuperuser + + app:generate-data: + desc: Generate new data (only in DEBUG mode) + deps: [prepare] + preconditions: + - sh: "test '{{.AMOUNT}}' = '' || test '{{.AMOUNT}}' = 'small' || test '{{.AMOUNT}}' = 'normal' || test '{{.AMOUNT}}' = 'extensive'" + msg: "AMOUNT should be one of the following: small, normal, extensive" + cmds: + - | + {{.COMPOSE}} exec --interactive --tty ninetofiver python manage.py create_test_data {{.AMOUNT}} {{.CLI_ARGS}} + + app:flush-database: + desc: Clean the complete database + deps: [prepare] + cmds: + - | + {{.COMPOSE}} exec --interactive --tty ninetofiver python manage.py flush + + app:help: + desc: Check the help from manage.py + deps: [prepare] + cmds: + - | + {{.COMPOSE}} exec --interactive --tty ninetofiver python manage.py help + + test: + desc: Run the test suite + deps: [prepare] + cmds: + - | + {{.COMPOSE}} run --rm web tox + + clean: + desc: Clean up + deps: [prepare] + cmds: + - | + {{.COMPOSE}} down --remove-orphans --volumes {{.CLI_ARGS}} + - rm -f .env diff --git a/compose.dev.yaml b/compose.dev.yaml new file mode 100644 index 0000000..6253cd1 --- /dev/null +++ b/compose.dev.yaml @@ -0,0 +1,31 @@ +services: + + mysql: + command: + [ + 'mysqld', + '--character-set-server=utf8mb4', + '--collation-server=utf8mb4_unicode_ci', + '--wait_timeout=28800', # needed to be able to add test data + '--max_allowed_packet=128M', # needed to be able to add test data + ] + + ninetofiver: + command: | + bash -c " + python manage.py migrate + echo \"from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('${SUPERUSER_USERNAME?}', '${SUPERUSER_EMAIL?}', '${SUPERUSER_PASSWORD?}')\" | python manage.py shell || true + echo \"from oauth2_provider.models import Application; from django.contrib.auth import get_user_model; User = get_user_model(); client = Application.objects.create(user=User.objects.filter(is_staff=True)[0], name='${API_APPLICATION_NAME?}', client_id='${API_APPLICATION_CLIENT_ID?}', client_secret='${API_APPLICATION_CLIENT_SECRET?}', authorization_grant_type=Application.GRANT_PASSWORD)\" | python manage.py shell || true + python manage.py runserver 0.0.0.0:8000 + " + volumes: + - ninetofiver-files:/code + +volumes: + + ninetofiver-files: + driver: local + driver_opts: + o: bind + type: none + device: ${PWD?} diff --git a/compose.fixed-ports.mixin.yaml b/compose.fixed-ports.mixin.yaml new file mode 100644 index 0000000..ecce002 --- /dev/null +++ b/compose.fixed-ports.mixin.yaml @@ -0,0 +1,9 @@ +services: + + mysql: + ports: + - "${MYSQL_EXPOSED_PORT:?}:3306" + + ninetofiver: + ports: + - "${NINETOFIVER_EXPOSED_PORT:?}:8000" diff --git a/compose.traefik.mixin.yaml b/compose.traefik.mixin.yaml new file mode 100644 index 0000000..e677e7d --- /dev/null +++ b/compose.traefik.mixin.yaml @@ -0,0 +1,15 @@ +services: + + ninetofiver: + networks: + traefik: + labels: + - "traefik.enable=true" + - "traefik.docker.network=traefik" + - "traefik.http.routers.${COMPOSE_PROJECT_NAME?}-ninetofiver.rule=Host(`ninetofiver.${PROJECT_DOMAIN_SUFFIX?}`)" + - "traefik.http.services.${COMPOSE_PROJECT_NAME?}-ninetofiver.loadbalancer.server.port=8000" + +networks: + + traefik: + external: true diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..1e4d7e3 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,60 @@ +services: + + ldap: + image: osixia/openldap:1.1.7 + networks: + ninetofiver: + + mysql: + image: mysql:5.7 + environment: + - MYSQL_RANDOM_ROOT_PASSWORD=yes + - MYSQL_DATABASE=${MYSQL_DATABASE?} + - MYSQL_USER=${MYSQL_USER?} + - MYSQL_PASSWORD=${MYSQL_PASSWORD?} + command: + [ + 'mysqld', + '--character-set-server=utf8mb4', + '--collation-server=utf8mb4_unicode_ci', + ] + networks: + ninetofiver: + ports: + - "3306" + volumes: + - mysql-data:/var/lib/mysql + + ninetofiver: + build: . + environment: + - DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE?} + - DJANGO_CONFIGURATION=${DJANGO_CONFIGURATION?} + - CFG_FILE_PATH=${CFG_FILE_PATH?} + - MYSQL_HOST=mysql + - MYSQL_PORT=3306 + - MYSQL_DB=${MYSQL_DATABASE?} + - MYSQL_USER=${MYSQL_USER?} + - MYSQL_PASSWORD=${MYSQL_PASSWORD?} + - PYTHONDONTWRITEBYTECODE=${PYTHONDONTWRITEBYTECODE?} + - PYTHONUNBUFFERED=${PYTHONUNBUFFERED?} + command: | + bash -c " + python manage.py migrate + python manage.py runserver 0.0.0.0:8000 + " + networks: + ninetofiver: + ports: + - "8000" + depends_on: + - ldap + - mysql + +volumes: + + mysql-data: + +networks: + + ninetofiver: diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index dd5a037..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,15 +0,0 @@ -version: '3.8' - -services: - ldap: - image: osixia/openldap:1.1.7 - web: - container_name: 925r-web - build: . - command: bash -c "python manage.py runserver 0.0.0.0:8000" - volumes: - - .:/code - ports: - - "8888:8000" - depends_on: - - ldap diff --git a/scripts/docker/Dockerfile b/scripts/docker/Dockerfile deleted file mode 100644 index f0b0f1d..0000000 --- a/scripts/docker/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM python:3.6 -ENV PYTHONUNBUFFERED 1 -RUN mkdir /code -RUN apt-get update -RUN apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev -WORKDIR /code -ADD requirements.txt /code/ -RUN pip install -r requirements.txt -ADD . /code/ diff --git a/scripts/docker/docker-compose.yml b/scripts/docker/docker-compose.yml deleted file mode 100644 index 501a0f4..0000000 --- a/scripts/docker/docker-compose.yml +++ /dev/null @@ -1,15 +0,0 @@ -version: '2' -services: - ldap: - image: osixia/openldap:1.1.7 - web: - build: - context: ../../. - dockerfile: ./scripts/docker/Dockerfile - command: python manage.py runserver 0.0.0.0:8000 - volumes: - - ../../.:/code - ports: - - "8888:8000" - depends_on: - - ldap From 6819f171a2dbfffd8e00ba12db648ed92d6b0a9d Mon Sep 17 00:00:00 2001 From: Bart Reunes Date: Tue, 27 Aug 2024 12:39:14 +0200 Subject: [PATCH 02/12] leave the validation to manage.py --- Taskfile.dist.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Taskfile.dist.yml b/Taskfile.dist.yml index 363db0b..0f8fe48 100644 --- a/Taskfile.dist.yml +++ b/Taskfile.dist.yml @@ -72,9 +72,6 @@ tasks: app:generate-data: desc: Generate new data (only in DEBUG mode) deps: [prepare] - preconditions: - - sh: "test '{{.AMOUNT}}' = '' || test '{{.AMOUNT}}' = 'small' || test '{{.AMOUNT}}' = 'normal' || test '{{.AMOUNT}}' = 'extensive'" - msg: "AMOUNT should be one of the following: small, normal, extensive" cmds: - | {{.COMPOSE}} exec --interactive --tty ninetofiver python manage.py create_test_data {{.AMOUNT}} {{.CLI_ARGS}} From 8eb43e3e03b4c5e7b51cfab1bbbd2e794972f08a Mon Sep 17 00:00:00 2001 From: Bart Reunes Date: Tue, 27 Aug 2024 12:53:21 +0200 Subject: [PATCH 03/12] pass commands to manage.py --- README.md | 23 +++++++++++++---------- Taskfile.dist.yml | 34 +++------------------------------- 2 files changed, 16 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index c7466af..a56c438 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,9 @@ If you want to walk the manual path, check the files `.env.dist`, `Taskfile.dist 1. Run `task prepare` and check if the values in the .env file are correct for your environment 2. Run `task start` to start the application at `http://localhost:8000`. -3. Run `task app:migrate` to create the models -4. Run `task app:create-superuser` to create an admin user (interactively) -5. Run `task app:generate-data` to fill the database with test data (see below for more information) +3. Run `task app:manage -- migrate` to create the models +4. Run `task app:manage -- createsuperuser` to create an admin user (interactively) +5. Run `task app:manage -- create_test_data` to fill the database with test data (see below for more information) For more tasks, check `task --list-all`. @@ -42,13 +42,11 @@ Now you can log in to YaYata with the root account, or you can create a new test ### Add example data -You can run `task app:generate-data` to fill the database with test data. -You can specify the amount of data to be created by one optional argument `AMOUNT`. Possible values are +You can run `task app:manage -- create_test_data` to fill the database with test data. +You can specify the amount of data to be created by one optional argument `amount`. Possible values are (`small`, `normal` or `extensive`) with `normal` being the default. -It can run a few minutes depending on resources. For this reason there is a `-t` option, so you -can see what is happening at the moment. ```shell -task app:generate-data AMOUNT=extensive -- -t +task app:manage -- create_test_data extensive ``` ## Configuration @@ -82,14 +80,19 @@ task test Generate dummy data for testing (only in DEBUG mode): ```bash -task app:generate-data # fills almost all tables +task task app:manage -- create_test_data # fills almost all tables ``` Clean the complete database: ```bash -task app:flush-database +task app:manage -- flush # or delete db.sqlite3 file in root directory +``` + +Other possible commands can be found by running: +```bash +task app:manage -- help ``` ## License diff --git a/Taskfile.dist.yml b/Taskfile.dist.yml index 0f8fe48..0daa19a 100644 --- a/Taskfile.dist.yml +++ b/Taskfile.dist.yml @@ -55,40 +55,12 @@ tasks: - | {{.COMPOSE}} exec --interactive --tty "{{.SERVICE}}" {{.COMMAND}} && exit 0 - app:migrate: - desc: Execute the initial migration + app:manage: + desc: Run a command against manage.py deps: [prepare] cmds: - | - {{.COMPOSE}} exec --interactive --tty ninetofiver python manage.py migrate - - app:create-superuser: - desc: Create a new superuser (interactively) - deps: [prepare] - cmds: - - | - {{.COMPOSE}} exec --interactive --tty ninetofiver python manage.py createsuperuser - - app:generate-data: - desc: Generate new data (only in DEBUG mode) - deps: [prepare] - cmds: - - | - {{.COMPOSE}} exec --interactive --tty ninetofiver python manage.py create_test_data {{.AMOUNT}} {{.CLI_ARGS}} - - app:flush-database: - desc: Clean the complete database - deps: [prepare] - cmds: - - | - {{.COMPOSE}} exec --interactive --tty ninetofiver python manage.py flush - - app:help: - desc: Check the help from manage.py - deps: [prepare] - cmds: - - | - {{.COMPOSE}} exec --interactive --tty ninetofiver python manage.py help + {{.COMPOSE}} exec --interactive --tty ninetofiver python manage.py {{.CLI_ARGS}} test: desc: Run the test suite From 3a789fbd1ce9e44fb8161db71998cabf362d688a Mon Sep 17 00:00:00 2001 From: Bart Reunes Date: Tue, 27 Aug 2024 16:30:01 +0200 Subject: [PATCH 04/12] move mysql to the dev setup with a version dependant volume --- .env.dist | 1 + compose.dev.yaml | 38 ++++++++++++++++++++++++++++++++++++++ compose.yaml | 34 ---------------------------------- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/.env.dist b/.env.dist index 9c9f228..f8ebe7d 100644 --- a/.env.dist +++ b/.env.dist @@ -9,6 +9,7 @@ COMPOSE_PATH_SEPARATOR=, MYSQL_EXPOSED_PORT=3306 NINETOFIVER_EXPOSED_PORT=8888 +MYSQL_VERSION=5.7 MYSQL_DATABASE=ninetofiver-database MYSQL_USER=ninetofiver-user MYSQL_PASSWORD=ninetofiver-password diff --git a/compose.dev.yaml b/compose.dev.yaml index 6253cd1..2903b26 100644 --- a/compose.dev.yaml +++ b/compose.dev.yaml @@ -1,6 +1,17 @@ services: + ldap: + image: osixia/openldap:1.1.7 + networks: + ninetofiver: + mysql: + image: mysql:${MYSQL_VERSION?} + environment: + - MYSQL_ROOT_PASSWORD=random-password + - MYSQL_DATABASE=${MYSQL_DATABASE?} + - MYSQL_USER=${MYSQL_USER?} + - MYSQL_PASSWORD=${MYSQL_PASSWORD?} command: [ 'mysqld', @@ -9,8 +20,23 @@ services: '--wait_timeout=28800', # needed to be able to add test data '--max_allowed_packet=128M', # needed to be able to add test data ] + networks: + ninetofiver: + ports: + - "3306" + volumes: + - "mysql-data:/var/lib/mysql" + healthcheck: + test: [ "CMD-SHELL", "MYSQL_PWD=$${MYSQL_PASSWORD} mysqladmin --host=127.0.0.1 --user=$${MYSQL_USER} ping" ] + interval: 5s + timeout: 3s + retries: 2 + start_period: 0s ninetofiver: + environment: + - MYSQL_HOST=mysql + - MYSQL_PORT=3306 command: | bash -c " python manage.py migrate @@ -20,12 +46,24 @@ services: " volumes: - ninetofiver-files:/code + depends_on: + ldap: + condition: service_started + mysql: + condition: service_healthy volumes: + mysql-data: + name: "mysql-${MYSQL_VERSION?}-data" + ninetofiver-files: driver: local driver_opts: o: bind type: none device: ${PWD?} + +networks: + + ninetofiver: diff --git a/compose.yaml b/compose.yaml index 1e4d7e3..fd501dc 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,38 +1,11 @@ services: - ldap: - image: osixia/openldap:1.1.7 - networks: - ninetofiver: - - mysql: - image: mysql:5.7 - environment: - - MYSQL_RANDOM_ROOT_PASSWORD=yes - - MYSQL_DATABASE=${MYSQL_DATABASE?} - - MYSQL_USER=${MYSQL_USER?} - - MYSQL_PASSWORD=${MYSQL_PASSWORD?} - command: - [ - 'mysqld', - '--character-set-server=utf8mb4', - '--collation-server=utf8mb4_unicode_ci', - ] - networks: - ninetofiver: - ports: - - "3306" - volumes: - - mysql-data:/var/lib/mysql - ninetofiver: build: . environment: - DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE?} - DJANGO_CONFIGURATION=${DJANGO_CONFIGURATION?} - CFG_FILE_PATH=${CFG_FILE_PATH?} - - MYSQL_HOST=mysql - - MYSQL_PORT=3306 - MYSQL_DB=${MYSQL_DATABASE?} - MYSQL_USER=${MYSQL_USER?} - MYSQL_PASSWORD=${MYSQL_PASSWORD?} @@ -47,13 +20,6 @@ services: ninetofiver: ports: - "8000" - depends_on: - - ldap - - mysql - -volumes: - - mysql-data: networks: From 26421c1c2a3ac79b0c091d2e15a7ff34354870be Mon Sep 17 00:00:00 2001 From: Bart Reunes Date: Mon, 16 Sep 2024 16:45:08 +0200 Subject: [PATCH 05/12] use the correct path to add the application files --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 61abdba..51cee89 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,4 +14,4 @@ RUN set -ex && pip install -r requirements.txt FROM builder AS final WORKDIR /code -COPY . /app/ +COPY . . From c3c2bbfb8ed59fb2d168c1efaba99e9da26141f9 Mon Sep 17 00:00:00 2001 From: Bart Reunes Date: Mon, 16 Sep 2024 23:12:10 +0200 Subject: [PATCH 06/12] use fixed ports by default --- .env.dist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.dist b/.env.dist index f8ebe7d..25a2b01 100644 --- a/.env.dist +++ b/.env.dist @@ -2,8 +2,8 @@ PROJECT_DOMAIN_SUFFIX=localhost COMPOSE_PROJECT_NAME=ninetofiver -COMPOSE_FILE=compose.yaml,compose.dev.yaml,compose.traefik.mixin.yaml -#COMPOSE_FILE=compose.yaml,compose.dev.yaml,compose.fixed-ports.mixin.yaml +#COMPOSE_FILE=compose.yaml,compose.dev.yaml,compose.traefik.mixin.yaml +COMPOSE_FILE=compose.yaml,compose.dev.yaml,compose.fixed-ports.mixin.yaml COMPOSE_PATH_SEPARATOR=, MYSQL_EXPOSED_PORT=3306 From 476d90f5d5c590a7bfc52bb784e9089fe7010d86 Mon Sep 17 00:00:00 2001 From: Bart Reunes Date: Mon, 16 Sep 2024 23:20:01 +0200 Subject: [PATCH 07/12] use the same fixed port as the application uses by default --- .env.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.dist b/.env.dist index 25a2b01..0ccf6c2 100644 --- a/.env.dist +++ b/.env.dist @@ -7,7 +7,7 @@ COMPOSE_FILE=compose.yaml,compose.dev.yaml,compose.fixed-ports.mixin.yaml COMPOSE_PATH_SEPARATOR=, MYSQL_EXPOSED_PORT=3306 -NINETOFIVER_EXPOSED_PORT=8888 +NINETOFIVER_EXPOSED_PORT=8000 MYSQL_VERSION=5.7 MYSQL_DATABASE=ninetofiver-database From 4019d7221b087d8b56cf72c79217450d1a86fe2e Mon Sep 17 00:00:00 2001 From: Bart Reunes Date: Tue, 17 Sep 2024 20:42:53 +0200 Subject: [PATCH 08/12] keep mysql 5.7 container running smooth on systems with nofile unlimited --- compose.dev.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compose.dev.yaml b/compose.dev.yaml index 2903b26..f284956 100644 --- a/compose.dev.yaml +++ b/compose.dev.yaml @@ -20,6 +20,12 @@ services: '--wait_timeout=28800', # needed to be able to add test data '--max_allowed_packet=128M', # needed to be able to add test data ] + # Fix memory leak issue on some systems when LimitCORE=infinity (containerd) + # @see https://github.com/docker-library/mysql/issues/873#issuecomment-1909948195 + ulimits: + nofile: + soft: 1048576 + hard: 1048576 networks: ninetofiver: ports: From 4c52eb525f52d2759fab372f4fa54cdb5f03e1cf Mon Sep 17 00:00:00 2001 From: Bart Reunes Date: Wed, 18 Sep 2024 19:44:57 +0200 Subject: [PATCH 09/12] fix default task --- Taskfile.dist.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Taskfile.dist.yml b/Taskfile.dist.yml index 0daa19a..04701e3 100644 --- a/Taskfile.dist.yml +++ b/Taskfile.dist.yml @@ -8,7 +8,7 @@ dotenv: ['.env'] # first file takes precedence tasks: default: cmds: - - "'{{.TASK_EXE}}' --list" + - "'{{.TASK_EXE}}' --list-all" .env: desc: Initiate the .env file From 84e8b7e2426e612837019466e226aa12c18bb68c Mon Sep 17 00:00:00 2001 From: Bart Reunes Date: Thu, 19 Sep 2024 20:44:08 +0200 Subject: [PATCH 10/12] make the root password configurable --- .env.dist | 1 + compose.dev.yaml | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.env.dist b/.env.dist index 0ccf6c2..7abe6fa 100644 --- a/.env.dist +++ b/.env.dist @@ -10,6 +10,7 @@ MYSQL_EXPOSED_PORT=3306 NINETOFIVER_EXPOSED_PORT=8000 MYSQL_VERSION=5.7 +MYSQL_ROOT_PASSWORD=root MYSQL_DATABASE=ninetofiver-database MYSQL_USER=ninetofiver-user MYSQL_PASSWORD=ninetofiver-password diff --git a/compose.dev.yaml b/compose.dev.yaml index f284956..928d91a 100644 --- a/compose.dev.yaml +++ b/compose.dev.yaml @@ -8,7 +8,7 @@ services: mysql: image: mysql:${MYSQL_VERSION?} environment: - - MYSQL_ROOT_PASSWORD=random-password + - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD?} - MYSQL_DATABASE=${MYSQL_DATABASE?} - MYSQL_USER=${MYSQL_USER?} - MYSQL_PASSWORD=${MYSQL_PASSWORD?} @@ -43,6 +43,9 @@ services: environment: - MYSQL_HOST=mysql - MYSQL_PORT=3306 + - DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE?} + - DJANGO_CONFIGURATION=${DJANGO_CONFIGURATION?} + - CFG_FILE_PATH=${CFG_FILE_PATH?} command: | bash -c " python manage.py migrate From dbaeeeda609af34af5c57a663aa4491eb29f21d9 Mon Sep 17 00:00:00 2001 From: Bart Reunes Date: Tue, 24 Sep 2024 22:05:28 +0200 Subject: [PATCH 11/12] default to traefik ports --- .env.dist | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.env.dist b/.env.dist index 7abe6fa..216d8bb 100644 --- a/.env.dist +++ b/.env.dist @@ -2,10 +2,11 @@ PROJECT_DOMAIN_SUFFIX=localhost COMPOSE_PROJECT_NAME=ninetofiver -#COMPOSE_FILE=compose.yaml,compose.dev.yaml,compose.traefik.mixin.yaml -COMPOSE_FILE=compose.yaml,compose.dev.yaml,compose.fixed-ports.mixin.yaml +COMPOSE_FILE=compose.yaml,compose.dev.yaml,compose.traefik.mixin.yaml +#COMPOSE_FILE=compose.yaml,compose.dev.yaml,compose.fixed-ports.mixin.yaml COMPOSE_PATH_SEPARATOR=, +# Only needed when using fixed ports MYSQL_EXPOSED_PORT=3306 NINETOFIVER_EXPOSED_PORT=8000 From 48e20079be9d0d4983e9c692ac90599570ae5903 Mon Sep 17 00:00:00 2001 From: Bart Reunes Date: Wed, 25 Sep 2024 13:54:24 +0200 Subject: [PATCH 12/12] default to fixed ports, leave the traefik setup as an advanced setting --- .env.dist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.dist b/.env.dist index 216d8bb..20ff1f2 100644 --- a/.env.dist +++ b/.env.dist @@ -2,8 +2,8 @@ PROJECT_DOMAIN_SUFFIX=localhost COMPOSE_PROJECT_NAME=ninetofiver -COMPOSE_FILE=compose.yaml,compose.dev.yaml,compose.traefik.mixin.yaml -#COMPOSE_FILE=compose.yaml,compose.dev.yaml,compose.fixed-ports.mixin.yaml +#COMPOSE_FILE=compose.yaml,compose.dev.yaml,compose.traefik.mixin.yaml +COMPOSE_FILE=compose.yaml,compose.dev.yaml,compose.fixed-ports.mixin.yaml COMPOSE_PATH_SEPARATOR=, # Only needed when using fixed ports