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