Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

postfacto helm chart DATABASE_URL env variable. Contacting to an external non containerized Postgresql #416

Open
bgarcial opened this issue Oct 29, 2021 · 1 comment

Comments

@bgarcial
Copy link

Hello postfacto community, this is not an issue itself but I want to ask which value should be the DATABASE_URL at the helm chart deployment?
My situation is the following:

  • I want to use an external Azure managed PostgreSQL and no the PostgreSQL container that comes with the helm chart.
    So in consequence, I modified the DATABASE_URL value, given here to connect to the container inside K8s, I've modified in this way:
 name: DATABASE_URL
 # value: "postgres://{{ .Values.postgresql.postgresqlUsername }}:$(POSTGRESQL_PASSWORD)@{{ .Release.Name }}-postgresql"
 value: "postgres://nmbrs@postgresql-nmb-psfc-stag:$(POSTGRESQL_PASSWORD)@postgresql-nmb-psfc-stag.postgres.database.azure.com/postfacto-staging-db"

but I am getting this error

/usr/local/lib/ruby/2.7.0/uri/generic.rb:208:in `initialize': the scheme postgres does not accept registry part: nmbrs@postgresql-nmb-psfc-stag:test2021*@postgresql-nmb-psfc-stag.postgres.database.azure.com (or bad hostname?) (URI::InvalidURIError)

Which should be the real DATABASE_URL value if I want to contact to a fully Postgres managed service?

Which is the equivalent value to this?:

value: "postgres://{{ .Values.postgresql.postgresqlUsername }}:$(POSTGRESQL_PASSWORD)@{{ .Release.Name }}-postgresql"

I mean is postgres//<username>:<my-pg-password>@<WHICH VALUE SHOULD BE HERE?>
What is the value of {{ .Release.Name }}-postgresql"

Just for the record, my customize postfacto/deployment/helm/templates/deployment.yaml is this:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "postfacto.fullname" . }}
  labels:
    {{- include "postfacto.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "postfacto.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "postfacto.selectorLabels" . | nindent 8 }}
    spec:
    {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      serviceAccountName: {{ include "postfacto.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
#      initContainers:
#        - name: psql-wait
#          image: postgres
#          env:
#          - name: POSTGRESQL_PASSWORD
#            valueFrom:
#              secretKeyRef:
#                name: "{{ .Release.Name }}-postgresql"
#                key: postgresql-password
#          command: ["sh", "-c", "for i in {1..33}; do sleep 3; if PGPASSWORD=$POSTGRESQL_PASSWORD psql -h {{ .Release.Name }}-postgresql -U {{ .Values.postgresql.postgresqlUsername }}; then exit 0; fi; done; exit 1"]
      containers:
        - name: {{ .Chart.Name }}
          env:
          - name: POSTGRES_HOST
            valueFrom:
              secretKeyRef:
                name: postfacto-ext-postgresql
                key: host
          - name: POSTGRES_DB
            valueFrom:
              secretKeyRef:
                name: postfacto-ext-postgresql
                key: database
          - name: POSTGRES_USERNAME
            valueFrom:
              secretKeyRef:
                name: postfacto-ext-postgresql
                key: username
          - name: POSTGRESQL_PASSWORD
            valueFrom:
              secretKeyRef:
                name: postfacto-ext-postgresql
                key: password
          - name: DATABASE_URL
            # value: "postgres://{{ .Values.postgresql.postgresqlUsername }}:$(POSTGRESQL_PASSWORD)@{{ .Release.Name }}-postgresql"
            value: "postgres://nmbrs@postgresql-nmb-psfc-stag:$(POSTGRESQL_PASSWORD)@postgresql-nmb-psfc-stag.postgres.database.azure.com/postfacto-staging-db"
          - name: SECRET_KEY_BASE
            value: {{ include "postfacto.secretKey" . }}
          - name: DISABLE_SSL_REDIRECT
            value: "{{ .Values.disableSSLRedirect }}"
#          - name: REDIS_PASSWORD
#            valueFrom:
#              secretKeyRef:
#                name: "{{ .Release.Name }}-redis"
#                key: redis-password
#          - name: REDIS_URL
#            value: "redis://:$(REDIS_PASSWORD)@{{ .Release.Name }}-redis-master"
          - name: GOOGLE_OAUTH_CLIENT_ID
            value: "{{ .Values.googleOAuthClientId }}"
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 3000
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}

@textbook
Copy link
Contributor

If that is your actual password in the error message, then as suggested in https://stackoverflow.com/a/34280541/3001761 it's probably because it contains * - avoid special characters in the password.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants