---
apiVersion: batch/v1
kind: Job
metadata:
  name: chaincodeupgrade
spec:
  backoffLimit: 1
  template:
    metadata:
      name: chaincodeupgrade
    spec:
      restartPolicy: "Never"
      volumes:
      - name: sharedvolume
        persistentVolumeClaim:
          claimName: common-pvc
      containers:
      - name: chaincodeupgrade1
        image: hyperledger/fabric-tools:1.3.0
        imagePullPolicy: Always
        command: ["sh", "-c", "echo $GOPATH; mkdir -p $GOPATH/src/github.com/lgsvl; cp -r /shared/artifacts/chaincode $GOPATH/src/github.com/lgsvl; $GOPATH/src/github.com/lgsvl; peer chaincode upgrade -o ${ORDERER_URL} -C ${CHANNEL_NAME} -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p github.com/lgsvl/data-marketplace-chaincode -c '{\"Args\":[\"init\",\"dmpoken\",\"10000\"]}'"]
        env:
        - name: CHANNEL_NAME
          value: dmp
        - name: CHAINCODE_NAME
          value: "dmp"
        - name: CHAINCODE_VERSION
          value: $VERSION
        - name: FABRIC_CFG_PATH
          value: /etc/hyperledger/fabric
        - name: ORDERER_URL
          value: blockchain-orderer:31010
        - 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:30110
        - name: GODEBUG
          value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume

      - name: chaincodeupgrade2
        image: hyperledger/fabric-tools:1.3.0
        imagePullPolicy: Always
        command: ["sh", "-c", "echo $GOPATH; mkdir -p $GOPATH/src/github.com/lgsvl; cp -r /shared/artifacts/chaincode $GOPATH/src/github.com/lgsvl; $GOPATH/src/github.com/lgsvl; peer chaincode upgrade -o ${ORDERER_URL} -C ${CHANNEL_NAME} -n ${CHAINCODE_NAME} -v ${CHAINCODE_VERSION} -p github.com/lgsvl/data-marketplace-chaincode -c '{\"Args\":[\"init\",\"dmpoken\",\"10000\"]}'"]
        env:
        - name: CHANNEL_NAME
          value: dmp
        - name: CHAINCODE_NAME
          value: "dmp"
        - name: CHAINCODE_VERSION
          value: $VERSION
        - name: FABRIC_CFG_PATH
          value: /etc/hyperledger/fabric
        - name: ORDERER_URL
          value: blockchain-orderer:31010
        - 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:30210
        - name: GODEBUG
          value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume