Skip to content

Commit

Permalink
Migrate the config.yaml generation to PKL
Browse files Browse the repository at this point in the history
  • Loading branch information
thesocialdev committed Aug 24, 2024
1 parent dca145d commit c3e4ae0
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 21 deletions.
29 changes: 8 additions & 21 deletions .github/workflows/aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ env:
NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY }}
IMAGE: aletheiafact-production
ENVIRONMENT: development
ENV: development
UMAMI_SITE_ID: ${{ secrets.DEVELOPMENT_UMAMI_SITE_ID }}
MONGODB_URI: ${{ secrets.DEVELOPMENT_MONGODB_URI }}
MONGODB_NAME: ${{ secrets.DEVELOPMENT_MONGODB_NAME }}
Expand All @@ -41,7 +42,7 @@ env:
ZENVIA_API_URL: ${{ secrets.DEVELOPMENT_ZENVIA_API_URL }}
ZENVIA_API_TOKEN: ${{ secrets.DEVELOPMENT_ZENVIA_API_URL }}
AGENCIA_ACCESS_TOKEN: ${{ secrets.DEVELOPMENT_AGENCIA_ACCESS_TOKEN }}

RECAPTCHA_SECRET: ${{ secrets.RECAPTCHA_SECRETKEY }}
jobs:
setup-build-publish:
name: Build & Publish
Expand All @@ -57,6 +58,7 @@ jobs:
sed -i '21{s/test.//}' deployment/app.yml
sed -i '11{s/testws./ws./}' deployment/websocket.yml
sed -i '11{s/test.//}' config.seed.example.yaml
echo "ENV=production" >> $GITHUB_ENV
echo "ENVIRONMENT=production" >> $GITHUB_ENV
echo "UMAMI_SITE_ID=${{ secrets.PRODUCTION_UMAMI_SITE_ID }}" >> $GITHUB_ENV
echo "NEXT_PUBLIC_UMAMI_SITE_ID=${{ secrets.PRODUCTION_UMAMI_SITE_ID }}" >> $GITHUB_ENV
Expand Down Expand Up @@ -90,29 +92,14 @@ jobs:
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Install pkl
uses: pkl-community/setup-pkl@v0
with:
pkl-version: 0.25.2
# Setting up config.yaml based on environment
- name: Set config.yaml
env:
RECAPTCHA_SECRET: ${{ secrets.RECAPTCHA_SECRETKEY }}
run: |
sed -i "s%ZENVIA_API_URL%$ZENVIA_API_URL%g" config.$ENVIRONMENT.yaml
sed -i "s%ZENVIA_API_TOKEN%$ZENVIA_API_TOKEN%g" config.$ENVIRONMENT.yaml
sed -i "s/ENV/$ENVIRONMENT/g" config.$ENVIRONMENT.yaml
sed -i "s%RECAPTCHA_SECRET%$RECAPTCHA_SECRET%g" config.$ENVIRONMENT.yaml
sed -i "s%MONGODB_URI%$MONGODB_URI%g" config.$ENVIRONMENT.yaml
sed -i "s%ORY_SDK_URL%$ORY_SDK_URL%g" config.$ENVIRONMENT.yaml
sed -i "s%GITLAB_FEATURE_FLAG_URL%$GITLAB_FEATURE_FLAG_URL%g" config.$ENVIRONMENT.yaml
sed -i "s%GITLAB_FEATURE_FLAG_INSTANCE_ID%$GITLAB_FEATURE_FLAG_INSTANCE_ID%g" config.$ENVIRONMENT.yaml
sed -i "s/ORY_ACCESS_TOKEN/$ORY_ACCESS_TOKEN/g" config.$ENVIRONMENT.yaml
sed -i "s/ALETHEIA_SCHEMA_ID/$ALETHEIA_SCHEMA_ID/g" config.$ENVIRONMENT.yaml
sed -i "s%AWS_SDK_BUCKET%$AWS_SDK_BUCKET%g" config.$ENVIRONMENT.yaml
sed -i "s%AWS_ACCESS_KEY_ID%$AWS_ACCESS_KEY_ID%g" config.$ENVIRONMENT.yaml
sed -i "s%AWS_SECRET_ACCESS_KEY%$AWS_SECRET_ACCESS_KEY%g" config.$ENVIRONMENT.yaml
sed -i "s%NOVU_API_KEY%$NOVU_API_KEY%g" config.$ENVIRONMENT.yaml
sed -i "s%NOVU_APPLICATION_IDENTIFIER%$NOVU_APPLICATION_IDENTIFIER%g" config.$ENVIRONMENT.yaml
sed -i "s%AGENTS_API_URL%$AGENTS_API_URL%g" config.$ENVIRONMENT.yaml
sed -i "s%OPENAI_API_KEY%$OPENAI_API_KEY%g" config.$ENVIRONMENT.yaml
sed -i "s%AGENCIA_ACCESS_TOKEN%$AGENCIA_ACCESS_TOKEN%g" config.$ENVIRONMENT.yaml
pkl eval -f yaml ./deployment/config/config-file/$ENVIRONMENT.pkl > config.$ENVIRONMENT.yaml
- name: Set migrate-mongo-config.ts
run: |
Expand Down
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")
4 changes: 4 additions & 0 deletions deployment/config/config-file/modules/service/base.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class BaseService {
name: String
conf: Map<String, Value>
}
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
}
}
}

0 comments on commit c3e4ae0

Please sign in to comment.