apiVersion: batch/v1
kind: Job
metadata:
  name: cloud-image-creator
spec:
  template:
    spec:
      containers:
      - name: docker-image-creator
        image: harbor.crownlabs.polito.it/crownlabs-cloud-vms/docker_image_creator:v0.5.5
        securityContext:
          privileged: true
        resources:
          requests:
            memory: "12Gi"
            cpu: "4000m"
          limits:
            memory: "16Gi"
            cpu: "4500m"
        env:
        - name: IMAGE_NAME
          value: <output-image>
        - name: USERNAME
          value: <registry-username>
        - name: PASSWORD
          value: <registry-password>
        volumeMounts:
        - mountPath: /images
          name: images
      restartPolicy: OnFailure
      initContainers:
      - name: packer-image-creator
        image: harbor.crownlabs.polito.it/crownlabs-cloud-vms/packer_image_creator:v0.5.5
        securityContext:
          privileged: true
        resources:
          requests:
            memory: "12Gi"
            cpu: "4000m"
          limits:
            memory: "16Gi"
            cpu: "4500m"
        env:
        - name: ISO_URL
          value: https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img
        - name: ISO_CHECKSUM
          value: sha256:826743a5b7aab6e5bf9253d99436daee757361ed05246225abb0054a0429b14b
        - name: INSTALL_DESKTOP_ENVIRONMENT
          value: "true" # set it to "false" to install the server version
        - name: ANSIBLE_PLAYBOOK
          value: ubuntu-base.yml
        - name: GIT_ANSIBLE_URL
          value: https://github.com/netgroup-polito/CrownLabs.git
        volumeMounts:
        - mountPath: /packer_builder/output
          name: images
      volumes:
      - name: images
        emptyDir: {}
  backoffLimit: 4
