---
apiVersion: batch/v1
kind: Job
metadata:
  name: createchannelonly
spec:
  backoffLimit: 1
  template:
    metadata:
      name: createchannelonly
    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 TwoOrgsChannel -outputCreateChannelTx ${CHANNEL_NAME}.tx -channelID ${CHANNEL_NAME} && touch /shared/status_channeltx_complete "]
      #   env:
      #   - name: CHANNEL_NAME
      #     value: example
      #   - 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} -f /shared/${CHANNEL_NAME}.tx --outputBlock /shared/${CHANNEL_NAME}.block --tls --cafile /shared/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem && rm /shared/status_channeltx_complete && touch /shared/status_channelcreate_complete"]
        env:
        - name: CHANNEL_NAME
          value: example
        - name: ORDERER_URL
          value: orderer:31010
        - name: CORE_PEER_ADDRESSAUTODETECT
          value: "true"
        - name: CORE_PEER_NETWORKID
          value: nid1
        - name: CORE_PEER_LOCALMSPID
          value: Org1MSP
        - name: CORE_PEER_MSPCONFIGPATH
          value: /shared/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/
        - name: FABRIC_LOGGING_SPEC
          value: debug
        - name: FABRIC_CFG_PATH
          value: /etc/hyperledger/fabric
        - name: CORE_PEER_TLS_ENABLED
          value: "true"
        - name: CORE_PEER_TLS_KEY_FILE
          value: /shared/crypto-config/peerOrganizations/org1.example.com/peers/org1peer0.org1.example.com/tls/server.key
        - name: CORE_PEER_TLS_CERT_FILE
          value: /shared/crypto-config/peerOrganizations/org1.example.com/peers/org1peer0.org1.example.com/tls/server.crt
        - name: CORE_PEER_TLS_ROOTCERT_FILE
          value: /shared/crypto-config/peerOrganizations/org1.example.com/peers/org1peer0.org1.example.com/tls/ca.crt
        - name: GODEBUG
          value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume

  