Skip to content

Commit

Permalink
API on Fly
Browse files Browse the repository at this point in the history
  • Loading branch information
vladzaharia committed Sep 19, 2024
1 parent 7986014 commit 5dc6b82
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
16 changes: 16 additions & 0 deletions directus-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM litestream/litestream:latest AS litestream

FROM directus/directus:latest

USER root

# Litefs
RUN apk add ca-certificates fuse3 sqlite
COPY --from=flyio/litefs:0.5 /usr/local/bin/litefs /usr/local/bin/litefs
ADD litefs.yml /etc/litefs.yml

# Litestream
COPY --from=litestream /usr/local/bin/litestream /usr/local/bin/litestream
ADD litestream.yml /etc/litestream.yml

ENTRYPOINT litefs mount
56 changes: 56 additions & 0 deletions directus-api/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# fly.toml app configuration file generated for vladgg-api on 2024-09-18T20:31:56-07:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'vladgg-api'
primary_region = 'sea'

[build]

[http_service]
internal_port = 8080
protocol = "tcp"

[mounts]
source = "litefs"
destination = "/var/lib/litefs"

[[vm]]
memory = '512mb'
cpu_kind = 'shared'
cpus = 1

[env]
PUBLIC_URL = "https://api.vlad.gg"
DB_CLIENT = "sqlite3"
DB_FILENAME = "/litefs/data.db"
AUTH_PROVIDERS = "authentik"
AUTH_AUTHENTIK_LABEL = "Polaris Auth"
AUTH_AUTHENTIK_ICON = "admin_panel_settings"
AUTH_AUTHENTIK_DRIVER = "openid"
AUTH_AUTHENTIK_SCOPE = "openid profile email split_name"
AUTH_AUTHENTIK_IDENTIFIER_KEY = "email"
AUTH_AUTHENTIK_FIRST_NAME_KEY = "given_name"
AUTH_AUTHENTIK_LAST_NAME_KEY = "family_name"
AUTH_AUTHENTIK_SYNC_USER_INFO = "true"
AUTH_AUTHENTIK_DEFAULT_ROLE_ID = "ac44bb88-4e2f-4804-99d9-44fa6e4f5659"
AUTH_AUTHENTIK_ALLOW_PUBLIC_REGISTRATION = "true"
STORAGE_LOCATIONS = "cloudflare,tigris"
STORAGE_CLOUDFLARE_DRIVER = "s3"
STORAGE_CLOUDFLARE_REGION = "auto"
STORAGE_TIGRIS_DRIVER = "s3"
STORAGE_TIGRIS_REGION = "auto"
EMAIL_TRANSPORT = "smtp"
EMAIL_SMTP_PORT = "465"
EMAIL_SMTP_SECURE = "true"
RATE_LIMITER_ENABLED = "true"
RATE_LIMITER_GLOBAL_ENABLED = "true"
# RATE_LIMITER_STORE="redis"
CACHE_ENABLED = "true"
# CACHE_STORE="redis"
REDIS_ENABLED="false"
REDIS_PORT="6379"
REDIS_USERNAME="default"
# SYNCHRONIZATION_STORE="redis"
WEBSOCKETS_ENABLED = "true"
28 changes: 28 additions & 0 deletions directus-api/litefs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
fuse:
dir: "/litefs"

data:
dir: "/var/lib/litefs"

exit-on-error: false

proxy:
addr: ":8080"
target: "localhost:8055"
db: "data.db"
passthrough:
- "*.ico"
- "*.png"

exec:
- cmd: "litestream replicate"

lease:
type: "consul"
advertise-url: "http://${HOSTNAME}.vm.${FLY_APP_NAME}.internal:20202"
candidate: ${FLY_REGION == PRIMARY_REGION}
promote: true

consul:
url: "${FLY_CONSUL_URL}"
key: "litefs/${FLY_APP_NAME}"
24 changes: 24 additions & 0 deletions directus-api/litestream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
exec: pm2-runtime start ecosystem.config.cjs && node cli.js bootstrap

dbs:
- path: /litefs/data.db
meta-path: /var/lib/litefs/data.db-litestream
replicas:
- name: cloudflare
type: s3
endpoint: ${STORAGE_CLOUDFLARE_ENDPOINT}
bucket: ${STORAGE_CLOUDFLARE_BUCKET}
path: backup/data.db
region: auto
force-path-style: true
access-key-id: ${STORAGE_CLOUDFLARE_KEY}
secret-access-key: ${STORAGE_CLOUDFLARE_SECRET}
- name: tigris
type: s3
endpoint: ${STORAGE_TIGRIS_ENDPOINT}
bucket: ${STORAGE_TIGRIS_BUCKET}
path: backup/data.db
region: auto
force-path-style: true
access-key-id: ${STORAGE_TIGRIS_KEY}
secret-access-key: ${STORAGE_TIGRIS_SECRET}

0 comments on commit 5dc6b82

Please # to comment.