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

      - name: createchannel
        image: hyperledger/fabric-peer:1.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 ${CHANNEL_NAME} --tls --cafile ${CA_FILE} -f /shared/${CHANNEL_NAME}.tx && rm /shared/status_channeltx_complete && touch /shared/status_channelcreate_complete"]
        env:
        - name: CHANNEL_NAME
          value: channel1
        - name: CORE_PEER_TLS_ENABLED
          value: "true"
        - name: CA_FILE
          value: /shared/crypto-config/ordererOrganizations/blockchain-orderer/orderers/blockchain-orderer/tls/ca.crt
        - name: ORDERER_URL
          value: blockchain-orderer:31010
        - name: CORE_PEER_ADDRESSAUTODETECT
          value: "false"
        - name: CORE_PEER_NETWORKID
          value: nid1
        - name: CORE_PEER_LOCALMSPID
          value: Org1MSP
        - name: CORE_PEER_MSPCONFIGPATH
          value: /shared/crypto-config/peerOrganizations/org1.example.com/peers/blockchain-org1peer1/msp/
        - name: FABRIC_LOGGING_SPEC
          value: debug
        - name: FABRIC_CFG_PATH
          value: /etc/hyperledger/fabric
        - name: GODEBUG
          value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume
      nodeSelector:
        kops.k8s.io/instancegroup: blockchain-nodes