---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: centos-xfce-ja
spec:
  serviceName: centos-xfce-ja
  selector:
    matchLabels:
      app: centos-xfce-ja
  replicas: 1
  template:
    metadata:
      labels:
        app: centos-xfce-ja
    spec:
      shareProcessNamespace: true
      enableServiceLinks: false
      automountServiceAccountToken: false
      initContainers:
      - name: init
        image: tmatsuo/centos-xfce-ja
        volumeMounts:
        - name: centos-xfce-ja
          mountPath: /volume
        command: ["/bin/bash", "-c"]
        args:
        - "
          if [ ! -d /volume/root ]; then
              echo copying root dir;
              cp -a -n /root /volume/;
          else
              echo skip copying root dir;
          fi;
          if [ ! -d /volume/usr ]; then
              echo copying usr dir;
              cp -a -n /usr /volume/;
          else
              echo skip copying usr dir; fi;
          if [ ! -d /volume/etc ]; then
              echo copying etc dir;
              cp -a -n /etc /volume/;
          else
              echo skip copying etc dir;
          fi;
          if [ ! -d /volume/var ]; then
              echo copying var dir;
              cp -a -n /var /volume/;
          else
              echo skip copying var dir;
          fi;
          if [ ! -d /volume/run ]; then
              echo copying run dir;
              cp -a -n /run /volume/;
          else
              echo skip copying run dir;
          fi;
          if [ ! -d /volume/home ]; then
              echo copying home dir;
              cp -a -n /home /volume/;
          else
              echo skip copying home dir;
          fi;
          if [ ! -d /volume/opt ]; then
              echo copying opt dir;
              cp -a -n /opt /volume/;
          else
              echo skip copying opt dir;
          fi;
          if [ ! -d /volume/srv ]; then
              echo copying srv dir;
              cp -a -n /srv /volume/;
          else
              echo skip copying srv dir;
          fi;
          if [ ! -d /volume/headless ]; then
              echo copying headless dir;
              cp -a -n /headless /volume/;
          else
              echo skip copying headless dir;
          fi;
          "
      containers:
      - name: centos
        image: tmatsuo/centos-xfce-ja
        livenessProbe:
          exec:
            command:
            - "curl"
            - "-s"
            - "-f"
            - "--insecure"
            - "-o"
            - "/dev/null"
            - "http://127.0.0.1:8080/desktop/vnc_lite.html"
            - "&&"
            - curl
            - "-s"
            - "-f"
            - "--insecure"
            - "-o"
            - "/dev/null"
            - "http://127.0.0.1:8080/term/static/main.css"
          initialDelaySeconds: 10
          failureThreshold: 3
          periodSeconds: 20
          timeoutSeconds: 5
        env:
        - name: PASSWORD
          value: password
        - name: PORT
          value: "8080"
        - name: VNC_RESOLUTION
          value: "1800x850"
        - name: NOSSL
          value: "true"
        - name: DISABLE_DESKTOP
          value: "false"
        - name: DISABLE_TERMINAL
          value: "false"
        - name: DISABLE_FILER
          value: "false"
        - name: DISABLE_SSH
          value: "false"
        - name: DISABLE_RDP
          value: "false"
        - name: DOCKER_HOST
          value: tcp://localhost:2375
        volumeMounts:
        - name: centos-xfce-ja
          mountPath: "/volume"
        - name: centos-xfce-ja
          subPath: "root"
          mountPath: "/root"
        - name: centos-xfce-ja
          subPath: "usr"
          mountPath: "/usr"
        - name: centos-xfce-ja
          subPath: "etc"
          mountPath: "/etc"
        - name: centos-xfce-ja
          subPath: "var"
          mountPath: "/var"
        - name: centos-xfce-ja
          subPath: "run"
          mountPath: "/run"
        - name: centos-xfce-ja
          subPath: "home"
          mountPath: "/home"
        - name: centos-xfce-ja
          subPath: "opt"
          mountPath: "/opt"
        - name: centos-xfce-ja
          subPath: "srv"
          mountPath: "/srv"
        - name: centos-xfce-ja
          subPath: "headless"
          mountPath: "/headless"
        - name: centos-xfce-ja
          subPath: "share"
          mountPath: "/share"
        - name: shm
          mountPath: "/dev/shm"
      - name: docker
        image: docker:stable-dind
        args: ["--insecure-registry", "registry:5000"]
        env:
          - name: DOCKER_TLS_CERTDIR
            value: ""
          - name: DOCKER_HOST
            value: "tcp://127.0.0.1:2375"
#        resources:
#          requests:
#            cpu: 20m
#            memory: 4096Mi
        securityContext:
          privileged: true
        volumeMounts:
        - name: centos-xfce-ja
          subPath: "docker"
          mountPath: "/var/lib/docker"
        - name: centos-xfce-ja
          subPath: "share"
          mountPath: "/share"
      volumes:
      - name: centos-xfce-ja
        persistentVolumeClaim:
          claimName: centos-xfce-ja
      - name: shm
        emptyDir:
          medium: Memory
