---
apiVersion: batch/v1
kind: Job
metadata:
  namespace: fabric
  name: createchannel
spec:
  backoffLimit: 1
  template:
    metadata:
      name: createchannel
    spec:
      restartPolicy: "Never"
      volumes:
      - name: sharedvolume
        persistentVolumeClaim:
          claimName: shared-pvc
      containers:
      - name: createchanneltx
        image: hyperledger/fabric-tools:x86_64-1.1.0
        command: ["sh", "-c", "cd /shared && pwd && ls && export FABRIC_CFG_PATH=$PWD && configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ${CHANNEL_NAME}.tx -channelID ${CHANNEL_NAME} && configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate Org1MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org1MSP && configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate Org2MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org2MSP && touch /shared/status_channeltx_complete "]
        env:
        - name: CHANNEL_NAME
          value: iphchannel
        - name: GODEBUG
          value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume

      - name: createchannel
        image: hyperledger/fabric-peer:x86_64-1.1.0
        command: ["sh", "-c", "while [ ! -f /shared/status_channeltx_complete ]; do echo Waiting for channeltx; sleep 2; done; peer channel create -o ${ORDERER_URL} -c ${CHANNEL_NAME} -f /shared/${CHANNEL_NAME}.tx -t 60 && rm /shared/status_channeltx_complete && touch /shared/status_channelcreate_complete"]
        env:
        - name: CHANNEL_NAME
        # changed channel name
          value: iphchannel
        - name: ORDERER_URL
          value: orderer0.ordererorg1:7050
        - name: CORE_PEER_ADDRESSAUTODETECT
          value: "false"
        - name: CORE_PEER_LOCALMSPID
          value: Org1MSP
        - name: CORE_PEER_MSPCONFIGPATH
          value: /shared/crypto-config/peerOrganizations/org1/users/Admin@org1/msp/
        - name: CORE_LOGGING_LEVEL
          value: debug
        - name: FABRIC_CFG_PATH
          value: /etc/hyperledger/fabric
        - name: GODEBUG
          value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume
