diff --git a/samples/directus-postgres/README.md b/samples/directus-postgres/README.md new file mode 100644 index 00000000..e4de3296 --- /dev/null +++ b/samples/directus-postgres/README.md @@ -0,0 +1,47 @@ +# Directus + PostgreSQL + +This sample project demonstrates how to deploy Directus with Defang and connect it to a PostgreSQL database. We also demonstrate how to run a PostgreSQL container during development and how to switch over to a managed PostgreSQL service like Neon in production. If you want to get a compatible database ready to go really quickly for free, [Neon](https://neon.tech/) is a quick and easy way to go. + +## Prerequisites + +1. Download [Defang CLI](https://github.com/DefangLabs/defang) +2. (Optional) If you are using [Defang BYOC](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) authenticated with your AWS account +3. (Optional - for local development) [Docker CLI](https://docs.docker.com/engine/install/) + +### Editing the database/permissions etc. + +If you want to edit the database, permissions, or any other Directus settings such that you can deploy them to production, you should make those changes in the Directus admin interface. Any changes you make in the admin interface will be saved to the database. + +## Deploying + +1. Open the terminal and type `defang login` +2. Add your connection string to the `DB_CONNECTION_STRING` on `compose.yaml` (which should be in the format `postgres://username:password@host:port/dbname`) +3. Setup all the env variables by doing the following + + - `defang config set SECRET` + - `defang config set ADMIN_EMAIL` + - `defang config set ADMIN_PASSWORD` + - `defang config set DB_CONNECTION_STRING` + +4. Type `defang compose up` in the CLI. 5. Your app will be running within a few minutes. + +## Development + +`For development, we use a PostgreSQL container. The PostgreSQL container is defined in the`compose.dev.yaml`file. The Directus container is defined in the`docker-compose.yaml`file, with some overrides in the`compose.dev.yaml` file so it can correctly connect to the development database container. + +To start the development environment, run +`docker-compose -f compose.dev.yaml up -d` + +This will start the PostgreSQL container and the Directus container. The Directus console will be available at `http://localhost:8055` with the admin email `admin@example.com` and password `d1r3ctu5`. (you can change these as you may) + +**Note:** _If you want to make changes to your database, permissions, etc., you should use the Directus console to make those changes._ + +--- + +Title: Directus + PostgreSQL + +Short Description: A sample project demonstrating how to deploy Directus with Defang and connect it to a PostgreSQL database + +Tags: directus, cms, postgres, database + +Languages: sql, cms diff --git a/samples/directus-postgres/compose.dev.yaml b/samples/directus-postgres/compose.dev.yaml new file mode 100644 index 00000000..b57a5378 --- /dev/null +++ b/samples/directus-postgres/compose.dev.yaml @@ -0,0 +1,30 @@ +version: "3.9" +name: directus-postgres +services: + directus: + extends: + file: compose.yaml + service: directus + environment: + - SECRET=a-very-secret-key + - ADMIN_EMAIL=admin@example.com + - ADMIN_PASSWORD=password + - DB_CONNECTION_STRING=postgres://directus:directus@postgres:5432/directus + volumes: + - /directus/uploads + depends_on: + - postgres + - redis + - minio + + postgres: + image: postgres:16 + environment: + POSTGRES_USER: directus + POSTGRES_PASSWORD: directus + POSTGRES_DB: directus + volumes: + - postgres_data:/var/lib/postgresql/data + +volumes: + postgres_data: \ No newline at end of file diff --git a/samples/directus-postgres/compose.yaml b/samples/directus-postgres/compose.yaml new file mode 100644 index 00000000..8f36431a --- /dev/null +++ b/samples/directus-postgres/compose.yaml @@ -0,0 +1,42 @@ +version: "3.9" +name: directus-postgres +services: + directus: + image: directus/directus:10.11.2 + ports: + - target: 8055 + mode: ingress + published: 8055 + deploy: + replicas: 2 + resources: + reservations: + cpus: "0.5" + memory: 512M + environment: + - SECRET + - ADMIN_EMAIL + - ADMIN_PASSWORD + - WEBSOCKETS_ENABLED=true + + # Database + - DB_CLIENT=pg + - DB_CONNECTION_STRING + + # Redis + - REDIS + - CACHE_STORE=redis + - CACHE_ENABLED=true + - CACHE_AUTO_PURGE=true + - RATE_LIMITER_STORE=redis + - SYNCHRONIZATION_STORE=redis + + # Storage + - STORAGE_LOCATIONS=s3 + - STORAGE_S3_DRIVER=s3 + - STORAGE_S3_KEY + - STORAGE_S3_SECRET + - STORAGE_S3_BUCKET + - STORAGE_S3_REGION + - STORAGE_S3_ENDPOINT + diff --git a/samples/sailsjs-postgres/compose.yaml b/samples/sailsjs-postgres/compose.yaml index 27ae48c9..dad38d10 100644 --- a/samples/sailsjs-postgres/compose.yaml +++ b/samples/sailsjs-postgres/compose.yaml @@ -8,8 +8,8 @@ services: published: 1337 mode: ingress environment: - DATABASE_URL: "postgresql://tasklistdb_owner:zPl3KMOmq5jy@ep-autumn-wind-a5fvcs0v.us-east-2.aws.neon.tech/tasklistdb?sslmode=require" - SESSION_SECRET: "91cc809104bca25c3dd96590124ee598" + - DATABASE_URL + - SESSION_SECRET command: ["sails", "lift", "--prod"] networks: - app-network