6f5644e6 by Adam Heath

Add many more tasks that are needed for transformation scripts in a

pipeline.
1 parent 41835ac9
......@@ -4,6 +4,9 @@ kind: Kustomization
resources:
- ./service-account.yaml
- ./task-postgresql-pod.yaml
- ./task-postgresql-create-databases-users.yaml
- ./task-postgresql-import.yaml
- ./task-postgresql-export.yaml
configMapGenerator:
- name: task-postgresql-pod-kustomization
......@@ -14,5 +17,13 @@ configMapGenerator:
- postgresql-pod_postgresql-pod.yaml=postgresql-pod/postgresql-pod.yaml
- postgresql-pod_set-deployment-config_deployment-config.env=postgresql-pod/set-deployment-config/deployment-config.env
- postgresql-pod_set-deployment-config_kustomization.yaml=postgresql-pod/set-deployment-config/kustomization.yaml
- name: task-postgresql-scripts
options:
disableNameSuffixHash: true
files:
- scripts/create-databases-users.sh
- scripts/export-dumps.sh
- scripts/import-dumps.sh
- scripts/wait-for-postgresql.sh
---
......
#!/bin/bash
set -ex
mode=
touch /tmp/pgpass
chmod 0600 /tmp/pgpass
echo "*:*:*:*:CHANGEME" > /tmp/pgpass
export PGPASSFILE=/tmp/pgpass
while [[ $# -gt 0 ]]; do
case "$1" in
(--databases)
mode="databases"
;;
(--users)
mode="users"
;;
(--*)
echo "Unknown mode: $1" 1>&2
exit 1
;;
(*)
case "$mode" in
(databases)
createdb -w -h ${POSTGRESQL_HOST} -U postgres "$1"
;;
(users)
createuser -w -h ${POSTGRESQL_HOST} -U postgres "$1"
;;
esac
;;
esac
shift
done
#!/bin/bash
set -ex
touch /tmp/pgpass
chmod 0600 /tmp/pgpass
echo "*:*:*:*:CHANGEME" > /tmp/pgpass
export PGPASSFILE=/tmp/pgpass
ls /workspace
for database in "$@"; do
pg_dump -w -h ${POSTGRESQL_HOST} -U postgres "$database" | gzip -9v > "/workspace/exports/$database.gz"
done
#!/bin/bash
set -ex
touch /tmp/pgpass
chmod 0600 /tmp/pgpass
echo "*:*:*:*:CHANGEME" > /tmp/pgpass
export PGPASSFILE=/tmp/pgpass
_import() {
psql -w -h ${POSTGRESQL_HOST} -U postgres "$1"
}
ls -alR /workspace
for file in /workspace/imports/*; do
[[ -e $file ]] || continue
case "$file" in
(*.sql.gz)
database="$(basename "$file" .sql.gz)"
zcat "$file" | _import "$database"
;;
(*.sql)
database="$(basename "$file" .sql)"
cat "$file" | _import "$database"
;;
(*)
echo "Ignoring file: $file"
;;
esac
done
#!/bin/sh
set -ex
check_pg() {
pg_isready -h ${POSTGRESQL_HOST} -U postgres
}
while ! check_pg; do
echo "Waiting for database" 1>&2
sleep 1
count=5
while [ $count -gt 0 ] && ! check_pg; do
count=$(($count - 1))
sleep 1
done
done
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: task-postgresql-create-databases-users
spec:
params:
- name: databases
type: array
- name: users
type: array
- name: POSTGRESQL_HOST
type: string
- name: postgresql-image
type: string
default: bitnami/postgresql:14.1.0-debian-10-r66
volumes:
- name: task-postgresql-scripts
configMap:
name: task-postgresql-scripts
defaultMode: 0755
steps:
- name: wait-for-start
image: $(params.postgresql-image)
command: ["/scripts/wait-for-postgresql.sh"]
env:
- name: POSTGRESQL_HOST
value: $(params.POSTGRESQL_HOST)
volumeMounts:
- name: task-postgresql-scripts
mountPath: /scripts
- name: create-databases-users
image: $(params.postgresql-image)
command: ["/scripts/create-databases-users.sh"]
args: ["--databases", "$(params.databases[*])", "--users", "$(params.users[*])"]
env:
- name: POSTGRESQL_HOST
value: $(params.POSTGRESQL_HOST)
volumeMounts:
- name: task-postgresql-scripts
mountPath: /scripts
---
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: task-postgresql-export
spec:
params:
- name: exports
type: array
- name: POSTGRESQL_HOST
type: string
- name: postgresql-image
type: string
default: bitnami/postgresql:14.1.0-debian-10-r66
workspaces:
- name: exports
description: The database exports will be placed in this workspace.
volumes:
- name: task-postgresql-scripts
configMap:
name: task-postgresql-scripts
defaultMode: 0755
steps:
- name: wait-for-start
image: $(params.postgresql-image)
command: ["/scripts/wait-for-postgresql.sh"]
env:
- name: POSTGRESQL_HOST
value: $(params.POSTGRESQL_HOST)
volumeMounts:
- name: task-postgresql-scripts
mountPath: /scripts
- name: exports
image: $(params.postgresql-image)
command: ["/scripts/export-dumps.sh", "$(params.exports[*])"]
env:
- name: POSTGRESQL_HOST
value: $(params.POSTGRESQL_HOST)
volumeMounts:
- name: task-postgresql-scripts
mountPath: /scripts
---
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: task-postgresql-import
spec:
params:
- name: POSTGRESQL_HOST
type: string
- name: postgresql-image
type: string
default: bitnami/postgresql:14.1.0-debian-10-r66
workspaces:
- name: imports
description: Place any input database dump files here
volumes:
- name: task-postgresql-scripts
configMap:
name: task-postgresql-scripts
defaultMode: 0755
steps:
- name: wait-for-start
image: $(params.postgresql-image)
command: ["/scripts/wait-for-postgresql.sh"]
env:
- name: POSTGRESQL_HOST
value: $(params.POSTGRESQL_HOST)
volumeMounts:
- name: task-postgresql-scripts
mountPath: /scripts
- name: imports
image: $(params.postgresql-image)
command: ["/scripts/import-dumps.sh"]
env:
- name: POSTGRESQL_HOST
value: $(params.POSTGRESQL_HOST)
volumeMounts:
- name: task-postgresql-scripts
mountPath: /scripts
---