Files
Olares/docs/developer/develop/mw-integrate-with-pg.md

2.8 KiB

outline, description
outline description
2
3
Learn how to integrate your app with the built-in PostgreSQL service in beOS Pro.

Integrate with PostgreSQL

Use beOS Pro PostgreSQL middleware by declaring it in beOS ProManifest.yaml, then mapping the injected values to your container environment variables.

:::info PosgreSQL installed PostgreSQL service has been installed by default. :::

Configure beOS ProManifest.yaml

In beOS ProManifest.yaml, add the required middleware configuration.

  • Use the scripts field to specify scripts that should be executed after the database is created.
  • Use the extensions field to add the corresponding extension in the database.

:::info Variable injection in scripts The OS provides two variables, $databasename and $dbusername, which will be replaced by beOS Pro Application Runtime when the command is executed. :::

Example

middleware:
  postgres:
    username: immich
    databases:
    - name: immich
      extensions:
      - vectors
      - earthdistance
      scripts:
      - BEGIN;                                           
      - ALTER DATABASE $databasename SET search_path TO "$user", public, vectors;
      - ALTER SCHEMA vectors OWNER TO $dbusername;
      - COMMIT;

Map to environment variables

In your deployment YAML, map the injected .Values.postgres.* fields to the container environment variables your app requires.

Example

containers:
  - name: my-app
    env:
      # The database name configured in beOS ProManifest, specified in middleware.postgres.databases[i].name
      # NOTE: Replace <dbname> with the actual name defined in the Manifest (e.g., immich)
      - name: DB_POSTGRESDB_DATABASE
        value: {{ .Values.postgres.databases.<dbname> }}
      
      # Host
      - name: DB_POSTGRESDB_HOST
        value: {{ .Values.postgres.host }}
      
      # Port
      - name: DB_POSTGRESDB_PORT
        value: "{{ .Values.postgres.port }}"
      
      # Username
      - name: DB_POSTGRESDB_USER
        value: {{ .Values.postgres.username }}
      
      # Password
      - name: DB_POSTGRESDB_PASSWORD
        value: {{ .Values.postgres.password }}

PostgreSQL values reference

PostgreSQL values are predefined runtime values injected into values.yaml during deployment. They are system-managed and not user-editable.

Value Type Description
.Values.postgres.host String PostgreSQL host.
.Values.postgres.port Number PostgreSQL port.
.Values.postgres.username String PostgreSQL username.
.Values.postgres.password String PostgreSQL password.
.Values.postgres.databases Map<String,String> Requested databases, keyed by database name. For example, a request for app_db is available at .Values.postgres.databases.app_db.