apiVersion: apps/v1
kind: Deployment
metadata:
  name: cli-org2
  namespace: hlf
  labels:
    app: cli-org2
spec:
  selector:
    matchLabels:
      app: cli-org2
  template:
    metadata:
      labels:
        app: cli-org2
    spec:
      containers:
        - name: cli-org2
          image: hyperledger/fabric-tools:2.2
          imagePullPolicy: IfNotPresent
          tty: true
          command: ["sh"]
          workingDir: /tmp/hyperledger/chaincode
          volumeMounts:
            - mountPath: /tmp/hyperledger/shared
              name: shared-volume
            - mountPath: /tmp/hyperledger/chaincode
              name: chaincode-mount
            - mountPath: /tmp/hyperledger/org2/admin
              name: pod-data
            - mountPath: /tmp/secrets/tls-ca
              name: tls-ca-cert
          env:
            - name: GOPATH
              value: "/opt/gopath"
            - name: CORE_VM_ENDPOINT
              value: "unix:///host/var/run/docker.sock"
            # Uncomment for debugging
            # - name: FABRIC_LOGGING_SPEC
            #   value: "DEBUG"
            - name: CORE_PEER_ID
              value: "cli-org2"
            - name: CORE_PEER_ADDRESS
              value: "peer1-org2:7051"
            - name: CORE_PEER_LOCALMSPID
              value: "org2MSP"
            - name: CORE_PEER_TLS_ENABLED
              value: "true"
            - name: CORE_PEER_TLS_ROOTCERT_FILE
              value: "/tmp/secrets/tls-ca/cert.pem"
            - name: CORE_PEER_MSPCONFIGPATH
              value: "/tmp/hyperledger/org2/admin/msp"
      initContainers:
        - name: fabric-ca
          image: hyperledger/fabric-ca:1.4.7
          imagePullPolicy: IfNotPresent
          command: ["bash", "./tmp/hyperledger/scripts/startNetwork/enrollJobs/enrollAdmin.sh"]
          volumeMounts:
            - mountPath: /tmp/hyperledger/shared
              name: shared-volume
            - mountPath: /tmp/hyperledger/scripts
              name: scripts
            - mountPath: /tmp/hyperledger/org2/admin
              name: pod-data
            - mountPath: /tmp/secrets/rca-org2
              name: rca-org2-cert
              readOnly: true
          env:
            - name: FABRIC_CA_SERVER_DEBUG
              value: "true"
            - name: ORG_NUM
              value: "2"
            - name: ORG_CA_PORT
              value: "7052"
            - name: ADMIN_IDENTITY_USER
              valueFrom:
                secretKeyRef:
                  name: credentials.admin-org2
                  key: username
            - name: ADMIN_IDENTITY_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: credentials.admin-org2
                  key: password

      volumes:
        - name: shared-volume
          hostPath:
            path: /mnt/hyperledger/shared
        - name: scripts
          hostPath:
            path: /mnt/hyperledger/scripts
        - name: chaincode-mount
          hostPath:
            path: /mnt/hyperledger/uc4
        - name: pod-data
          emptyDir: {}
        - name: docker-mount
          hostPath:
            path: /var/run/
        - name: tls-ca-cert
          secret:
            secretName: cert.tls-ca
        - name: rca-org2-cert
          secret:
            secretName: cert.rca-org2
