From 24a99557d7ac26b1944da9065c553ad583d0887a Mon Sep 17 00:00:00 2001 From: Valentin Date: Fri, 3 May 2024 19:02:25 +0200 Subject: [PATCH] first commit --- .env.example | 6 ++++++ .gitignore | 4 ++++ README.md | 43 ++++++++++++++++++++++++++++++++++++ docker-compose.yml | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 README.md create mode 100644 docker-compose.yml diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..dc2d9a0 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +PROJECT_NAME= +KEY= +SECRET= +ADMIN_EMAIL= +ADMIN_PASSWORD= +PORT= diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b61dc98 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +data/ +uploads/ +*.sql +.env diff --git a/README.md b/README.md new file mode 100644 index 0000000..c865f91 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# Directus on Mariadb running with Docker for local development + +## Run + +Create the `.env` file following `.env.example`. + +To generate the `SECRET` and `KEY` + +`head -c 16 /dev/urandom | od -An -tx1 | tr -d ' \n'` + +`docker-compose up -d` + +## On first launch, create the DB + +A few troubles to run Directus with Docker on MariaDB instead of Postgresql, so we have to create the DB manually on the first launch. + +`docker exec -it PROJECTNAME_Directus_DB /bin/bash` +`mariadb -u root` +`CREATE DATABASE directus;` +`GRANT ALL PRIVILEGES ON directus.* TO 'directus'@'%';` +`FLUSH PRIVILEGES;` +`exit;` +`exit` + +## Import an exported DB + +`docker cp db_export.sql PROJECTNAME_Directus_DB:/root/` +`docker exec -it PROJECTNAME_Directus_DB /bin/bash` +`mariadb -u root` +`drop database directus;` +`create database directus;` +`exit;` +`mariadb -uroot directus < /root/db_export.sql` +`exit` +`docker exec -it PROJECTNAME_Directus_DB /bin/sh` +`npx directus database migrate:latest` + +## Export data model + +`docker exec -it PROJECTNAME_Directus /bin/sh` +`npx directus schema snapshot ./snapshot.yaml` +`exit` +`docker cp PROJECTNAME_Directus:/directus/snapshot.yaml .` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..00c6100 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,54 @@ +version: "3" +services: + database: + container_name: ${PROJECT_NAME}_Directus_DB + image: mariadb:10 + volumes: + - ./data:/var/lib/mysql + environment: + - MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=1 + - MARIADB_USER=directus + - MARIADB_PASSWORD=directus + - MARIADB_DB=directus + + cache: + container_name: ${PROJECT_NAME}_Directus_Cache + image: redis:6 + + directus: + container_name: ${PROJECT_NAME}_Directus + image: directus/directus:latest + restart: unless-stopped + ports: + - ${PORT}:8055 + volumes: + - ./uploads:/directus/uploads + depends_on: + - cache + - database + environment: + KEY: ${SECRET} + SECRET: ${KEY} + + LOG_LEVEL: 'debug' + + DB_CLIENT: "mysql" + DB_HOST: "database" + DB_PORT: "3306" + DB_DATABASE: "directus" + DB_USER: "directus" + DB_PASSWORD: "directus" + + CACHE_ENABLED: "true" + CACHE_STORE: "redis" + REDIS: "redis://cache:6379" + + ADMIN_EMAIL: ${ADMIN_EMAIL} + ADMIN_PASSWORD: ${ADMIN_PASSWORD} + + PUBLIC_URL: http://localhost:${PORT} + + CORS_ENABLED: true + CORS_ORIGIN: true + + CACHE_AUTO_PURGE: true