Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Directus to 10.8.2, add S3 storage options #474

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
130 changes: 91 additions & 39 deletions templates/directus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,78 @@ export function generate(input: Input): Output {
const services: Services = [];
const appKey = randomString(48);
const appSecret = randomString(48);
const adminPassword = input.adminPassword || randomPassword();
const databasePassword = randomPassword();
const redisPassword = randomPassword();
const adminPassword = input.adminPassword ?? randomPassword();
const logLevel = input.logLevel || "info";

const appEnv = {
general: {
KEY: appKey,
SECRET: appSecret,
PUBLIC_URL: "/",
LOG_LEVEL: logLevel,
},
admin: {
ADMIN_EMAIL: input.adminEmail,
ADMIN_PASSWORD: adminPassword,
},
db: {
DB_CLIENT: input.databaseType,
DB_HOST: `$(PROJECT_NAME)_${input.databaseServiceName}`,
DB_PORT: input.databaseType === "postgres" ? "5432" : "3306",
DB_DATABASE: "$(PROJECT_NAME)",
DB_USER: input.databaseType === "postgres" ? "postgres" : "mysql",
DB_PASSWORD: databasePassword,
},
storage: {
STORAGE_LOCATIONS: input.storageLocation,
},
cache: {
CACHE_ENABLED: "true",
CACHE_STORE: input.redisServiceName ? "redis" : "memory",
},
cors: {
CORS_ENABLED: "true",
CORS_ORIGIN: "true",
},
};

if (input.storageLocation === "s3") {
appEnv.storage = {
...appEnv.storage,
...{
STORAGE_S3_DRIVER: `s3`,
STORAGE_S3_KEY: input.storageS3Key,
STORAGE_S3_SECRET: input.storageS3Secret,
STORAGE_S3_BUCKET: input.storageS3Bucket,
STORAGE_S3_REGION: input.storageS3Region,
STORAGE_S3_ENDPOINT: input.storageS3Endpoint,
},
};
}

if (input.redisServiceName) {
appEnv.cache = {
...appEnv.cache,
...{
REDIS: `redis://default:${redisPassword}@$(PROJECT_NAME)_${input.redisServiceName}:6379`,
},
};
}

services.push({
type: "app",
data: {
projectName: input.projectName,
serviceName: input.appServiceName,
env: [
`KEY=${appKey}`,
`SECRET=${appSecret}`,
`DB_CLIENT=${input.databaseType}`,
`DB_HOST=$(PROJECT_NAME)_${input.databaseServiceName}`,
`DB_PORT=${input.databaseType === "postgres" ? "5432" : "3306"}`,
`DB_DATABASE=$(PROJECT_NAME)`,
`DB_USER=${input.databaseType === "postgres" ? "postgres" : "mysql"}`,
`DB_PASSWORD=${databasePassword}`,
`CACHE_ENABLED=true`,
`CACHE_STORE=redis`,
`CACHE_REDIS=redis://default:${redisPassword}@$(PROJECT_NAME)_${input.redisServiceName}:6379`,
`ADMIN_EMAIL=${input.adminEmail}`,
`ADMIN_PASSWORD=${adminPassword}`,
].join("\n"),
env: Object.values(appEnv)
.map((category) => {
return Object.entries(category)
.map(([key, value]) => `${key}=${value}`)
.join("\n");
})
.join("\n\n"),
source: {
type: "image",
image: input.appServiceImage,
Expand All @@ -59,37 +107,41 @@ export function generate(input: Input): Output {
},
});

if (input.databaseType === "postgres") {
services.push({
type: "postgres",
data: {
projectName: input.projectName,
serviceName: input.databaseServiceName,
password: databasePassword,
},
});
switch (input.databaseType) {
case "postgres":
services.push({
type: "postgres",
data: {
projectName: input.projectName,
serviceName: input.databaseServiceName,
password: databasePassword,
},
});
break;

case "mysql":
services.push({
type: "mysql",
data: {
projectName: input.projectName,
serviceName: input.databaseServiceName,
image: "mysql:5",
password: databasePassword,
},
});
break;
}

if (input.databaseType === "mysql") {
if (input.redisServiceName) {
services.push({
type: "mysql",
type: "redis",
data: {
projectName: input.projectName,
serviceName: input.databaseServiceName,
image: "mysql:5",
password: databasePassword,
serviceName: input.redisServiceName,
password: redisPassword,
},
});
}

services.push({
type: "redis",
data: {
projectName: input.projectName,
serviceName: input.redisServiceName,
password: redisPassword,
},
});

return { services };
}
95 changes: 83 additions & 12 deletions templates/directus/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ contributors:
url: https://github.com/Ponkhy
- name: Andrei Canta
url: https://github.com/deiucanta
- name: Davide Gaio
url: https://github.com/dukio
schema:
type: object
required:
- projectName
- appServiceName
- appServiceImage
- adminEmail
- adminPassword
- logLevel
- databaseType
- databaseServiceName
- redisServiceName
- storageLocation
properties:
# Base properties
projectName:
type: string
title: Project Name
Expand All @@ -48,14 +51,48 @@ schema:
appServiceImage:
type: string
title: App Service Image
default: directus/directus:9.18.1
default: directus/directus:10.8.2
# Admin
adminEmail:
type: string
title: Admin Email
description: admin@example.com
default: admin@example.com
adminPassword:
type: string
title: Admin Password
description: Leave empty to generate a random one
# General
logLevel:
type: string
title: Log Level
oneOf:
- enum:
- fatal
title: Fatal
- enum:
- error
title: Error
- enum:
- warn
title: Warn
- enum:
- info
title: Info
- enum:
- debug
title: Debug
- enum:
- trace
title: Trace
- enum:
- silent
title: Silent
default: info
# Database
databaseServiceName:
type: string
title: Database Service Name
default: directus-db
databaseType:
type: string
title: Database Type
Expand All @@ -66,17 +103,48 @@ schema:
- enum:
- mysql
title: MySQL
databaseServiceName:
type: string
title: Database Service Name
default: directus-db
default: postgres
# Cache
redisServiceName:
type: string
title: Redis Service Name
default: directus-redis
description: Leave empty to use memory cache instead
# Storage
storageLocation:
type: string
title: Storage Location
oneOf:
- enum:
- local
title: Local
- enum:
- s3
title: S3
default: local
description: If S3, compile the following "Storage S3" fields
storageS3Key:
type: string
title: Storage S3 Key
storageS3Secret:
type: string
title: Storage S3 Secret
storageS3Bucket:
type: string
title: Storage S3 Bucket
default: bucket-name
storageS3Region:
type: string
title: Storage S3 Region
default: eu-central-001
storageS3Endpoint:
type: string
title: Storage S3 Endpoint
default: s3.eu-central-001.example.com
benefits:
- title: Efficient Data Management
description: Directus is a modern, open-source data platform that allows you to
description:
Directus is a modern, open-source data platform that allows you to
efficiently manage your SQL database. It provides a dynamic API for your
data, enabling you to browse, manage, and visualize your data in an
intuitive no-code app.
Expand All @@ -91,18 +159,21 @@ benefits:
need to migrate to a proprietary data model, so there's no vendor lock-in.
features:
- title: Data Engine
description: Directus features a modern data stack that turns any SQL database
description:
Directus features a modern data stack that turns any SQL database
into an API and a beautiful no-code app. It's the world's first Open Data
Platform for instantly managing your data.
- title: Data Studio
description: The Data Studio feature allows for no-code data collaboration. It
description:
The Data Studio feature allows for no-code data collaboration. It
enables your entire team to safely and intuitively browse, manage, and
visualize data.
- title: Workflow Automation
description: With the Workflow Automation feature, Directus allows you to
automate your workflows, increasing efficiency and productivity.
- title: Asset Management
description: Directus also features an Asset Management system that allows you
description:
Directus also features an Asset Management system that allows you
to manage and deliver assets efficiently.
tags:
- Developer Tools
Expand Down