From 2afdd28c0f4e047bfb3c53471e7aee8a6d843e2f Mon Sep 17 00:00:00 2001 From: Dave Poon Date: Sat, 16 Dec 2023 17:57:15 +1100 Subject: [PATCH] template created --- .github/dependabot.yml | 14 +++++++ .gitignore | 5 +++ Dockerfile | 15 ++++++++ README.md | 70 ++++++++++++++++++++++++++++++++++ config.js | 26 +++++++++++++ docker-compose.yml | 51 +++++++++++++++++++++++++ extensions/displays/.gitkeep | 0 extensions/endpoints/.gitkeep | 0 extensions/hooks/.gitkeep | 0 extensions/interfaces/.gitkeep | 0 extensions/layouts/.gitkeep | 0 extensions/modules/.gitkeep | 0 extensions/panels/.gitkeep | 0 railway.json | 21 ++++++++++ 14 files changed, 202 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 config.js create mode 100644 docker-compose.yml create mode 100644 extensions/displays/.gitkeep create mode 100644 extensions/endpoints/.gitkeep create mode 100644 extensions/hooks/.gitkeep create mode 100644 extensions/interfaces/.gitkeep create mode 100644 extensions/layouts/.gitkeep create mode 100644 extensions/modules/.gitkeep create mode 100644 extensions/panels/.gitkeep create mode 100644 railway.json diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..42c9350 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,14 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "npm" + directory: "/" + schedule: + interval: "daily" + # Always increase the version requirement + # to match the new version. + versioning-strategy: increase diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c77e317 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/node_modules +.env +data +database +uploads \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4a15e8a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +# Explicitly specify a Directus version to use on Railway +FROM directus/directus:10.8.2 + +USER root +RUN corepack enable +USER node + +# Installing contributed/custom extensions through npm on Railway +RUN pnpm install directus-extension-computed-interface && pnpm install directus-extension-upsert && pnpm install directus-extension-wpslug-interface && pnpm install pg + +# Uncomment this if you would like to install contributed/custom extensions through the extensions folder on Railway +#COPY ./extensions /directus/extensions + +COPY ./config.js /directus/config.js + diff --git a/README.md b/README.md new file mode 100644 index 0000000..c579ee4 --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +--- +title: Directus (Docker + extensions + websocket) + PostGIS (Docker & TCP) + S3 +description: A one-click-install Directus instance with PostGIS and S3 for persistent storage. +tags: + - Directus + - Typescript + - Vue + - Websocket + - CMS + - Data Platform + - PostgreSQL + - PostGIS + - Railway +--- + +# Directus railway template + +This example runs a [Directus](https://directus.io/) instance with minimal config using PostGIS. + +[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/zAZIod?referralCode=OYCuBb) + +## ✨ Features + +- Directus config is pre-configured +- Install Directus using Docker +- Directus extensions and websocket are pre-configured +- Directus version can be updated through Dockerfile +- Directus extensions can be updated and loaded through Dockerfile +- PostGIS config is pre-configured +- SSL certificates is pre-configured using the self-signed Snakeoil certificate for PostGIS +- Railway Database View is pre-configured +- Install PostGIS instead of Postgre as Directus recommended for supporting GIS features +- S3 for persistent storage +- docker-compose.yml is added for local development +- The communication from Directus to the database is accomplished through the private network, saving its users from egress fees. This reduces the users' exposure to unnecessary egress fees. + +## 💁‍♀️ How to use + +- Click the Deploy on Railway button +- Let railway deploy your service, most of the configurations have been preset, but feel free to tweak them as you like before deployment. +- Login in the admin panel using the defined ADMIN_EMAIL and ADMIN_PASSWORD. +- Use of S3 is a must in this template. +- For local development, just run `docker compose up` or run the same command twice (Sometimes, the Directus container starts before other containers are ready, resulting in a failure upon startup). + + +## 💁‍♀️ Example screenshots + +**Directus extensions** + +![Directus extensions!](https://zyugzloemocjcxmspsso.supabase.co/storage/v1/object/public/static-assets/extensions.png?t=2023-12-15T10%3A32%3A35.939Z "Directus extensions enabled") + +**Directus S3 image upload** + +![Directus S3 image upload!](https://zyugzloemocjcxmspsso.supabase.co/storage/v1/object/public/static-assets/s3-file-upload.png "Directus S3 image upload") + +**Directus S3 storage** + +![Directus S3 storage!](https://zyugzloemocjcxmspsso.supabase.co/storage/v1/object/public/static-assets/s3-storage.png "Directus S3 storage") + +**Railway Database View for Postgis** + +![Railway Database View for Postgis!](https://zyugzloemocjcxmspsso.supabase.co/storage/v1/object/public/static-assets/database-view.png "Railway Database View for Postgis") + +## 📝 Notes + +- This is a minimal one-click-deploy solution to Directus, see [Directus docs](https://docs.directus.io/getting-started/introduction.html) to config it to your needs. + +## Credit + +- Inspired and learnt from [https://github.com/freekrai/directus-railway](https://github.com/freekrai/directus-railway) and [https://railway.app/template/postgis](https://railway.app/template/postgis) diff --git a/config.js b/config.js new file mode 100644 index 0000000..40267ac --- /dev/null +++ b/config.js @@ -0,0 +1,26 @@ +export default function (env) { + return { + // Railway inputs + ADMIN_EMAIL: env.ADMIN_EMAIL, + ADMIN_PASSWORD: env.ADMIN_PASSWORD, + KEY: env.KEY, + SECRET: env.SECRET, + + // https://docs.railway.app/guides/public-networking#railway-provided-port + PORT: env.PORT, + + PUBLIC_URL: `http://0.0.0.0:${env.PORT}`, + + // Database & storage variables for connecting to PostGIS and S3/local storage + DB_CLIENT: 'pg', + DB_CONNECTION_STRING: env.DB_CONNECTION_STRING, + STORAGE_LOCATIONS: env.STORAGE_LOCATIONS, + STORAGE_S3_DRIVER: env.STORAGE_S3_DRIVER, + STORAGE_S3_KEY: env.STORAGE_S3_KEY, + STORAGE_S3_SECRET: env.STORAGE_S3_SECRET, + STORAGE_S3_REGION: env.STORAGE_S3_REGION, + STORAGE_S3_BUCKET: env.STORAGE_S3_BUCKET, + STORAGE_S3_ENDPOINT: env.STORAGE_S3_ENDPOINT, + WEBSOCKETS_ENABLED: env.WEBSOCKETS_ENABLED, + }; +}; \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..067bbbd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,51 @@ +# For local development, you can use the following docker-compose.yml file: +version: "3" +services: + database: + image: postgis/postgis:13-master + # Required when running on platform other than amd64, like Apple M1/M2: + platform: linux/amd64 + volumes: + - ./data/database:/var/lib/postgresql/data + environment: + POSTGRES_USER: "directus" + POSTGRES_PASSWORD: "directus" + POSTGRES_DB: "directus" + + cache: + image: redis:6 + + directus: + image: directus/directus:10.8.2 + ports: + - 8055:8055 + volumes: + - ./database:/directus/database + - ./uploads:/directus/uploads + - ./extensions:/directus/extensions + depends_on: + - cache + - database + environment: + KEY: "255d861b-5ea1-5996-9aa3-922530ec40b1" + SECRET: "6116487b-cda1-52c2-b5b5-c8022c45e263" + + DB_CLIENT: "pg" + DB_HOST: "database" + DB_PORT: "5432" + DB_DATABASE: "directus" + DB_USER: "directus" + DB_PASSWORD: "directus" + + CACHE_ENABLED: "true" + CACHE_STORE: "redis" + REDIS: "redis://cache:6379" + + ADMIN_EMAIL: "admin@example.com" + ADMIN_PASSWORD: "d1r3ctu5" + + EXTENSIONS_AUTO_RELOAD: "true" + + # Make sure to set this in production + # (see https://docs.directus.io/self-hosted/config-options#general) + # PUBLIC_URL: "https://directus.example.com" \ No newline at end of file diff --git a/extensions/displays/.gitkeep b/extensions/displays/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/extensions/endpoints/.gitkeep b/extensions/endpoints/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/extensions/hooks/.gitkeep b/extensions/hooks/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/extensions/interfaces/.gitkeep b/extensions/interfaces/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/extensions/layouts/.gitkeep b/extensions/layouts/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/extensions/modules/.gitkeep b/extensions/modules/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/extensions/panels/.gitkeep b/extensions/panels/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/railway.json b/railway.json new file mode 100644 index 0000000..03cc968 --- /dev/null +++ b/railway.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://schema.up.railway.app/railway.schema.json", + "build": { + "builder": "NIXPACKS", + "nixpacksPlan": { + "phases": { + "setup": { + "nixPkgs": [ + "...", + "gcc", + "python311" + ], + "aptPkgs": [ + "build-essential", + "glibc-source" + ] + } + } + } + } +} \ No newline at end of file