Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/db-table-dump.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
kubectl -n credreg-prod wait \
--for=condition=complete \
"job/${{ steps.create_job.outputs.job_name }}" \
--timeout=30m
--timeout=4h

- name: Get presigned URL
id: presign
Expand Down Expand Up @@ -99,12 +99,13 @@ jobs:
STATUS="${{ job.status }}"
TABLE="${{ inputs.table_name }}"
ACTOR="${{ github.actor }}"
NL=$'\n'

if [ "$STATUS" = "success" ]; then
PRESIGNED_URL="${{ steps.presign.outputs.presigned_url }}"
MSG=":white_check_mark: *DB dump ready* | table: \`${TABLE}\` | triggered by: ${ACTOR}\nDownload (expires in 1h): ${PRESIGNED_URL}\n${RUN_URL}"
MSG=":white_check_mark: *DB dump ready*${NL}• Table: \`${TABLE}\`${NL}• Triggered by: ${ACTOR}${NL}• <${PRESIGNED_URL}|Download SQL dump> _(expires in 1h)_${NL}• <${RUN_URL}|View run>"
else
MSG=":x: *DB dump failed* | table: \`${TABLE}\` | triggered by: ${ACTOR}\n${RUN_URL}"
MSG=":x: *DB dump failed*${NL}• Table: \`${TABLE}\`${NL}• Triggered by: ${ACTOR}${NL}• <${RUN_URL}|View run>"
fi

payload=$(jq -nc --arg text "$MSG" '{text:$text}')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ metadata:
app: db-table-dump
spec:
backoffLimit: 0
activeDeadlineSeconds: 1800
activeDeadlineSeconds: 14400
ttlSecondsAfterFinished: 300
template:
spec:
serviceAccountName: main-app-service-account
restartPolicy: Never
containers:
- name: pg-dump
image: postgres:16-alpine
image: postgres:17-alpine
command: ["/bin/sh", "-c"]
args:
- |
Expand All @@ -24,8 +24,7 @@ spec:
apk add --no-cache aws-cli >/dev/null 2>&1

TIMESTAMP=$(date +%Y%m%d_%H%M%S)
DUMP_FILE="/tmp/${TABLE_NAME}_${TIMESTAMP}.dump"
S3_KEY="table-dumps/${TABLE_NAME}/${TIMESTAMP}.dump"
S3_KEY="table-dumps/${TABLE_NAME}/${TIMESTAMP}.sql.gz"

echo "Dumping table '${TABLE_NAME}' from ${POSTGRESQL_DATABASE}..."
PGPASSWORD="${POSTGRESQL_PASSWORD}" pg_dump \
Expand All @@ -35,11 +34,12 @@ spec:
-p "${POSTGRESQL_PORT:-5432}" \
--table "${TABLE_NAME}" \
--no-owner --no-acl \
-Fc \
-f "${DUMP_FILE}"

echo "Uploading to s3://${S3_DUMP_BUCKET}/${S3_KEY}"
aws s3 cp "${DUMP_FILE}" "s3://${S3_DUMP_BUCKET}/${S3_KEY}" --region us-east-1
-Fp | \
gzip | \
aws s3 cp - "s3://${S3_DUMP_BUCKET}/${S3_KEY}" \
--region us-east-1 \
--content-encoding gzip \
--content-type "text/plain"

echo "S3_KEY=${S3_KEY}"
env:
Expand All @@ -50,3 +50,5 @@ spec:
envFrom:
- secretRef:
name: app-secrets
- configMapRef:
name: main-app-config
Loading