magda-io / magda

A federated, open-source data catalog for all your big data and small data
https://magda.io
Apache License 2.0
514 stars 93 forks source link

Better way of passing deploy time config values to Scala Web Service #3464

Closed t83714 closed 1 year ago

t83714 commented 1 year ago

Better way of passing deploy time config values to Scala Web Service

We currently pass deploy time config values to Scale Web Service via JVM system properties (set via command line parameters).

e.g. a final deployed k8s pod manifest (generated by helm chart) might look like the following:

spec:
  containers:
  - command:
    - bin/magda-registry-api
    - -Dhttp.port=6101
    - -Dhttp.externalUrl.v0=https://minikube.data.gov.au/api/v0/registry
    - -Ddb.default.url=jdbc:postgresql://registry-db/postgres
    - -Dakka.loglevel=INFO
    - -DauthApi.baseUrl=http://authorization-api
    - -Dscalikejdbc.global.loggingSQLAndTime.logLevel=info
    - -Dauthorization.skip=false
    - -Dauthorization.skipOpaQuery=false
    - -Drole=full
    - -DvalidateJsonSchema=false
    - -Dakka.http.server.request-timeout=60s
    - -Dakka.http.server.idle-timeout=60s
    - -Dscalikejdbc.global.loggingSQLAndTime.enabled=false

Problems with the current approach

Proposed Solution

e.g. The appConfig (that passes the same config data as the k8s pod manifest example above) might look like this:

appConfig:
  http: 
    port: 6101
    externalUrl:
      v0: https://minikube.data.gov.au/api/v0/registry
  db:
    default:
      url: jdbc:postgresql://registry-db/postgres
  authApi:
    baseUrl: http://authorization-api
  scalikejdbc:
    global:
      loggingSQLAndTime:
        logLevel: info
        enabled: false
  authorization:
    skip: false
    skipOpaQuery: false
  role: full
  validateJsonSchema: false
  akka:
    loglevel: INFO
    http:
      server:
        "request-timeout": "60s"
        "idle-timeout": "60s"
apiVersion: v1
kind: ConfigMap
metadata:
  name: "xxxx-srv-application-conf"
data:
  deploy-application.conf: {{ (mustRegexReplaceAllLiteral "^\\s*{" (.Values. appConfig | mustToPrettyJson) "{\n  include \"application\"") | quote }}

The string stored in deploy-application.conf in the configMap above will look like the following:

{
  # load the default application.conf in jar
  include "application"
  "http": {
    "port": 6101,
    "externalUrl": {
      "v0": "https://minikube.data.gov.au/api/v0/registry"
    }
  },
  "db": {
    "default": {
      "url": "jdbc:postgresql://registry-db/postgres"
    }
  },
  "authApi": {
    "baseUrl": "http://authorization-api"
  },
  "scalikejdbc": {
    "global": {
      "loggingSQLAndTime": {
        "logLevel": "info",
        "enabled": false
      }
    }
  },
  "authorization": {
    "skip": false,
    "skipOpaQuery": false
  },
  "role": "full",
  "validateJsonSchema": false,
  "akka": {
    "loglevel": "INFO",
    "http": {
      "server": {
        "request-timeout": "60s",
        "idle-timeout": "60s"
      }
    }
  }
}
spec:
  containers:
  - command:
    - bin/magda-registry-api
    - -Dconfig.file=/etc/config/deploy-application.conf
    volumeMounts:
    - mountPath: /etc/config
      name: deploy-application-config
  volumes:
  - name: config
    configMap:
      name: xxxx-srv-application-conf
t83714 commented 1 year ago

Further technical notes:

t83714 commented 1 year ago

closed via PR: https://github.com/magda-io/magda/pull/3468