---
apiVersion: batch/v1
kind: Job
metadata:
  name: chaincodeinstall
spec:
  backoffLimit: 1
  template:
    metadata:
      name: chaincodeinstall
    spec:
      restartPolicy: "Never"
      volumes:
      - name: sharedvolume
        persistentVolumeClaim:
          claimName: shared-pvc
      containers:
      - name: chaincodeinstall1
        image: hyperledger/fabric-tools:1.4
        imagePullPolicy: Always
        command: ["sh", "-c", "echo $GOPATH; cp -r /shared/artifacts/chaincode $GOPATH/src/; ls $GOPATH/src; peer chaincode install -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p chaincode_example02/"]
        env:
        - name: CHAINCODE_NAME
          value: "cc"
        - name: CHAINCODE_VERSION
          value: "1.0"
        - name: FABRIC_CFG_PATH
          value: /etc/hyperledger/fabric
        - name: CORE_PEER_MSPCONFIGPATH
          value: /shared/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
        - name: CORE_PEER_LOCALMSPID
          value: Org1MSP
        - name: CORE_PEER_ADDRESS
          value: blockchain-org1peer1:7051
        - name: GODEBUG
          value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume

      # - name: chaincodeinstall2
      #   image: hyperledger/fabric-tools:1.4
      #   imagePullPolicy: Always
      #   command: ["sh", "-c", "echo $GOPATH; cp -r /shared/artifacts/chaincode $GOPATH/src/; ls $GOPATH/src; peer chaincode install -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p chaincode_example02/"]
      #   env:
      #   - name: CHAINCODE_NAME
      #     value: "cc"
      #   - name: CHAINCODE_VERSION
      #     value: "1.0"
      #   - name: FABRIC_CFG_PATH
      #     value: /etc/hyperledger/fabric
      #   - name: CORE_PEER_MSPCONFIGPATH
      #     value: /shared/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
      #   - name: CORE_PEER_LOCALMSPID
      #     value: Org2MSP
      #   - name: CORE_PEER_ADDRESS
      #     value: blockchain-org2peer1:8051
      #   - name: GODEBUG
      #     value: "netdns=go"
      #   volumeMounts:
      #   - mountPath: /shared
      #     name: sharedvolume

      # - name: chaincodeinstall3
      #   image: hyperledger/fabric-tools:1.4
      #   imagePullPolicy: Always
      #   command: ["sh", "-c", "echo $GOPATH; cp -r /shared/artifacts/chaincode $GOPATH/src/; ls $GOPATH/src; peer chaincode install -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p chaincode_example02/"]
      #   env:
      #   - name: CHAINCODE_NAME
      #     value: "cc"
      #   - name: CHAINCODE_VERSION
      #     value: "1.0"
      #   - name: FABRIC_CFG_PATH
      #     value: /etc/hyperledger/fabric
      #   - name: CORE_PEER_MSPCONFIGPATH
      #     value: /shared/crypto-config/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp
      #   - name: CORE_PEER_LOCALMSPID
      #     value: Org3MSP
      #   - name: CORE_PEER_ADDRESS
      #     value: blockchain-org3peer1:9051
      #   - name: GODEBUG
      #     value: "netdns=go"
      #   volumeMounts:
      #   - mountPath: /shared
      #     name: sharedvolume

      # - name: chaincodeinstall4
      #   image: hyperledger/fabric-tools:1.4
      #   imagePullPolicy: Always
      #   command: ["sh", "-c", "echo $GOPATH; cp -r /shared/artifacts/chaincode $GOPATH/src/; ls $GOPATH/src; peer chaincode install -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p chaincode_example02/"]
      #   env:
      #   - name: CHAINCODE_NAME
      #     value: "cc"
      #   - name: CHAINCODE_VERSION
      #     value: "1.0"
      #   - name: FABRIC_CFG_PATH
      #     value: /etc/hyperledger/fabric
      #   - name: CORE_PEER_MSPCONFIGPATH
      #     value: /shared/crypto-config/peerOrganizations/org4.example.com/users/Admin@org4.example.com/msp
      #   - name: CORE_PEER_LOCALMSPID
      #     value: Org4MSP
      #   - name: CORE_PEER_ADDRESS
      #     value: blockchain-org4peer1:10051
      #   - name: GODEBUG
      #     value: "netdns=go"
      #   volumeMounts:
      #   - mountPath: /shared
      #     name: sharedvolume
      hostAliases:
      - ip: "10.107.46.145"
        hostnames:
        - "blockchain-org1peer1"
      - ip: "10.107.47.145"
        hostnames:
        - "blockchain-org2peer1"
      - ip: "10.107.48.145"
        hostnames:
        - "blockchain-org3peer1"
      - ip: "10.107.49.145"
        hostnames:
        - "blockchain-org4peer1"