---
apiVersion: batch/v1
kind: Job
metadata:
  name: utils
spec:
  backoffLimit: 1
  template:
    metadata:
      name: utils
    spec:
      restartPolicy: "Never"
      volumes:
      - name: sharedvolume
        persistentVolumeClaim:
          claimName: shared-pvc
      - name: dockersocket
        hostPath:
          path: /var/run/docker.sock
      containers:
      - name: cryptogen
        image: hyperledger/fabric-tools:1.3.0
        imagePullPolicy: Always
        command: ["sh", "-c", "echo 'Cryptogen Starts'; ls -l /opt/shared/artifacts; while [ ! -d /opt/shared/artifacts ]; do echo Waiting for configFiles; sleep 1; done; cryptogen generate --config /opt/shared/artifacts/crypto-config.yaml && cp -r crypto-config /opt/shared/ && for file in $(find /opt/shared/ -iname *_sk); do echo $file; dir=$(dirname $file); echo ${dir}; mv ${dir}/*_sk ${dir}/key.pem; done && touch /opt/shared/status_cryptogen_complete;"]
        volumeMounts:
        - mountPath: /opt/shared
          name: sharedvolume
      - name: configtxgen
        image: hyperledger/fabric-tools:1.3.0
        imagePullPolicy: Always
        command: ["sh", "-c", "echo 'Configtxgen Starts'; ls -l /opt/shared; sleep 1 && while [ ! -f /opt/shared/status_cryptogen_complete ]; do echo Waiting for cryptogen; sleep 1; done; cp /opt/shared/artifacts/configtx.yaml /opt/shared/; cd /opt/shared/; export FABRIC_CFG_PATH=$PWD; configtxgen -profile TwoOrgsOrdererGenesis -outputBlock genesis.block && touch /opt/shared/status_configtxgen_complete && rm /opt/shared/status_cryptogen_complete;"]
        volumeMounts:
        - mountPath: /opt/shared
          name: sharedvolume
