-
Notifications
You must be signed in to change notification settings - Fork 19
133 lines (113 loc) · 5.15 KB
/
ci.yaml
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
name: CI
on:
push:
branches:
- main
tags:
- "v**"
pull_request:
concurrency:
group: branch-ci-${{ github.ref }}
cancel-in-progress: true
jobs:
rspec:
runs-on: ubuntu-20.04
timeout-minutes: 30
name: Ruby ${{ matrix.ruby }} - PG ${{ matrix.pg.from }} -> PG ${{ matrix.pg.to }}
strategy:
matrix:
ruby: ["3.0.5", "3.1.4", "3.2.1"]
pg:
[
{ from: 10, to: 11 },
{ from: 11, to: 12 },
{ from: 12, to: 13 },
{ from: 13, to: 14 },
{ from: 14, to: 15 },
{ from: 10, to: 15 },
]
steps:
- uses: actions/checkout@v1
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Bundle install
env:
RAILS_ENV: test
run: |
gem install bundler
bundle install --jobs 4 --retry 3 --path vendor/bundle
- name: Run Lint
run: bundle exec rubocop
# - name: Setup upterm session
# uses: lhotari/action-upterm@v1
- name: "Setup PG databases"
run: |
set -euvxo pipefail
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null
sudo apt-get update
sudo apt-get install --yes --no-install-recommends postgresql-${{ matrix.pg.from }} postgresql-client-${{ matrix.pg.from }}
sudo apt-get install --yes --no-install-recommends postgresql-${{ matrix.pg.to }} postgresql-client-${{ matrix.pg.to }}
sudo systemctl restart postgresql@${{ matrix.pg.from }}-main.service
sudo systemctl restart postgresql@${{ matrix.pg.to }}-main.service
sudo systemctl restart postgresql
# Escape the quote because we are setting the password in PG
# String: james-bond123@7!''3aaR
export PGPASSWORD='james-bond123@7!'"'"''"'"'3aaR'
sudo su - postgres -c "createuser -p 5432 -d -s -e -l james-bond"
sudo -u postgres psql -p 5432 -c 'alter user "james-bond" with encrypted password '"'"''"$PGPASSWORD"''"'"';'
sudo su - postgres -c "createdb -p 5432 postgres-db"
sudo -u postgres psql -p 5432 -c "grant all privileges on database \"postgres-db\" to \"james-bond\";"
sudo su - postgres -c "createuser -p 5433 -d -s -e -l james-bond"
sudo -u postgres psql -p 5433 -c 'alter user "james-bond" with encrypted password '"'"''"$PGPASSWORD"''"'"';'
sudo su - postgres -c "createdb -p 5433 postgres-db"
sudo -u postgres psql -p 5433 -c "grant all privileges on database \"postgres-db\" to \"james-bond\";"
# Remove the escaped quote since we are passing the pwd to psql
# String: james-bond123@7!'3aaR
export PGPASSWORD='james-bond123@7!'"'"'3aaR'
psql -h localhost -d postgres-db -U james-bond -p 5432 -c 'ALTER SYSTEM SET wal_level = logical;'
psql -h localhost -d postgres-db -U james-bond -p 5433 -c 'ALTER SYSTEM SET wal_level = logical;'
sudo systemctl restart postgresql@${{ matrix.pg.from }}-main.service
sudo systemctl restart postgresql@${{ matrix.pg.to }}-main.service
sudo systemctl restart postgresql
psql -h localhost -d postgres-db -U james-bond -p 5432 -c 'show wal_level;'
psql -h localhost -d postgres-db -U james-bond -p 5433 -c 'show wal_level;'
sudo -u postgres psql -p 5432 -c "ALTER SYSTEM SET max_connections = '500';"
sudo -u postgres psql -p 5433 -c "ALTER SYSTEM SET max_connections = '500';"
sudo systemctl restart postgresql@${{ matrix.pg.from }}-main.service
sudo systemctl restart postgresql@${{ matrix.pg.to }}-main.service
sudo systemctl restart postgresql
# Verify the changes
psql -h localhost -d postgres-db -U james-bond -p 5432 -c 'SHOW max_connections;'
psql -h localhost -d postgres-db -U james-bond -p 5433 -c 'SHOW max_connections;'
- name: Run RSpec
run: bundle exec rspec
build-push-image:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-20.04
timeout-minutes: 30
needs: [rspec]
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Branch name
id: version_name
run: |
echo ::set-output name=no_v_tag::${GITHUB_REF_NAME:1}
- name: Build and push
uses: docker/build-push-action@v4
with:
platforms: linux/amd64,linux/arm64
push: true
build-args: VERSION=${{ steps.version_name.outputs.no_v_tag }}
tags: shayonj/pg_easy_replicate:latest, shayonj/pg_easy_replicate:${{ steps.version_name.outputs.no_v_tag }}