test.yml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. name: Test
  2. on: [push, pull_request]
  3. jobs:
  4. tests:
  5. name: ${{ matrix.version }}
  6. runs-on: ${{ matrix.os }}
  7. strategy:
  8. fail-fast: false
  9. matrix:
  10. include:
  11. - {version: '13', os: ubuntu-latest}
  12. - {version: '12', os: ubuntu-latest}
  13. - {version: '11', os: ubuntu-latest}
  14. - {version: '10', os: ubuntu-latest}
  15. services:
  16. postgres:
  17. image: postgres:${{ matrix.version }}
  18. env:
  19. POSTGRES_PASSWORD: test
  20. POSTGRES_USER: test
  21. POSTGRES_DB: test_${{ matrix.version }}
  22. ports:
  23. - 5432:5432
  24. options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10
  25. s3:
  26. image: zenko/cloudserver
  27. env:
  28. ENDPOINT: s3
  29. S3BACKEND: mem
  30. REMOTE_MANAGEMENT_DISABLE: 1
  31. SCALITY_ACCESS_KEY_ID: access_key
  32. SCALITY_SECRET_ACCESS_KEY: secret
  33. steps:
  34. - name: Create Test Data
  35. uses: addnab/docker-run-action@v3
  36. with:
  37. image: postgres:${{ matrix.version }}
  38. run: >
  39. psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -c '
  40. CREATE TABLE books (
  41. id serial PRIMARY KEY,
  42. name VARCHAR ( 128 ) UNIQUE NOT NULL,
  43. author VARCHAR (128 ) NOT NULL
  44. );
  45. INSERT INTO books (name, author) VALUES
  46. ($$Fittstim$$, $$Linda Skugge$$),
  47. ($$DSM-5$$, $$American Psychiatric Association$$);
  48. '
  49. options: >
  50. -e PGPASSWORD=test
  51. - name: Create S3 bucket
  52. uses: addnab/docker-run-action@v3
  53. with:
  54. image: amazon/aws-cli
  55. run: aws --endpoint-url=http://s3:8000 s3api create-bucket --bucket test-postgresql-backup; aws --endpoint-url=http://s3:8000 s3 ls
  56. options: >
  57. -e AWS_EC2_METADATA_DISABLED=true
  58. -e AWS_ACCESS_KEY_ID=access_key
  59. -e AWS_SECRET_ACCESS_KEY=secret
  60. - uses: actions/checkout@v2
  61. - name: Build Docker Image
  62. uses: docker/build-push-action@v2
  63. with:
  64. tags: heyman/postgresql-backup:latest
  65. push: false
  66. context: ${{ matrix.version }}
  67. - name: Take Backup
  68. uses: addnab/docker-run-action@v3
  69. with:
  70. image: heyman/postgresql-backup:latest
  71. run: python -u /backup/backup.py
  72. options: >
  73. -e S3_EXTRA_OPTIONS='--endpoint-url=http://s3:8000'
  74. -e DB_HOST=postgres
  75. -e DB_PASS=test
  76. -e DB_USER=test
  77. -e DB_NAME=test_${{ matrix.version }}
  78. -e S3_PATH=s3://test-postgresql-backup/backups
  79. -e AWS_ACCESS_KEY_ID=access_key
  80. -e AWS_SECRET_ACCESS_KEY=secret
  81. -e AWS_DEFAULT_REGION=us-east-1
  82. -e FILENAME=test_${{ matrix.version }}
  83. - name: Take Backup (using DB_USE_ENV)
  84. uses: addnab/docker-run-action@main
  85. with:
  86. image: heyman/postgresql-backup:latest
  87. run: python -u /backup/backup.py
  88. options: >
  89. -e S3_EXTRA_OPTIONS='--endpoint-url=http://s3:8000'
  90. -e DB_USE_ENV=True
  91. -e PGHOST=postgres
  92. -e PGPASSWORD=test
  93. -e PGUSER=test
  94. -e PGDATABASE=test_${{ matrix.version }}
  95. -e S3_PATH=s3://test-postgresql-backup/backups
  96. -e AWS_ACCESS_KEY_ID=access_key
  97. -e AWS_SECRET_ACCESS_KEY=secret
  98. -e AWS_DEFAULT_REGION=us-east-1
  99. -e FILENAME=test_${{ matrix.version }}_env
  100. - name: Check equality
  101. uses: addnab/docker-run-action@main
  102. with:
  103. image: amazon/aws-cli
  104. entryPoint: /bin/bash
  105. run: |
  106. aws s3 --endpoint-url=http://s3:8000 cp s3://test-postgresql-backup/backups/test_${{ matrix.version }} .
  107. aws s3 --endpoint-url=http://s3:8000 cp s3://test-postgresql-backup/backups/test_${{ matrix.version }}_env .
  108. diff test_${{ matrix.version }} test_${{ matrix.version }}_env
  109. echo "$( md5sum test_${{ matrix.version }} |awk '{print $1}') test_${{ matrix.version }}_env"|md5sum -c
  110. options: >
  111. -e AWS_EC2_METADATA_DISABLED=true
  112. -e AWS_ACCESS_KEY_ID=access_key
  113. -e AWS_SECRET_ACCESS_KEY=secret
  114. - name: Clear DB table
  115. uses: addnab/docker-run-action@v3
  116. with:
  117. image: postgres:${{ matrix.version }}
  118. run: >
  119. psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -c '
  120. DROP TABLE books;
  121. '
  122. options: >
  123. -e PGPASSWORD=test
  124. - name: Check that table was actually removed
  125. uses: addnab/docker-run-action@v3
  126. with:
  127. image: postgres:${{ matrix.version }}
  128. shell: bash
  129. run: >
  130. [[ "0" == `psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -A -t -c '
  131. SELECT count(*) FROM pg_catalog.pg_tables WHERE tablename=$$books$$;
  132. '` ]]
  133. options: >
  134. -e PGPASSWORD=test
  135. - name: Restore Backup
  136. uses: addnab/docker-run-action@v3
  137. with:
  138. image: heyman/postgresql-backup:latest
  139. run: python -u /backup/restore.py test_${{ matrix.version }}
  140. options: >
  141. -e S3_EXTRA_OPTIONS='--endpoint-url=http://s3:8000'
  142. -e DB_HOST=postgres
  143. -e DB_PASS=test
  144. -e DB_USER=test
  145. -e DB_NAME=test_${{ matrix.version }}
  146. -e S3_PATH=s3://test-postgresql-backup/backups
  147. -e AWS_ACCESS_KEY_ID=access_key
  148. -e AWS_SECRET_ACCESS_KEY=secret
  149. -e AWS_DEFAULT_REGION=us-east-1
  150. - name: Check that table got imported
  151. uses: addnab/docker-run-action@v3
  152. with:
  153. image: postgres:${{ matrix.version }}
  154. shell: bash
  155. run: >
  156. [[ "1" == `psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -A -t -c '
  157. SELECT count(*) FROM pg_catalog.pg_tables WHERE tablename=$$books$$;
  158. '` ]] && [[ "Fittstim" == `psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -A -t -c '
  159. SELECT name FROM books WHERE author=$$Linda Skugge$$;
  160. '` ]]
  161. options: >
  162. -e PGPASSWORD=test
  163. - name: Clear DB table
  164. uses: addnab/docker-run-action@main
  165. with:
  166. image: postgres:${{ matrix.version }}
  167. shell: bash
  168. run: >
  169. psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -c '
  170. DROP TABLE books;
  171. ' && [[ "0" == `psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -A -t -c '
  172. SELECT count(*) FROM pg_catalog.pg_tables WHERE tablename=$$books$$;
  173. '` ]]
  174. options: >
  175. -e PGPASSWORD=test
  176. - name: Restore Backup (DB_USE_ENV)
  177. uses: addnab/docker-run-action@main
  178. with:
  179. image: heyman/postgresql-backup:latest
  180. run: python -u /backup/restore.py test_${{ matrix.version }}
  181. options: >
  182. -e S3_EXTRA_OPTIONS='--endpoint-url=http://s3:8000'
  183. -e DB_USE_ENV=True
  184. -e PGHOST=postgres
  185. -e PGPASSWORD=test
  186. -e PGUSER=test
  187. -e PGDATABASE=test_${{ matrix.version }}
  188. -e S3_PATH=s3://test-postgresql-backup/backups
  189. -e AWS_ACCESS_KEY_ID=access_key
  190. -e AWS_SECRET_ACCESS_KEY=secret
  191. -e AWS_DEFAULT_REGION=us-east-1
  192. - name: Check that table got imported
  193. uses: addnab/docker-run-action@main
  194. with:
  195. image: postgres:${{ matrix.version }}
  196. shell: bash
  197. run: >
  198. [[ "1" == `psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -A -t -c '
  199. SELECT count(*) FROM pg_catalog.pg_tables WHERE tablename=$$books$$;
  200. '` ]] && [[ "Fittstim" == `psql -d test_${{ matrix.version }} -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} -A -t -c '
  201. SELECT name FROM books WHERE author=$$Linda Skugge$$;
  202. '` ]]
  203. options: >
  204. -e PGPASSWORD=test