apiVersion: batch/v1
kind: Job
metadata:
  name: guix-image-workstation
  annotations:
    # Setting spec.force to true will make Flux recreate the Job when any
    # immutable field is changed, forcing the Job to run every time the
    # container image tag changes.
    kustomize.toolkit.fluxcd.io/force: enabled
spec:
  backoffLimit: 0
  template:
    spec:
      hostNetwork: true
      hostPID: true
      restartPolicy: Never
      containers:
      - command:
        - /bin/sh
        - -c
        - |
          nsenter --target "1" --mount --uts --ipc --net --pid --no-fork \
          /run/setuid-programs/sudo --user=oleg --login bash <<'EOF'
          set -o nounset -o errexit -o pipefail -o xtrace
          image=$(~/src/git.savannah.gnu.org/git/guix.32bd53c/pre-inst-env guix system image --load-path=/home/oleg/.local/share/chezmoi/dotfiles/guixsd/modules -t docker --network ~/.local/share/chezmoi/dotfiles/guixsd/guix-image-workstation.scm)
          skopeo copy docker-archive:${image} docker://harbor.home.wugi.info/library/guix-image-workstation:latest
          EOF
        image: docker-registry.wugi.info/library/util-linux-with-udev
        name: refresh
        resources:
          limits:
            cpu: 14000m
            memory: 4096Mi
          requests:
            cpu: 1000m
            memory: 512Mi
        securityContext:
          privileged: true
