Skip to content

Commit

Permalink
Merge pull request #1361 from AletheiaFact/stage
Browse files Browse the repository at this point in the history
Migrate the config.yaml and k8s deployment file generation to PKL
  • Loading branch information
thesocialdev authored Aug 25, 2024
2 parents 4868607 + 20bbdca commit a5fcc44
Show file tree
Hide file tree
Showing 19 changed files with 585 additions and 232 deletions.
427 changes: 195 additions & 232 deletions .github/workflows/aws.yml

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions deployment/config/config-file/development.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
amends "./modules/main.pkl"
import "./modules/database/mongodb.pkl"
appBaseUrl = "aletheiafact.org"

var = new {
name = "aletheia-development"
conf {
cors = "*"
recaptcha_sitekey = "6Lc2BtYUAAAAAOUBI-9r1sDJUIfG2nt6C43noOXh"
websocketUrl = "wss://testws.\(appBaseUrl) "
baseUrl = "https://test.\(appBaseUrl)"
db = (mongodb) {
atlas = true
}
}
}
1 change: 1 addition & 0 deletions deployment/config/config-file/modules/agencia.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
access_token = read("env:AGENCIA_ACCESS_TOKEN")
3 changes: 3 additions & 0 deletions deployment/config/config-file/modules/aws/s3.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bucket = read("env:AWS_SDK_BUCKET")
accessKeyId = read("env:AWS_ACCESS_KEY_ID")
secretAccessKey = read("env:AWS_SECRET_ACCESS_KEY")
8 changes: 8 additions & 0 deletions deployment/config/config-file/modules/database/mongodb.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
atlas = false
connection_uri = read("env:MONGODB_URI")
options = new {
useUnifiedTopology = true
useNewUrlParser = true
retryWrites = true
w = "majority"
}
3 changes: 3 additions & 0 deletions deployment/config/config-file/modules/feature_flag.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
url = read("env:GITLAB_FEATURE_FLAG_URL")
appName = read("env:ENV")
instanceId = read("env:GITLAB_FEATURE_FLAG_INSTANCE_ID")
34 changes: 34 additions & 0 deletions deployment/config/config-file/modules/main.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import "./database/mongodb.pkl"
import "./service/confBase.pkl"
import "./ory.pkl" as oryConfig


hidden appBaseUrl: String

hidden var = new {
name = "service-aletheia"
conf = new {
port = 3000
recaptcha_sitekey = read("env:RECAPTCHA_SITEKEY")
websocketUrl = read("env:WEBSOCKET_URL")
baseUrl = read("env:BASE_URL")
automatedFactCheckingAPIUrl = read("env:AGENTS_API_URL")
recaptcha_secret = read("env:RECAPTCHA_SECRET")
throttle = new confBase.Throttle {
ttl = 60
limit = 100
}
ory = (oryConfig) {
admin_endpoint = "admin"
}
}
}

services = new Listing {
new {
name = var.name
conf = (confBase) {
...var.conf
}
}
}
2 changes: 2 additions & 0 deletions deployment/config/config-file/modules/novu.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
api_key = read("env:NOVU_API_KEY")
application_identifier = read("env:NOVU_APPLICATION_IDENTIFIER")
2 changes: 2 additions & 0 deletions deployment/config/config-file/modules/openai.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
api_key = read("env:OPENAI_API_KEY")

5 changes: 5 additions & 0 deletions deployment/config/config-file/modules/ory.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
url = read("env:ORY_SDK_URL")
admin_url = read("env:ORY_SDK_URL")
admin_endpoint: String
access_token = read("env:ORY_ACCESS_TOKEN")
schema_id = read("env:ALETHEIA_SCHEMA_ID")
31 changes: 31 additions & 0 deletions deployment/config/config-file/modules/service/confBase.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import "../database/mongodb.pkl" as mongoDbConfig
import "../ory.pkl" as oryConfig
import "../feature_flag.pkl" as featureFlagConfig
import "../aws/s3.pkl" as s3Config
import "../novu.pkl" as novuConfig
import "../openai.pkl" as openaiConfig
import "../zenvia.pkl" as zenviaConfig
import "../agencia.pkl" as agenciaConfig

class Throttle {
ttl: Number
limit: Number
}

port: Number
cors: String
websocketUrl: String
baseUrl: String
automatedFactCheckingAPIUrl: String
recaptcha_secret: String
recaptcha_sitekey: String
throttle: Throttle
authentication_type = "ory"
db = (mongoDbConfig) {}
ory = (oryConfig) {}
feature_flag = (featureFlagConfig) {}
aws = (s3Config) {}
novu = (novuConfig) {}
openai = (openaiConfig) {}
zenvia = (zenviaConfig) {}
agencia = (agenciaConfig) {}
2 changes: 2 additions & 0 deletions deployment/config/config-file/modules/zenvia.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
api_url = read("env:ZENVIA_API_URL")
api_token = read("env:ZENVIA_API_TOKEN")
16 changes: 16 additions & 0 deletions deployment/config/config-file/production.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
amends "./modules/main.pkl"
import "./modules/database/mongodb.pkl"
appBaseUrl = "aletheiafact.org"

var = new {
name = "aletheia-production"
conf {
cors = "*"
recaptcha_sitekey = "6Lc2BtYUAAAAAOUBI-9r1sDJUIfG2nt6C43noOXh"
websocketUrl = "wss://ws.\(appBaseUrl) "
baseUrl = "https://\(appBaseUrl)"
db = (mongodb) {
atlas = true
}
}
}
92 changes: 92 additions & 0 deletions deployment/k8s/app.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1#/K8sResource.pkl"
import "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1#/api/apps/v1/Deployment.pkl"
import "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1#/api/core/v1/Service.pkl"
import "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1#/api/networking/v1/Ingress.pkl"
import "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1#/api/core/v1/PodSpec.pkl"
import "./modules/ingress.pkl" as ingress

hidden appNamespace = "development"
hidden podPort = 3000

hidden IngressOptions = new {
rules = new {}
}
hidden ServiceOptions = new {
spec = new Service.ServiceSpec {
type = "NodePort"
selector {
["app"] = "aletheia"
}
ports {
new {
name = "aletheia"
targetPort = trace(podPort)
port = 80
}
}
}
}
hidden DeploymentOptions = new {
replicas = 1
containers = new Listing<PodSpec.Container> {}
}


resources: Listing<K8sResource> = new {
new Ingress {
metadata {
name = "ingress-aletheia"
namespace = appNamespace
annotations {
["kubernetes.io/ingress.class"] = "traefik"
}
}
spec {
rules = new {
for (_rule in IngressOptions.rules) {
_rule
}
}
}
}

new Service {
metadata {
name = "aletheia"
namespace = appNamespace
}
spec = ServiceOptions.spec
}

new Deployment {
metadata {
name = "aletheia"
namespace = appNamespace
}
spec {
replicas = DeploymentOptions.replicas
selector {
matchLabels {
["app"] = "aletheia"
}
}
template {
metadata {
labels {
["app"] = "aletheia"
}
}
spec {
containers = DeploymentOptions.containers
}
}
}
}
}

output {
value = resources
renderer = (K8sResource.output.renderer as YamlRenderer) {
isStream = true
}
}
28 changes: 28 additions & 0 deletions deployment/k8s/development.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
amends "./app.pkl"
import "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1#/K8sResource.pkl"
import "./modules/ingress.pkl" as ingress
import "./modules/aletheia.pkl"

appNamespace = "development"
podPort = 3000

local newAletheia = new (aletheia) {
ns = appNamespace
p = podPort
}

IngressOptions {
rules {
(ingress.rule) {
host = "test.aletheiafact.org"
}
}
}

DeploymentOptions {
containers {
(newAletheia.pod.container) {
name = "aletheia"
}
}
}
11 changes: 11 additions & 0 deletions deployment/k8s/modules/aletheia.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import "./container.pkl" as containerConfig
import "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1#/api/core/v1/PodSpec.pkl"

hidden ns = ""
hidden p = 3000

pod = (containerConfig) {
namespace = ns
imagePath = "134187360702.dkr.ecr.us-east-1.amazonaws.com/aletheiafact-production" + ":" + read("env:TAG")
podPort = p
}
79 changes: 79 additions & 0 deletions deployment/k8s/modules/container.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1#/api/core/v1/EnvVar.pkl"
import "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1#/api/core/v1/ResourceRequirements.pkl"
import "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1#/api/core/v1/PodSpec.pkl"

hidden namespace = ""
hidden imagePath = ""
hidden podPort = ""

container: PodSpec.Container = new {
name = ""
image = imagePath
imagePullPolicy = "Always"
env = new {
new {
name = "NEXT_PUBLIC_UMAMI_SITE_ID"
value = read("env:UMAMI_SITE_ID")
}
new {
name = "NEXT_PUBLIC_RECAPTCHA_SITEKEY"
value = read("env:RECAPTCHA_SITEKEY")
}
new {
name = "ORY_SDK_URL"
value = read("env:ORY_SDK_URL")
}
new {
name = "ORY_ACCESS_TOKEN"
value = read("env:ORY_ACCESS_TOKEN")
}
new {
name = "NEW_RELIC_LICENSE_KEY"
value = read("env:NEW_RELIC_LICENSE_KEY")
}
new {
name = "NEW_RELIC_APP_NAME"
value = "aletheia-" + namespace
}
new {
name = "NEXT_PUBLIC_ORY_SDK_URL"
value = read("env:ORY_SDK_URL")
}
new {
name = "OPENAI_API_KEY"
value = read("env:OPENAI_API_KEY")
}
new {
name = "ENV_NAME"
value = namespace
}
}

readinessProbe {
httpGet {
path = "/api/health"
port = podPort
}
initialDelaySeconds = 50
timeoutSeconds = 5
}
livenessProbe {
httpGet {
path = "/api/health"
port = podPort
}
initialDelaySeconds = 50
timeoutSeconds = 10
failureThreshold = 10
}
resources {
requests {
["cpu"] = "300m"
["memory"] = 512.mib
}
limits {
["cpu"] = "400m"
["memory"] = 1024.mib
}
}
}
25 changes: 25 additions & 0 deletions deployment/k8s/modules/ingress.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1#/api/networking/v1/Ingress.pkl" as Ingress
import "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1#/api/apps/v1/Deployment.pkl"
import "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1#/api/core/v1/Service.pkl"
import "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1#/K8sResource.pkl"

rule: Ingress.IngressRule = new {
host = "www.test.aletheiafact.org"
http {
paths {
new {
path = "/"
pathType = "Prefix"
backend {
service {
name = "aletheia"
port {
name = "aletheia"
}
}
}
}
}
}
}

Loading

0 comments on commit a5fcc44

Please sign in to comment.