---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: openslice
  labels:
    org.etsi.osl.service: osportalapi
  name: osportalapi
spec:
  replicas: 1
  selector:
    matchLabels:
      org.etsi.osl.service: osportalapi
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        org.etsi.osl.service: osportalapi
    spec:
      initContainers:
        - name: init-keycloak
          image: busybox:1.28
          command: ['sh', '-c', "until nslookup keycloak; do echo waiting for keycloak; sleep 2; done"]
        - name: init-mysql-portal
          image: busybox:1.28
          command: ['sh', '-c', "until nslookup mysql; do echo waiting for mysql; sleep 2; done"]
      containers:
        - name: openslice-portalapi
          image: openslice/org.etsi.osl.portal.api:latest
          ports:
            - containerPort: 13000
          volumeMounts:
            - name: osportalapi-claim0
              mountPath: /root
          env:
            - name: SPRING_APPLICATION_JSON
              value: >-
                {
                  "spring.datasource.url": "jdbc:mysql://mysql/osdb?createDatabaseIfNotExist=true",
                  "spring.datasource.username": "root",
                  "spring.datasource.password": "letmein",
                  "spring-addons.issuers[0].uri": "http://INGRESSADDR/auth/realms/openslice",
                  "spring-addons.issuers[0].username-json-path":"$.preferred_username",
                  "spring-addons.issuers[0].claims[0].jsonPath":"$.realm_access.roles",
                  "spring-addons.issuers[0].claims[1].jsonPath":"$.resource_access.*.roles",
                  "spring.security.oauth2.resourceserver.jwt.issuer-uri": "http://INGRESSADDR/auth/realms/openslice",
                  "springdoc.oAuthFlow.authorizationUrl": "http://INGRESSADDR/auth/realms/openslice/protocol/openid-connect/auth",
                  "springdoc.oAuthFlow.tokenUrl": "http://INGRESSADDR/auth/realms/openslice/protocol/openid-connect/token",
                  "springdoc.oauth.client-id" : "osapiWebClientId",
                  "springdoc.oauth.clientsecret" : "secret",
                  "spring.activemq.brokerUrl": "tcp://artemis:61616?jms.watchTopicAdvisories=false",
                  "spring.activemq.user": "artemis",
                  "spring.activemq.password": "artemis",
                  "logging.level.org.springframework" : "INFO"
                }
      restartPolicy: Always
      volumes:
        - name: osportalapi-claim0
          persistentVolumeClaim:
            claimName: osportalapi-claim0
---
apiVersion: v1
kind: Service
metadata:
  namespace: openslice
  labels:
    org.etsi.osl.service: osportalapi
  name: osportalapi
spec:
  ports:
    - name: "13000"
      port: 13000
      targetPort: 13000
  selector:
    org.etsi.osl.service: osportalapi
