---
apiVersion: batch/v1
kind: Job
metadata:
  name: copyartifacts
spec:
  backoffLimit: 1
  template:
    metadata:
      name: copyartifacts
    spec:
      restartPolicy: "Never"
      volumes:
      - name: sharedvolume
        persistentVolumeClaim:
          claimName: shared-pvc
      - name: sharedartifactvolume
        persistentVolumeClaim:
          claimName: shared-artifacts-pvc
      - name: dockersocket
        hostPath:
          path: /var/run/docker.sock
      containers:
      - name: copyartifacts
        image: alpine:3.7
        imagePullPolicy: Always
        command: ["sh", "-c", 
        "ls -l /shared; 
          rm -rf /shared/*; 
          ls -l /shared; 
          mkdir -p /shared/artifacts;
          cp -r /artifacts/* /shared/artifacts/;
          # while [ ! -f /shared/artifacts_complete ];
          # do echo Waiting for artifacts to be copied;
          # sleep 2;
          # done; sleep 10; 
          ls -l /shared/artifacts/*/*; 
        "]
        resources:
          limits:
            cpu: 1
            memory: 1000Mi
          requests:
            cpu: 500m
            memory: 256Mi
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume
        - mountPath: /artifacts
          name: sharedartifactvolume
      tolerations:
      - key: dedicated
        operator: Exists
        effect: NoSchedule