structurizr / onpremises

Structurizr on-premises installation
https://docs.structurizr.com/onpremises
MIT License
140 stars 54 forks source link

Configuration and data directory issue #62

Closed Rudis1261 closed 1 year ago

Rudis1261 commented 1 year ago

Description

I am struggling to run the on-premises version of the application in our kubernetes strack. And it's because the properties file is nested in the data directory.

I want to manage the config via configmap, and mount it to a filepath. And my data directory to be a volume mount. But you cannot mount a config map to disk over a volume mount.

Something simple to fix this would be to provide a way to point to the properties file outside of the data directory. Or alternatively, make all options available via ENV variable.

Steps to reproduce

Use both a volume mount and configmap.

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nexus-diagrams
  namespace: {{ .Values.namespace}}
spec:
  selector:
    matchLabels:
      run: nexus-diagrams
  replicas: {{ .Values.replicaCount }}
  template:
    metadata:
      labels:
        run: nexus-diagrams
    spec:
      containers:
        - name: nexus-diagrams
          image: structurizr/onpremises:3130
          imagePullPolicy: Always
          ports:
            - containerPort: 8080
          # readinessProbe:
          #   httpGet:
          #     path: /
          #     port: 8080
          #   initialDelaySeconds: 5
          #   periodSeconds: 10
          # livenessProbe:
          #   httpGet:
          #     path: /
          #     port: 8080
          #   initialDelaySeconds: 10
          #   periodSeconds: 20
          command: 
            - tail
            - -f
            - /dev/null
          resources:
            limits:
              memory: 1Gi
            requests:
              memory: 512Mi
          env:
            - name: STRUCTURIZR_DATA_DIRECTORY
              value: "/data"
          volumeMounts:
            - name: diagrams-storage-volume
              mountPath: "/data"
            - name: structurizr-properties
              mountPath: "/data"
              subPath: "structurizr.properties"

      volumes:
        - name: diagrams-storage-volume
          persistentVolumeClaim:
            claimName: diagrams-storage-pv-claim
        - name: structurizr-properties
          configMap:
            name: properties-file
            items:
              - key: "config"
                path: "structurizr.properties"
---
apiVersion: v1
kind: Service
metadata:
  name: nexus-diagrams
  namespace: {{ .Values.namespace}}
  labels:
    run: nexus-diagrams
spec:
  ports:
    - port: 8080
      protocol: TCP
      name: http
  selector:
    run: nexus-diagrams
---
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
  name: nexus-diagrams-ingress
  namespace: {{ .Values.namespace}}
  annotations:
    traefik.ingress.kubernetes.io/router.middlewares: {{ .Values.namespace }}-whitelist@kubernetescrd
spec:
  rules:
    - host: {{ .Values.dnsName }}
      http:
        paths:
          - backend:
              service:
                name: nexus-diagrams
                port:
                  name: http
            path: /
            pathType: Prefix
  tls:
    - hosts:
        - {{ .Values.dnsName }}
      secretName: tls-nexus-diagrams-ingress
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: tls-nexus-diagrams-ingress
  namespace: {{ .Values.namespace}}
spec:
  secretName: tls-nexus-diagrams-ingress
  dnsNames:
    - {{ .Values.dnsName }}
  issuerRef:
    name: letsencrypt-production
    kind: ClusterIssuer
    group: cert-manager.io
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: whitelist
  namespace: {{ .Values.namespace}}
spec:
  ipWhiteList:
    sourceRange:
      {{- range .Values.vpnOfficeIps }}
      - {{.}}{{- end }}
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: properties-file
data:
  config: |
    structurizr.url={{.Values.dnsName}}
    structurizr.session=local
    structurizr.data=file
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: diagrams-storage-pv-claim
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: csi-cinder-sc-retain
  resources:
    requests:
      storage: 1Gi

Screenshot

No response

Code sample

No response

Configuration

Using image: structurizr/onpremises:3130

Severity

Major

Priority

Low

Resolution

I have no budget, please fix this for free

More information

No response

Rudis1261 commented 1 year ago

I have since discovered you can mount configuration over a volume mount. You do need to provide a subPath and specify the mounting file name and it does indeed work as expected.

Adding my config as an example:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nexus-diagrams
  namespace: {{ .Values.namespace}}
spec:
  selector:
    matchLabels:
      run: nexus-diagrams
  replicas: {{ .Values.replicaCount }}
  template:
    metadata:
      labels:
        run: nexus-diagrams
    spec:
      containers:
        - name: nexus-diagrams
          image: structurizr/onpremises:3130 #https://hub.docker.com/r/structurizr/onpremises/tags 
          imagePullPolicy: Always
          ports:
            - containerPort: 8080
          readinessProbe:
            httpGet:
              path: /
              port: 8080
            initialDelaySeconds: 5
            periodSeconds: 10
          livenessProbe:
            httpGet:
              path: /
              port: 8080
            initialDelaySeconds: 10
            periodSeconds: 20
          resources:
            limits:
              memory: 1Gi
            requests:
              memory: 512Mi
          env:
            - name: STRUCTURIZR_DATA_DIRECTORY
              value: "/data"
          volumeMounts:
            - name: diagrams-storage-volume
              mountPath: "/data"
            - name: configuration-volume 
              mountPath: /data/structurizr.properties
              subPath: structurizr-properties
            - name: configuration-volume
              mountPath: /data/structurizr.users
              subPath: structurizr-users

      volumes:
        - name: diagrams-storage-volume
          persistentVolumeClaim:
            claimName: diagrams-storage-pv-claim
        - name: configuration-volume 
          configMap:
            name: configuration
---
apiVersion: v1
kind: Service
metadata:
  name: nexus-diagrams
  namespace: {{ .Values.namespace}}
  labels:
    run: nexus-diagrams
spec:
  ports:
    - port: 8080
      protocol: TCP
      name: http
  selector:
    run: nexus-diagrams
---
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
  name: nexus-diagrams-ingress
  namespace: {{ .Values.namespace}}
  annotations:
    traefik.ingress.kubernetes.io/router.middlewares: {{ .Values.namespace }}-whitelist@kubernetescrd
spec:
  rules:
    - host: {{ .Values.dnsName }}
      http:
        paths:
          - backend:
              service:
                name: nexus-diagrams
                port:
                  name: http
            path: /
            pathType: Prefix
  tls:
    - hosts:
        - {{ .Values.dnsName }}
      secretName: tls-nexus-diagrams-ingress
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: tls-nexus-diagrams-ingress
  namespace: {{ .Values.namespace}}
spec:
  secretName: tls-nexus-diagrams-ingress
  dnsNames:
    - {{ .Values.dnsName }}
  issuerRef:
    name: letsencrypt-production
    kind: ClusterIssuer
    group: cert-manager.io
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: whitelist
  namespace: {{ .Values.namespace}}
spec:
  ipWhiteList:
    sourceRange:
      {{- range .Values.vpnOfficeIps }}
      - {{.}}{{- end }}
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: configuration
data:
  structurizr-properties: |
    structurizr.url={{.Values.dnsName}}
    structurizr.session=local
    structurizr.data=file
  structurizr-users: |
    nexus=$2a$10$Mbz56LQa....4icrc8xIMevoLq
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: diagrams-storage-pv-claim
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: csi-cinder-sc-retain
  resources:
    requests:
      storage: 5Gi