Add many more tasks that are needed for transformation scripts in a
pipeline.
Showing
8 changed files
with
235 additions
and
0 deletions
... | @@ -4,6 +4,9 @@ kind: Kustomization | ... | @@ -4,6 +4,9 @@ kind: Kustomization |
4 | resources: | 4 | resources: |
5 | - ./service-account.yaml | 5 | - ./service-account.yaml |
6 | - ./task-postgresql-pod.yaml | 6 | - ./task-postgresql-pod.yaml |
7 | - ./task-postgresql-create-databases-users.yaml | ||
8 | - ./task-postgresql-import.yaml | ||
9 | - ./task-postgresql-export.yaml | ||
7 | 10 | ||
8 | configMapGenerator: | 11 | configMapGenerator: |
9 | - name: task-postgresql-pod-kustomization | 12 | - name: task-postgresql-pod-kustomization |
... | @@ -14,5 +17,13 @@ configMapGenerator: | ... | @@ -14,5 +17,13 @@ configMapGenerator: |
14 | - postgresql-pod_postgresql-pod.yaml=postgresql-pod/postgresql-pod.yaml | 17 | - postgresql-pod_postgresql-pod.yaml=postgresql-pod/postgresql-pod.yaml |
15 | - postgresql-pod_set-deployment-config_deployment-config.env=postgresql-pod/set-deployment-config/deployment-config.env | 18 | - postgresql-pod_set-deployment-config_deployment-config.env=postgresql-pod/set-deployment-config/deployment-config.env |
16 | - postgresql-pod_set-deployment-config_kustomization.yaml=postgresql-pod/set-deployment-config/kustomization.yaml | 19 | - postgresql-pod_set-deployment-config_kustomization.yaml=postgresql-pod/set-deployment-config/kustomization.yaml |
20 | - name: task-postgresql-scripts | ||
21 | options: | ||
22 | disableNameSuffixHash: true | ||
23 | files: | ||
24 | - scripts/create-databases-users.sh | ||
25 | - scripts/export-dumps.sh | ||
26 | - scripts/import-dumps.sh | ||
27 | - scripts/wait-for-postgresql.sh | ||
17 | 28 | ||
18 | --- | 29 | --- | ... | ... |
scripts/create-databases-users.sh
0 → 100644
1 | #!/bin/bash | ||
2 | |||
3 | set -ex | ||
4 | |||
5 | mode= | ||
6 | touch /tmp/pgpass | ||
7 | chmod 0600 /tmp/pgpass | ||
8 | echo "*:*:*:*:CHANGEME" > /tmp/pgpass | ||
9 | export PGPASSFILE=/tmp/pgpass | ||
10 | |||
11 | while [[ $# -gt 0 ]]; do | ||
12 | case "$1" in | ||
13 | (--databases) | ||
14 | mode="databases" | ||
15 | ;; | ||
16 | (--users) | ||
17 | mode="users" | ||
18 | ;; | ||
19 | (--*) | ||
20 | echo "Unknown mode: $1" 1>&2 | ||
21 | exit 1 | ||
22 | ;; | ||
23 | (*) | ||
24 | case "$mode" in | ||
25 | (databases) | ||
26 | createdb -w -h ${POSTGRESQL_HOST} -U postgres "$1" | ||
27 | ;; | ||
28 | (users) | ||
29 | createuser -w -h ${POSTGRESQL_HOST} -U postgres "$1" | ||
30 | ;; | ||
31 | esac | ||
32 | ;; | ||
33 | esac | ||
34 | shift | ||
35 | done | ||
36 |
scripts/export-dumps.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 | ls /workspace | ||
11 | for database in "$@"; do | ||
12 | pg_dump -w -h ${POSTGRESQL_HOST} -U postgres "$database" | gzip -9v > "/workspace/exports/$database.gz" | ||
13 | done | ||
14 |
scripts/import-dumps.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/imports/*; 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 | (*) | ||
27 | echo "Ignoring file: $file" | ||
28 | ;; | ||
29 | esac | ||
30 | done | ||
31 |
scripts/wait-for-postgresql.sh
0 → 100644
task-postgresql-create-databases-users.yaml
0 → 100644
1 | --- | ||
2 | apiVersion: tekton.dev/v1beta1 | ||
3 | kind: Task | ||
4 | metadata: | ||
5 | name: task-postgresql-create-databases-users | ||
6 | spec: | ||
7 | params: | ||
8 | - name: databases | ||
9 | type: array | ||
10 | - name: users | ||
11 | type: array | ||
12 | - name: POSTGRESQL_HOST | ||
13 | type: string | ||
14 | - name: postgresql-image | ||
15 | type: string | ||
16 | default: bitnami/postgresql:14.1.0-debian-10-r66 | ||
17 | volumes: | ||
18 | - name: task-postgresql-scripts | ||
19 | configMap: | ||
20 | name: task-postgresql-scripts | ||
21 | defaultMode: 0755 | ||
22 | steps: | ||
23 | - name: wait-for-start | ||
24 | image: $(params.postgresql-image) | ||
25 | command: ["/scripts/wait-for-postgresql.sh"] | ||
26 | env: | ||
27 | - name: POSTGRESQL_HOST | ||
28 | value: $(params.POSTGRESQL_HOST) | ||
29 | volumeMounts: | ||
30 | - name: task-postgresql-scripts | ||
31 | mountPath: /scripts | ||
32 | - name: create-databases-users | ||
33 | image: $(params.postgresql-image) | ||
34 | command: ["/scripts/create-databases-users.sh"] | ||
35 | args: ["--databases", "$(params.databases[*])", "--users", "$(params.users[*])"] | ||
36 | env: | ||
37 | - name: POSTGRESQL_HOST | ||
38 | value: $(params.POSTGRESQL_HOST) | ||
39 | volumeMounts: | ||
40 | - name: task-postgresql-scripts | ||
41 | mountPath: /scripts | ||
42 | --- |
task-postgresql-export.yaml
0 → 100644
1 | --- | ||
2 | apiVersion: tekton.dev/v1beta1 | ||
3 | kind: Task | ||
4 | metadata: | ||
5 | name: task-postgresql-export | ||
6 | spec: | ||
7 | params: | ||
8 | - name: exports | ||
9 | type: array | ||
10 | - name: POSTGRESQL_HOST | ||
11 | type: string | ||
12 | - name: postgresql-image | ||
13 | type: string | ||
14 | default: bitnami/postgresql:14.1.0-debian-10-r66 | ||
15 | workspaces: | ||
16 | - name: exports | ||
17 | description: The database exports will be placed in this workspace. | ||
18 | volumes: | ||
19 | - name: task-postgresql-scripts | ||
20 | configMap: | ||
21 | name: task-postgresql-scripts | ||
22 | defaultMode: 0755 | ||
23 | steps: | ||
24 | - name: wait-for-start | ||
25 | image: $(params.postgresql-image) | ||
26 | command: ["/scripts/wait-for-postgresql.sh"] | ||
27 | env: | ||
28 | - name: POSTGRESQL_HOST | ||
29 | value: $(params.POSTGRESQL_HOST) | ||
30 | volumeMounts: | ||
31 | - name: task-postgresql-scripts | ||
32 | mountPath: /scripts | ||
33 | - name: exports | ||
34 | image: $(params.postgresql-image) | ||
35 | command: ["/scripts/export-dumps.sh", "$(params.exports[*])"] | ||
36 | env: | ||
37 | - name: POSTGRESQL_HOST | ||
38 | value: $(params.POSTGRESQL_HOST) | ||
39 | volumeMounts: | ||
40 | - name: task-postgresql-scripts | ||
41 | mountPath: /scripts | ||
42 | |||
43 | --- | ||
44 |
task-postgresql-import.yaml
0 → 100644
1 | --- | ||
2 | apiVersion: tekton.dev/v1beta1 | ||
3 | kind: Task | ||
4 | metadata: | ||
5 | name: task-postgresql-import | ||
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: imports | ||
15 | description: Place any input database dump files 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: imports | ||
32 | image: $(params.postgresql-image) | ||
33 | command: ["/scripts/import-dumps.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