active_record_proxy_adapters 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +4 -0
- data/.rubocop.yml +20 -0
- data/CHANGELOG.md +9 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/Dockerfile +18 -0
- data/LICENSE.txt +21 -0
- data/README.md +114 -0
- data/Rakefile +12 -0
- data/ci/stages/build.yml +91 -0
- data/ci/stages/env_vars.yml +18 -0
- data/ci/stages/lint.yml +12 -0
- data/ci/stages/prebuild.yml +28 -0
- data/ci/stages/push.yml +23 -0
- data/ci/stages/test.yml +133 -0
- data/docker-compose.yml +77 -0
- data/lib/active_record/connection_adapters/postgresql_proxy_adapter.rb +43 -0
- data/lib/active_record/tasks/postgresql_proxy_database_tasks.rb +45 -0
- data/lib/active_record_proxy_adapters/active_record_context.rb +48 -0
- data/lib/active_record_proxy_adapters/configuration.rb +23 -0
- data/lib/active_record_proxy_adapters/connection_handling.rb +35 -0
- data/lib/active_record_proxy_adapters/hijackable.rb +42 -0
- data/lib/active_record_proxy_adapters/postgresql_proxy.rb +14 -0
- data/lib/active_record_proxy_adapters/primary_replica_proxy.rb +190 -0
- data/lib/active_record_proxy_adapters/railtie.rb +21 -0
- data/lib/active_record_proxy_adapters/version.rb +5 -0
- data/lib/active_record_proxy_adapters.rb +22 -0
- data/postgres_primary.dockerfile +34 -0
- data/postgres_replica.dockerfile +23 -0
- data/sig/active_record_proxy_adapters.rbs +4 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6f1bd3461586c7443e358fe82092039c05dd7cba760b4e4b7660ce6ecbd928e4
|
4
|
+
data.tar.gz: a8b40dce128c9449744ef8725bc6baa446ba8f4119e64c068a3d553e74b6fd1e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4a50dc55929c1d7c57f5278788d23240314660eba4ceb17335ac079740265b77042a35900ab64482073fabf79cc0612a7a38de9521f0cf5676a30b6545c5811a
|
7
|
+
data.tar.gz: 35ec9da8d5d1f4703129e66fa79f2f872bf5e36e053b38ea5abb25383e11980bbb19febee7c579d4e7b9905971b99e58be15d748ca13bafa064470bd873cc138
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rspec
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
TargetRubyVersion: 3.1
|
6
|
+
NewCops: enable
|
7
|
+
|
8
|
+
Style/StringLiterals:
|
9
|
+
EnforcedStyle: double_quotes
|
10
|
+
|
11
|
+
Style/StringLiteralsInInterpolation:
|
12
|
+
EnforcedStyle: double_quotes
|
13
|
+
|
14
|
+
RSpec/NestedGroups:
|
15
|
+
Enabled: true
|
16
|
+
Max: 5
|
17
|
+
|
18
|
+
# TODO: Enable MFA once we open source the gem
|
19
|
+
Gemspec/RequireMFA:
|
20
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/Dockerfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
ARG RUBY_VERSION=3.2.3
|
2
|
+
ARG DOCKER_REGISTRY=docker.io
|
3
|
+
FROM $DOCKER_REGISTRY/ruby:$RUBY_VERSION-alpine
|
4
|
+
ARG RAILS_VERSION="~> 6.1.0"
|
5
|
+
ENV RAILS_VERSION=$RAILS_VERSION
|
6
|
+
|
7
|
+
RUN apk --update add \
|
8
|
+
build-base \
|
9
|
+
git \
|
10
|
+
postgresql-dev \
|
11
|
+
postgresql-client
|
12
|
+
RUN gem install bundler -v 2.5.13
|
13
|
+
|
14
|
+
COPY . /app
|
15
|
+
WORKDIR /app
|
16
|
+
|
17
|
+
RUN bundle install
|
18
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Nasdaq
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# ActiveRecordProxyAdapters
|
2
|
+
|
3
|
+
A set of ActiveRecord adapters that leverage Rails native multiple database setup to allow automatic connection switching from _one_ primary pool to _one_ replica pool at the database statement level.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add 'UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG'
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
### On Rails
|
20
|
+
|
21
|
+
In `config/database.yml`, use `postgresql_proxy` as the adapter for the `primary` database, and keep `postgresql` for the replica database.
|
22
|
+
|
23
|
+
```yaml
|
24
|
+
# config/database.yml
|
25
|
+
development:
|
26
|
+
primary:
|
27
|
+
adapter: postgresql_proxy
|
28
|
+
# your primary credentials here
|
29
|
+
|
30
|
+
primary_replica:
|
31
|
+
adapter: postgresql
|
32
|
+
replica: true
|
33
|
+
# your replica credentials here
|
34
|
+
```
|
35
|
+
|
36
|
+
### Off Rails
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
# In your application setup
|
40
|
+
require "active_record_proxy_adapters"
|
41
|
+
|
42
|
+
ActiveSupport.on_load :active_record do
|
43
|
+
require "active_record_proxy_adapters/connection_handling"
|
44
|
+
ActiveRecord::Base.extend(ActiveRecordProxyAdapters::ConnectionHandling)
|
45
|
+
end
|
46
|
+
|
47
|
+
# in your base model
|
48
|
+
class ApplicationRecord << ActiveRecord::Base
|
49
|
+
establish_connection(
|
50
|
+
{
|
51
|
+
adapter: 'postgresql_proxy',
|
52
|
+
# your primary credentials here
|
53
|
+
},
|
54
|
+
role: :writing
|
55
|
+
)
|
56
|
+
|
57
|
+
establish_connection(
|
58
|
+
{
|
59
|
+
adapter: 'postgresql',
|
60
|
+
# your replica credentials here
|
61
|
+
},
|
62
|
+
role: :reading
|
63
|
+
)
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
### Configuration
|
68
|
+
|
69
|
+
The gem comes preconfigured out of the box. However, if default configuration does not suit your needs, you can modify them by using a `.configure` block:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
# config/initializers/active_record_proxy_adapters.rb
|
73
|
+
ActiveRecordProxyAdapters.configure do |config|
|
74
|
+
# How long proxy should reroute all read requests to primary after a write
|
75
|
+
config.proxy_delay = 5.seconds # defaults to 2.seconds
|
76
|
+
|
77
|
+
# How long proxy should wait for replica to connect.
|
78
|
+
config.checkout_timeout = 5.seconds # defaults to 2.seconds
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
### How it works
|
83
|
+
|
84
|
+
The proxy will analyze each SQL string, using pattern matching, to decide the appropriate connection for it (i.e. if it should go to the primary or replica).
|
85
|
+
|
86
|
+
- All queries inside a transaction go to the primary
|
87
|
+
- All `SET` queries go to all connections
|
88
|
+
- All `INSERT`, `UPDATE` and `DELETE` queries go to the primary
|
89
|
+
- All `SELECT FOR UPDATE` queries go to the primary
|
90
|
+
- All `lock` queries (e.g `get_lock`) go the primary
|
91
|
+
- All sequence methods (e.g `nextval`) go the primary
|
92
|
+
- Everything else goes to the replica
|
93
|
+
|
94
|
+
#### TL;DR
|
95
|
+
|
96
|
+
All `SELECT` queries go to the _replica_, everything else goes to _primary_.
|
97
|
+
|
98
|
+
## Development
|
99
|
+
|
100
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
101
|
+
|
102
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
103
|
+
|
104
|
+
## Contributing
|
105
|
+
|
106
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nasdaq/active_record_proxy_adapters. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/nasdaq/active_record_proxy_adapters/blob/main/CODE_OF_CONDUCT.md).
|
107
|
+
|
108
|
+
## License
|
109
|
+
|
110
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
111
|
+
|
112
|
+
## Code of Conduct
|
113
|
+
|
114
|
+
Everyone interacting in the ActiveRecordProxyAdapters project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nasdaq/active_record_proxy_adapters/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/ci/stages/build.yml
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
.build_app_base:
|
2
|
+
extends: .build_base
|
3
|
+
stage: build
|
4
|
+
variables:
|
5
|
+
DOCKERFILE: Dockerfile
|
6
|
+
DOCKER_REGISTRY: registry.git.nasdaq.com/smp/common
|
7
|
+
rules:
|
8
|
+
- changes:
|
9
|
+
- Dockerfile
|
10
|
+
- Gemfile
|
11
|
+
- active_record_proxy_adapters.gemspec
|
12
|
+
- ci/stages/build.yml
|
13
|
+
retry: 2
|
14
|
+
script:
|
15
|
+
- echo "CI_JOB_NAME=${CI_JOB_NAME}"
|
16
|
+
- SUFFIX="-rails${RAILS_VERSION}-ruby${RUBY_VERSION}"
|
17
|
+
- SUFFIX=$(echo $SUFFIX | tr -d '~> ' | tr -d '>=' | tr -d '<=' | tr -d '>' | tr -d '<' | tr -d ' ' )
|
18
|
+
- APP_IMAGE=${ENV_IMAGE_PREFIX}${SUFFIX}
|
19
|
+
- echo "APP_IMAGE=${APP_IMAGE}"
|
20
|
+
- echo "RAILS_VERSION=${RAILS_VERSION}"
|
21
|
+
- echo "RUBY_VERSION=${RUBY_VERSION}"
|
22
|
+
- buildah_build -t $APP_IMAGE --build-arg DOCKER_REGISTRY="${DOCKER_REGISTRY}" --build-arg RUBY_VERSION="${RUBY_VERSION}" --build-arg RAILS_VERSION="${RAILS_VERSION}" -f $DOCKERFILE .
|
23
|
+
- buildah push $APP_IMAGE
|
24
|
+
|
25
|
+
env-rails-7.0.x 316 / 3:
|
26
|
+
extends: .build_app_base
|
27
|
+
variables:
|
28
|
+
RAILS_VERSION: '~> 7.0.0'
|
29
|
+
RUBY_VERSION: '3.1.6'
|
30
|
+
|
31
|
+
env-rails-7.0.x 325 / 3:
|
32
|
+
extends: .build_app_base
|
33
|
+
variables:
|
34
|
+
RAILS_VERSION: '~> 7.0.0'
|
35
|
+
RUBY_VERSION: '3.2.5'
|
36
|
+
|
37
|
+
env-rails-7.0.x 335 / 3:
|
38
|
+
extends: .build_app_base
|
39
|
+
variables:
|
40
|
+
RAILS_VERSION: '~> 7.0.0'
|
41
|
+
RUBY_VERSION: '3.3.5'
|
42
|
+
|
43
|
+
env-rails-7.1.x 316 / 3:
|
44
|
+
extends: .build_app_base
|
45
|
+
variables:
|
46
|
+
RAILS_VERSION: '~> 7.1.0'
|
47
|
+
RUBY_VERSION: '3.1.6'
|
48
|
+
|
49
|
+
env-rails-7.1.x 325 / 3:
|
50
|
+
extends: .build_app_base
|
51
|
+
variables:
|
52
|
+
RAILS_VERSION: '~> 7.1.0'
|
53
|
+
RUBY_VERSION: '3.2.5'
|
54
|
+
|
55
|
+
env-rails-7.1.x 335 / 3:
|
56
|
+
extends: .build_app_base
|
57
|
+
variables:
|
58
|
+
RUBY_VERSION: '3.3.5'
|
59
|
+
RAILS_VERSION: '~> 7.1.0'
|
60
|
+
|
61
|
+
env-rails-7.2.x 316 / 3:
|
62
|
+
extends: .build_app_base
|
63
|
+
variables:
|
64
|
+
RAILS_VERSION: '~> 7.2.0'
|
65
|
+
RUBY_VERSION: '3.1.6'
|
66
|
+
|
67
|
+
env-rails-7.2.x 325 / 3:
|
68
|
+
extends: .build_app_base
|
69
|
+
variables:
|
70
|
+
RAILS_VERSION: '~> 7.2.0'
|
71
|
+
RUBY_VERSION: '3.2.5'
|
72
|
+
|
73
|
+
env-rails-7.2.x 335 / 3:
|
74
|
+
extends: .build_app_base
|
75
|
+
variables:
|
76
|
+
RAILS_VERSION: '~> 7.2.0'
|
77
|
+
RUBY_VERSION: '3.3.5'
|
78
|
+
|
79
|
+
# Rails 8.0.x does not support Ruby 3.1.6
|
80
|
+
|
81
|
+
env-rails-8.0.x 325 / 3:
|
82
|
+
extends: .build_app_base
|
83
|
+
variables:
|
84
|
+
RAILS_VERSION: '~> 8.0.0'
|
85
|
+
RUBY_VERSION: '3.2.5'
|
86
|
+
|
87
|
+
env-rails-8.0.x 335 / 3:
|
88
|
+
extends: .build_app_base
|
89
|
+
variables:
|
90
|
+
RAILS_VERSION: '~> 8.0.0'
|
91
|
+
RUBY_VERSION: '3.3.5'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
export:
|
2
|
+
stage: env_vars
|
3
|
+
image: registry.git.nasdaq.com/gitlab/ci/buildah/stable:v1.30.0
|
4
|
+
artifacts:
|
5
|
+
reports:
|
6
|
+
dotenv: build.env
|
7
|
+
script:
|
8
|
+
- !reference [.checksums, functions]
|
9
|
+
- POSTGRES_PRIMARY_TAG=$(checksum postgres_primary.dockerfile)
|
10
|
+
- POSTGRES_REPLICA_TAG=$(checksum postgres_replica.dockerfile)
|
11
|
+
- DOCKERFILE_CHECKSUM=$(checksum Dockerfile)
|
12
|
+
- GEMFILE_CHECKSUM=$(checksum Gemfile)
|
13
|
+
- GEMSPEC_CHECKSUM=$(checksum active_record_proxy_adapters.gemspec)
|
14
|
+
- TAG_PREFIX=$(checksum_join $DOCKERFILE_CHECKSUM $GEMFILE_CHECKSUM $GEMSPEC_CHECKSUM)
|
15
|
+
- ENV_IMAGE_PREFIX=${CI_REGISTRY_IMAGE}/env:${TAG_PREFIX}
|
16
|
+
- echo "POSTGRES_PRIMARY_IMAGE=${CI_REGISTRY_IMAGE}/postgres_primary:${POSTGRES_PRIMARY_TAG}" >> build.env
|
17
|
+
- echo "POSTGRES_REPLICA_IMAGE=${CI_REGISTRY_IMAGE}/postgres_replica:${POSTGRES_REPLICA_TAG}" >> build.env
|
18
|
+
- echo "ENV_IMAGE_PREFIX=${ENV_IMAGE_PREFIX}" >> build.env
|
data/ci/stages/lint.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
postgres_primary:
|
4
|
+
extends: .build_base
|
5
|
+
stage: prebuild
|
6
|
+
variables:
|
7
|
+
DOCKERFILE: postgres_primary.dockerfile
|
8
|
+
REPLICA_USER: replicator
|
9
|
+
REPLICA_PASSWORD: replicator
|
10
|
+
script:
|
11
|
+
- echo "POSTGRES_PRIMARY_IMAGE=${POSTGRES_PRIMARY_IMAGE}"
|
12
|
+
- echo "DOCKERFILE=${DOCKERFILE}"
|
13
|
+
- buildah_build -t $POSTGRES_PRIMARY_IMAGE --build-arg REPLICA_USER=${REPLICA_USER} --build-arg REPLICA_PASSWORD=${REPLICA_PASSWORD} -f $DOCKERFILE .
|
14
|
+
- buildah push $POSTGRES_PRIMARY_IMAGE
|
15
|
+
rules:
|
16
|
+
- changes:
|
17
|
+
- postgres_primary.dockerfile
|
18
|
+
postgres_replica:
|
19
|
+
extends: .build_base
|
20
|
+
stage: prebuild
|
21
|
+
variables:
|
22
|
+
DOCKERFILE: postgres_replica.dockerfile
|
23
|
+
script:
|
24
|
+
- buildah_build -t $POSTGRES_REPLICA_IMAGE -f $DOCKERFILE .
|
25
|
+
- buildah push $POSTGRES_REPLICA_IMAGE
|
26
|
+
rules:
|
27
|
+
- changes:
|
28
|
+
- postgres_replica.dockerfile
|
data/ci/stages/push.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
push_to_rubygems:
|
2
|
+
stage: push
|
3
|
+
image: ruby:alpine
|
4
|
+
rules:
|
5
|
+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
6
|
+
when: manual
|
7
|
+
allow_failure: true
|
8
|
+
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
9
|
+
when: never
|
10
|
+
- if: $CI_COMMIT_TAG
|
11
|
+
when: always
|
12
|
+
script: |
|
13
|
+
apk add git curl
|
14
|
+
GEM_VERSION="${CI_COMMIT_TAG:-$(grep VERSION lib/active_record_proxy_adapters/version.rb | tr -d 'VERSION=' | tr -d ' ' | tr -d '"')}"
|
15
|
+
mkdir ~/.gem
|
16
|
+
echo "---" > ~/.gem/credentials
|
17
|
+
echo "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/rubygems: '${CI_JOB_TOKEN}'" >> ~/.gem/credentials
|
18
|
+
chmod 0600 ~/.gem/credentials
|
19
|
+
echo "------------------"
|
20
|
+
echo "building gem"
|
21
|
+
gem build active_record_proxy_adapters.gemspec
|
22
|
+
echo "Uploading to rubygems"
|
23
|
+
curl --verbose --fail --user "$NEXUS_USER_ID:$NEXUS_PASSWORD" --upload-file "${CI_PROJECT_DIR}/active_record_proxy_adapters-${GEM_VERSION}.gem" "https://pro.nexus.aws.nasdaq.com/repository/smp-second-market-gems/active_record_proxy_adapters/"
|
data/ci/stages/test.yml
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
.test_base:
|
2
|
+
stage: test
|
3
|
+
needs:
|
4
|
+
- export
|
5
|
+
- job: postgres_primary
|
6
|
+
optional: true
|
7
|
+
- job: postgres_replica
|
8
|
+
optional: true
|
9
|
+
services:
|
10
|
+
- name: $POSTGRES_PRIMARY_IMAGE
|
11
|
+
alias: postgres-primary
|
12
|
+
variables:
|
13
|
+
POSTGRES_DB: postgres_primary_test
|
14
|
+
POSTGRES_USER: postgres_primary_test
|
15
|
+
POSTGRES_PASSWORD: postgres_primary_test
|
16
|
+
POSTGRES_HOST_AUTH_METHOD: "scram-sha-256\nhost replication all 0.0.0.0/0 md5"
|
17
|
+
POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256"
|
18
|
+
- name: $POSTGRES_REPLICA_IMAGE
|
19
|
+
alias: postgres-replica
|
20
|
+
variables:
|
21
|
+
PGUSER: replicator
|
22
|
+
PGPASSWORD: replicator
|
23
|
+
PGPORT: 5433
|
24
|
+
PRIMARY_DATABASE_HOST: postgres-primary
|
25
|
+
variables:
|
26
|
+
PGHOST: postgres-primary
|
27
|
+
PG_PRIMARY_USER: postgres_primary_test
|
28
|
+
PG_PRIMARY_PASSWORD: postgres_primary_test
|
29
|
+
PG_PRIMARY_HOST: postgres-primary
|
30
|
+
PG_PRIMARY_PORT: 5432
|
31
|
+
PG_REPLICA_USER: postgres_primary_test
|
32
|
+
PG_REPLICA_PASSWORD: postgres_primary_test
|
33
|
+
PG_REPLICA_HOST: postgres-replica
|
34
|
+
PG_REPLICA_PORT: 5433
|
35
|
+
|
36
|
+
|
37
|
+
.rspec:
|
38
|
+
extends: .test_base
|
39
|
+
retry: 2
|
40
|
+
script:
|
41
|
+
- echo "Ruby version => $(ruby -v)"
|
42
|
+
- echo "ActiveRecord Version => $(gem list | grep activerecord)"
|
43
|
+
- rspec --format progress
|
44
|
+
|
45
|
+
rspec-rails-7.0.x 316 / 3:
|
46
|
+
extends: .rspec
|
47
|
+
needs:
|
48
|
+
- !reference [.test_base, needs]
|
49
|
+
- job: env-rails-7.0.x 316 / 3
|
50
|
+
optional: true
|
51
|
+
image: ${ENV_IMAGE_PREFIX}-rails7.0.0-ruby3.1.6
|
52
|
+
|
53
|
+
rspec-rails-7.0.x 325 / 3:
|
54
|
+
extends: .rspec
|
55
|
+
needs:
|
56
|
+
- !reference [.test_base, needs]
|
57
|
+
- job: env-rails-7.0.x 325 / 3
|
58
|
+
optional: true
|
59
|
+
image: ${ENV_IMAGE_PREFIX}-rails7.0.0-ruby3.2.5
|
60
|
+
|
61
|
+
rspec-rails-7.0.x 335 / 3:
|
62
|
+
extends: .rspec
|
63
|
+
needs:
|
64
|
+
- !reference [.test_base, needs]
|
65
|
+
- job: env-rails-7.0.x 335 / 3
|
66
|
+
optional: true
|
67
|
+
image: ${ENV_IMAGE_PREFIX}-rails7.0.0-ruby3.3.5
|
68
|
+
|
69
|
+
rspec-rails-7.1.x 316 / 3:
|
70
|
+
extends: .rspec
|
71
|
+
needs:
|
72
|
+
- !reference [.test_base, needs]
|
73
|
+
- job: env-rails-7.1.x 316 / 3
|
74
|
+
optional: true
|
75
|
+
image: ${ENV_IMAGE_PREFIX}-rails7.1.0-ruby3.1.6
|
76
|
+
|
77
|
+
rspec-rails-7.1.x 325 / 3:
|
78
|
+
extends: .rspec
|
79
|
+
needs:
|
80
|
+
- !reference [.test_base, needs]
|
81
|
+
- job: env-rails-7.1.x 325 / 3
|
82
|
+
optional: true
|
83
|
+
image: ${ENV_IMAGE_PREFIX}-rails7.1.0-ruby3.2.5
|
84
|
+
|
85
|
+
rspec-rails-7.1.x 335 / 3:
|
86
|
+
extends: .rspec
|
87
|
+
needs:
|
88
|
+
- !reference [.test_base, needs]
|
89
|
+
- job: env-rails-7.1.x 335 / 3
|
90
|
+
optional: true
|
91
|
+
image: ${ENV_IMAGE_PREFIX}-rails7.1.0-ruby3.3.5
|
92
|
+
|
93
|
+
rspec-rails-7.2.x 316 / 3:
|
94
|
+
extends: .rspec
|
95
|
+
needs:
|
96
|
+
- !reference [.test_base, needs]
|
97
|
+
- job: env-rails-7.2.x 316 / 3
|
98
|
+
optional: true
|
99
|
+
image: ${ENV_IMAGE_PREFIX}-rails7.2.0-ruby3.1.6
|
100
|
+
|
101
|
+
rspec-rails-7.2.x 325 / 3:
|
102
|
+
extends: .rspec
|
103
|
+
needs:
|
104
|
+
- !reference [.test_base, needs]
|
105
|
+
- job: env-rails-7.2.x 325 / 3
|
106
|
+
optional: true
|
107
|
+
image: ${ENV_IMAGE_PREFIX}-rails7.2.0-ruby3.2.5
|
108
|
+
|
109
|
+
rspec-rails-7.2.x 335 / 3:
|
110
|
+
extends: .rspec
|
111
|
+
needs:
|
112
|
+
- !reference [.test_base, needs]
|
113
|
+
- job: env-rails-7.2.x 335 / 3
|
114
|
+
optional: true
|
115
|
+
image: ${ENV_IMAGE_PREFIX}-rails7.2.0-ruby3.3.5
|
116
|
+
|
117
|
+
# Rails 8.0.x does not support Ruby 3.1.6
|
118
|
+
|
119
|
+
rspec-rails-8.0.x 325 / 3:
|
120
|
+
extends: .rspec
|
121
|
+
needs:
|
122
|
+
- !reference [.test_base, needs]
|
123
|
+
- job: env-rails-8.0.x 325 / 3
|
124
|
+
optional: true
|
125
|
+
image: ${ENV_IMAGE_PREFIX}-rails8.0.0-ruby3.2.5
|
126
|
+
|
127
|
+
rspec-rails-8.0.x 335 / 3:
|
128
|
+
extends: .rspec
|
129
|
+
needs:
|
130
|
+
- !reference [.test_base, needs]
|
131
|
+
- job: env-rails-8.0.x 335 / 3
|
132
|
+
optional: true
|
133
|
+
image: ${ENV_IMAGE_PREFIX}-rails8.0.0-ruby3.3.5
|