Added task-postgresql-transformer.
Showing
3 changed files
with
76 additions
and
0 deletions
... | @@ -6,6 +6,7 @@ resources: | ... | @@ -6,6 +6,7 @@ resources: |
6 | - ./task-postgresql-pod.yaml | 6 | - ./task-postgresql-pod.yaml |
7 | - ./task-postgresql-create-databases-users.yaml | 7 | - ./task-postgresql-create-databases-users.yaml |
8 | - ./task-postgresql-import.yaml | 8 | - ./task-postgresql-import.yaml |
9 | - ./task-postgresql-transformer.yaml | ||
9 | - ./task-postgresql-export.yaml | 10 | - ./task-postgresql-export.yaml |
10 | 11 | ||
11 | configMapGenerator: | 12 | configMapGenerator: |
... | @@ -24,6 +25,7 @@ configMapGenerator: | ... | @@ -24,6 +25,7 @@ configMapGenerator: |
24 | - scripts/create-databases-users.sh | 25 | - scripts/create-databases-users.sh |
25 | - scripts/export-dumps.sh | 26 | - scripts/export-dumps.sh |
26 | - scripts/import-dumps.sh | 27 | - scripts/import-dumps.sh |
28 | - scripts/transformations.sh | ||
27 | - scripts/wait-for-postgresql.sh | 29 | - scripts/wait-for-postgresql.sh |
28 | 30 | ||
29 | --- | 31 | --- | ... | ... |
scripts/transformations.sh
0 → 100644
1 | #!/bin/bash | ||
2 | |||
3 | set -ex | ||
4 | |||
5 | touch /tmp/pgpass | ||
6 | chmod 0600 /tmp/pgpass | ||
7 | echo "*:*:*:*:CHANGEME" > /tmp/pgpass | ||
8 | export PGPASSFILE=/tmp/pgpass | ||
9 | |||
10 | _import() { | ||
11 | psql -w -h ${POSTGRESQL_HOST} -U postgres "$1" | ||
12 | } | ||
13 | |||
14 | ls -alR /workspace | ||
15 | for file in /workspace/transformations/*; do | ||
16 | [[ -e $file ]] || continue | ||
17 | case "$file" in | ||
18 | (*.sql.gz) | ||
19 | database="$(basename "$file" .sql.gz)" | ||
20 | zcat "$file" | _import "$database" | ||
21 | ;; | ||
22 | (*.sql) | ||
23 | database="$(basename "$file" .sql)" | ||
24 | cat "$file" | _import "$database" | ||
25 | ;; | ||
26 | (*.sh) | ||
27 | "$file" | ||
28 | ;; | ||
29 | (*) | ||
30 | echo "Ignoring file: $file" | ||
31 | ;; | ||
32 | esac | ||
33 | done | ||
34 |
task-postgresql-transformer.yaml
0 → 100644
1 | --- | ||
2 | apiVersion: tekton.dev/v1beta1 | ||
3 | kind: Task | ||
4 | metadata: | ||
5 | name: task-postgresql-transformer | ||
6 | spec: | ||
7 | params: | ||
8 | - name: POSTGRESQL_HOST | ||
9 | type: string | ||
10 | - name: postgresql-image | ||
11 | type: string | ||
12 | default: bitnami/postgresql:14.1.0-debian-10-r66 | ||
13 | workspaces: | ||
14 | - name: transformations | ||
15 | description: Place any transformation scripts here. | ||
16 | volumes: | ||
17 | - name: task-postgresql-scripts | ||
18 | configMap: | ||
19 | name: task-postgresql-scripts | ||
20 | defaultMode: 0755 | ||
21 | steps: | ||
22 | - name: wait-for-start | ||
23 | image: $(params.postgresql-image) | ||
24 | command: ["/scripts/wait-for-postgresql.sh"] | ||
25 | env: | ||
26 | - name: POSTGRESQL_HOST | ||
27 | value: $(params.POSTGRESQL_HOST) | ||
28 | volumeMounts: | ||
29 | - name: task-postgresql-scripts | ||
30 | mountPath: /scripts | ||
31 | - name: transformations | ||
32 | image: $(params.postgresql-image) | ||
33 | command: ["/scripts/transformations.sh"] | ||
34 | env: | ||
35 | - name: POSTGRESQL_HOST | ||
36 | value: $(params.POSTGRESQL_HOST) | ||
37 | volumeMounts: | ||
38 | - name: task-postgresql-scripts | ||
39 | mountPath: /scripts | ||
40 | --- |
-
Please register or sign in to post a comment