-
Notifications
You must be signed in to change notification settings - Fork 40
299 lines (277 loc) · 11.9 KB
/
test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
name: Test
on: [push, pull_request]
jobs:
tests:
name: ${{ matrix.version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- {version: '16', os: ubuntu-latest}
- {version: '15', os: ubuntu-latest}
- {version: '14', os: ubuntu-latest}
- {version: '13', os: ubuntu-latest}
- {version: '12', os: ubuntu-latest}
- {version: '11', os: ubuntu-latest}
- {version: '10', os: ubuntu-latest}
services:
postgres:
image: postgres:${{ matrix.version }}
env:
POSTGRES_PASSWORD: test
POSTGRES_USER: test
POSTGRES_DB: test_${{ matrix.version }}
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10
s3:
image: zenko/cloudserver
env:
ENDPOINT: s3
S3BACKEND: mem
REMOTE_MANAGEMENT_DISABLE: 1
SCALITY_ACCESS_KEY_ID: access_key
SCALITY_SECRET_ACCESS_KEY: secret
steps:
- name: Create Test Data
uses: addnab/docker-run-action@v3
with:
image: postgres:${{ matrix.version }}
run: >
psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -c '
CREATE TABLE books (
id serial PRIMARY KEY,
name VARCHAR ( 128 ) UNIQUE NOT NULL,
author VARCHAR (128 ) NOT NULL
);
INSERT INTO books (name, author) VALUES
($$Fittstim$$, $$Linda Skugge$$),
($$DSM-5$$, $$American Psychiatric Association$$);
CREATE TABLE movies (
id serial PRIMARY KEY,
name VARCHAR ( 128 ) UNIQUE NOT NULL,
director VARCHAR (128 ) NOT NULL
);
INSERT INTO movies (name, director) VALUES
($$Beau Travail$$, $$Claire Denis$$),
($$Reservoir Dogs$$, $$Quentin Tarantino$$);
'
options: >
-e PGPASSWORD=test
- name: Create S3 bucket
uses: addnab/docker-run-action@v3
with:
image: amazon/aws-cli
run: aws --endpoint-url=http://s3:8000 s3api create-bucket --bucket test-postgresql-backup; aws --endpoint-url=http://s3:8000 s3 ls
options: >
-e AWS_EC2_METADATA_DISABLED=true
-e AWS_ACCESS_KEY_ID=access_key
-e AWS_SECRET_ACCESS_KEY=secret
- uses: actions/checkout@v2
- name: Build Docker Image
uses: docker/build-push-action@v2
with:
tags: heyman/postgresql-backup:latest
push: false
context: ${{ matrix.version }}
- name: Take Backup
uses: addnab/docker-run-action@v3
with:
image: heyman/postgresql-backup:latest
run: python3 -u /backup/backup.py
options: >
-e S3_EXTRA_OPTIONS='--endpoint-url=http://s3:8000'
-e DB_HOST=postgres
-e DB_PASS=test
-e DB_USER=test
-e DB_NAME=test_${{ matrix.version }}
-e S3_PATH=s3://test-postgresql-backup/backups
-e AWS_ACCESS_KEY_ID=access_key
-e AWS_SECRET_ACCESS_KEY=secret
-e AWS_DEFAULT_REGION=us-east-1
-e FILENAME=test_${{ matrix.version }}
- name: Take Backup (using DB_USE_ENV)
uses: addnab/docker-run-action@main
with:
image: heyman/postgresql-backup:latest
run: python3 -u /backup/backup.py
options: >
-e S3_EXTRA_OPTIONS='--endpoint-url=http://s3:8000'
-e DB_USE_ENV=True
-e PGHOST=postgres
-e PGPASSWORD=test
-e PGUSER=test
-e PGDATABASE=test_${{ matrix.version }}
-e S3_PATH=s3://test-postgresql-backup/backups
-e AWS_ACCESS_KEY_ID=access_key
-e AWS_SECRET_ACCESS_KEY=secret
-e AWS_DEFAULT_REGION=us-east-1
-e FILENAME=test_${{ matrix.version }}_env
- name: Take Backup (using PG_DUMP_EXTRA_OPTIONS)
uses: addnab/docker-run-action@main
with:
image: heyman/postgresql-backup:latest
run: python3 -u /backup/backup.py
options: >
-e S3_EXTRA_OPTIONS='--endpoint-url=http://s3:8000'
-e DB_USE_ENV=True
-e PGHOST=postgres
-e PGPASSWORD=test
-e PGUSER=test
-e PGDATABASE=test_${{ matrix.version }}
-e S3_PATH=s3://test-postgresql-backup/backups
-e AWS_ACCESS_KEY_ID=access_key
-e AWS_SECRET_ACCESS_KEY=secret
-e AWS_DEFAULT_REGION=us-east-1
-e FILENAME=test_${{ matrix.version }}_exclude
-e PG_DUMP_EXTRA_OPTIONS='--exclude-table=movies'
- name: Check equality
uses: addnab/docker-run-action@main
with:
image: amazon/aws-cli
entryPoint: /bin/bash
run: |
aws s3 --endpoint-url=http://s3:8000 cp s3://test-postgresql-backup/backups/test_${{ matrix.version }} .
aws s3 --endpoint-url=http://s3:8000 cp s3://test-postgresql-backup/backups/test_${{ matrix.version }}_env .
diff test_${{ matrix.version }} test_${{ matrix.version }}_env
echo "$( md5sum test_${{ matrix.version }} |awk '{print $1}') test_${{ matrix.version }}_env"|md5sum -c
options: >
-e AWS_EC2_METADATA_DISABLED=true
-e AWS_ACCESS_KEY_ID=access_key
-e AWS_SECRET_ACCESS_KEY=secret
- name: Clear DB table
uses: addnab/docker-run-action@v3
with:
image: postgres:${{ matrix.version }}
run: >
psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -c '
DROP TABLE books;
'
options: >
-e PGPASSWORD=test
- name: Check that table was actually removed
uses: addnab/docker-run-action@v3
with:
image: postgres:${{ matrix.version }}
shell: bash
run: >
[[ "0" == `psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -A -t -c '
SELECT count(*) FROM pg_catalog.pg_tables WHERE tablename=$$books$$;
'` ]]
options: >
-e PGPASSWORD=test
- name: Restore Backup
uses: addnab/docker-run-action@v3
with:
image: heyman/postgresql-backup:latest
run: python3 -u /backup/restore.py test_${{ matrix.version }}
options: >
-e S3_EXTRA_OPTIONS='--endpoint-url=http://s3:8000'
-e DB_HOST=postgres
-e DB_PASS=test
-e DB_USER=test
-e DB_NAME=test_${{ matrix.version }}
-e S3_PATH=s3://test-postgresql-backup/backups
-e AWS_ACCESS_KEY_ID=access_key
-e AWS_SECRET_ACCESS_KEY=secret
-e AWS_DEFAULT_REGION=us-east-1
- name: Check that table got imported
uses: addnab/docker-run-action@v3
with:
image: postgres:${{ matrix.version }}
shell: bash
run: >
[[ "1" == `psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -A -t -c '
SELECT count(*) FROM pg_catalog.pg_tables WHERE tablename=$$books$$;
'` ]] && [[ "Fittstim" == `psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -A -t -c '
SELECT name FROM books WHERE author=$$Linda Skugge$$;
'` ]]
options: >
-e PGPASSWORD=test
- name: Clear DB table
uses: addnab/docker-run-action@main
with:
image: postgres:${{ matrix.version }}
shell: bash
run: >
psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -c '
DROP TABLE books;
DROP TABLE movies;
' && [[ "0" == `psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -A -t -c '
SELECT count(*) FROM pg_catalog.pg_tables WHERE tablename=$$books$$;
'` ]]
options: >
-e PGPASSWORD=test
- name: Restore Backup (DB_USE_ENV)
uses: addnab/docker-run-action@main
with:
image: heyman/postgresql-backup:latest
run: python3 -u /backup/restore.py test_${{ matrix.version }}_env
options: >
-e S3_EXTRA_OPTIONS='--endpoint-url=http://s3:8000'
-e DB_USE_ENV=True
-e PGHOST=postgres
-e PGPASSWORD=test
-e PGUSER=test
-e PGDATABASE=test_${{ matrix.version }}
-e S3_PATH=s3://test-postgresql-backup/backups
-e AWS_ACCESS_KEY_ID=access_key
-e AWS_SECRET_ACCESS_KEY=secret
-e AWS_DEFAULT_REGION=us-east-1
- name: Check that table got imported
uses: addnab/docker-run-action@main
with:
image: postgres:${{ matrix.version }}
shell: bash
run: >
[[ "1" == `psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -A -t -c '
SELECT count(*) FROM pg_catalog.pg_tables WHERE tablename=$$books$$;
'` ]] && [[ "Fittstim" == `psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -A -t -c '
SELECT name FROM books WHERE author=$$Linda Skugge$$;
'` ]]
options: >
-e PGPASSWORD=test
- name: Clear DB table
uses: addnab/docker-run-action@main
with:
image: postgres:${{ matrix.version }}
shell: bash
run: >
psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -c '
DROP TABLE books;
DROP TABLE movies;
' && [[ "0" == `psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -A -t -c '
SELECT count(*) FROM pg_catalog.pg_tables WHERE tablename=$$books$$;
'` ]]
options: >
-e PGPASSWORD=test
- name: Restore Backup (PG_DUMP_EXTRA_OPTIONS)
uses: addnab/docker-run-action@main
with:
image: heyman/postgresql-backup:latest
run: python3 -u /backup/restore.py test_${{ matrix.version }}_exclude
options: >
-e S3_EXTRA_OPTIONS='--endpoint-url=http://s3:8000'
-e PGHOST=postgres
-e PGPASSWORD=test
-e PGUSER=test
-e PGDATABASE=test_${{ matrix.version }}
-e S3_PATH=s3://test-postgresql-backup/backups
-e AWS_ACCESS_KEY_ID=access_key
-e AWS_SECRET_ACCESS_KEY=secret
-e AWS_DEFAULT_REGION=us-east-1
- name: Check that table got imported (PG_DUMP_EXTRA_OPTIONS)
uses: addnab/docker-run-action@main
with:
image: postgres:${{ matrix.version }}
shell: bash
run: >
[[ "1" == `psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -A -t -c '
SELECT count(*) FROM pg_catalog.pg_tables WHERE tablename=$$books$$;
'` ]] && [[ "Fittstim" == `psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -A -t -c '
SELECT name FROM books WHERE author=$$Linda Skugge$$;
'` ]] && [[ "0" == `psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -A -t -c '
SELECT count(*) FROM pg_catalog.pg_tables WHERE tablename=$$movies$$;
options: >
-e PGPASSWORD=test