apiVersion: batch/v1
kind: Job
metadata:
  name: geoip-db-init
spec:
  template:
    metadata:
      creationTimestamp: null
    spec:
      containers:
      - command:
        - sh
        - -c
        - |
          wget -O geoip.tar.gz "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=${API_KEY}&suffix=tar.gz" && \
          tar -C /tmp -xvzf geoip.tar.gz && rm geoip.tar.gz && \
          wget -O geoip.tar.gz "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=${API_KEY}&suffix=tar.gz" && \
          tar -C /tmp -xvzf geoip.tar.gz && rm geoip.tar.gz && \
          wget -O geoip.tar.gz "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=${API_KEY}&suffix=tar.gz" && \
          tar -C /tmp -xvzf geoip.tar.gz && rm geoip.tar.gz && \
          find /tmp -name '*.mmdb' -exec cp {} /data/geoip \;
        image: busybox
        name: geoip-db-init
        env:
        - name: API_KEY
          valueFrom:
            secretKeyRef:
              name: maxmind-api-key
              key: API_KEY
        volumeMounts:
        - name: geoip
          mountPath: /data/geoip
      volumes:
      - name: geoip
        persistentVolumeClaim:
          claimName: ipapi-geodb
      restartPolicy: Never
