Skip to content

Instantly share code, notes, and snippets.

@rm3l
Created March 13, 2021 22:30
Show Gist options
  • Save rm3l/b8a02f5355b63b9050eb6ba48c910dac to your computer and use it in GitHub Desktop.
Save rm3l/b8a02f5355b63b9050eb6ba48c910dac to your computer and use it in GitHub Desktop.
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: ghost-s3-export-cron-job
spec:
schedule: "@daily"
concurrencyPolicy: Forbid
jobTemplate:
spec:
ttlSecondsAfterFinished: 300
backoffLimit: 1
parallelism: 1
template:
spec:
restartPolicy: OnFailure
volumes:
- name: export-data
emptyDir: {}
initContainers:
- name: download-glorious-json-from-ghost
image: curlimages/curl:7.74.0
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- |
curl --fail -sSL -c /tmp/ghost-cookie.txt \
-d username='$(GHOST_AUTH_USERNAME)' \
-d password='$(GHOST_AUTH_PASSWORD)' \
-H 'Origin: ghost-export-to-s3-job' \
'$(GHOST_URL)'/api/v3/admin/session/ && \
curl --fail -sSL -b /tmp/ghost-cookie.txt \
-H 'Origin: ghost-export-to-s3-job' \
-H 'Content-Type: application/json' \
'$(GHOST_URL)'/api/v3/admin/db/ \
-o /data/ghost-export/ghost-export.json && \
rm -rf /tmp/ghost-cookie.txt
env:
- name: GHOST_URL
valueFrom:
configMapKeyRef:
name: ghost-export-k8s-to-s3-configmap
key: GHOST_URL
- name: GHOST_AUTH_USERNAME
valueFrom:
secretKeyRef:
name: ghost-export-k8s-to-s3-secret
key: GHOST_AUTH_USERNAME
- name: GHOST_AUTH_PASSWORD
valueFrom:
secretKeyRef:
name: ghost-export-k8s-to-s3-secret
key: GHOST_AUTH_PASSWORD
volumeMounts:
- name: export-data
mountPath: /data/ghost-export
containers:
- name: export-ghost-json-to-s3
image: amazon/aws-cli:2.1.15
imagePullPolicy: IfNotPresent
args:
- s3
- cp
- "/data/to-export/ghost-export.json"
- "$(S3_DESTINATION)"
env:
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: ghost-export-k8s-to-s3-secret
key: AWS_ACCESS_KEY_ID
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: ghost-export-k8s-to-s3-secret
key: AWS_SECRET_ACCESS_KEY
- name: S3_DESTINATION
valueFrom:
configMapKeyRef:
name: ghost-export-k8s-to-s3-configmap
key: S3_DESTINATION
volumeMounts:
- name: export-data
mountPath: /data/to-export
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment