---
apiVersion: batch/v1
kind: Job
metadata:
  namespace: cadanac-v0-1
  name: createchannel
spec:
  backoffLimit: 1
  template:
    metadata:
      name: createchannel
    spec:
      restartPolicy: "Never"
      volumes:
      - name: cadanacvolume
        persistentVolumeClaim:
          claimName: cadanac-pvc
      containers:
      - name: createchanneltx
        image: hyperledger/fabric-tools:1.4.4
        imagePullPolicy: Always
        command: ["sh", "-c", "cd /shared && pwd && ls && export FABRIC_CFG_PATH=$PWD && configtxgen -profile ProfilePersonLocation -outputCreateChannelTx channelpersonlocation.tx -channelID channelpersonlocation && configtxgen -profile ProfilePersonHealth -outputCreateChannelTx channelpersonhealth.tx -channelID channelpersonhealth && configtxgen -profile ProfileHealthFinance -outputCreateChannelTx channelhealthfinance.tx -channelID channelhealthfinance && touch /shared/status_channeltx_complete "]
        env:
        - name: GODEBUG
          value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: cadanacvolume

      - name: createchannel
        image: hyperledger/fabric-peer:1.4.4
        imagePullPolicy: Always
        command: ["sh", "-c", "while [ ! -f /shared/status_channeltx_complete ]; do echo Waiting for channeltx; sleep 2; done; peer channel create -o ${ORDERER_URL} -c channelpersonlocation -f /shared/channelpersonlocation.tx && peer channel create -o ${ORDERER_URL} -c channelpersonhealth -f /shared/channelpersonhealth.tx && peer channel create -o ${ORDERER_URL} -c channelhealthfinance -f /shared/channelhealthfinance.tx && rm /shared/status_channeltx_complete && touch /shared/status_channelcreate_complete"]
        env:
        - name: ORDERER_URL
          value: blockchain-orderer:31010
        - name: CORE_PEER_ADDRESSAUTODETECT
          value: "false"
        - name: CORE_PEER_NETWORKID
          value: nid1
        - name: CORE_PEER_LOCALMSPID
          value: Government1MSP
        - name: CORE_PEER_MSPCONFIGPATH
          value: /shared/crypto-config/peerOrganizations/government1.example.com/peers/peer0.government1.example.com/msp/
        - name: FABRIC_LOGGING_SPEC
          value: debug
        - name: FABRIC_CFG_PATH
          value: /etc/hyperledger/fabric
        - name: GODEBUG
          value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: cadanacvolume
