Skip to content

Commit c265405

Browse files
authored
Merge pull request #61 from code0-tech/44-sagittarius-grpc-boot-tests
Add boot test for sagittarius grpc server
2 parents f260fc3 + 4953144 commit c265405

5 files changed

Lines changed: 115 additions & 3 deletions

File tree

.gitlab/ci/container-boot.gitlab-ci.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
extends:
33
- .dind
44
stage: container:boot
5-
image: ghcr.io/code0-tech/build-images/reticulum-builder:171.1-ruby-3.2.2
5+
image: ghcr.io/code0-tech/build-images/reticulum-builder:177.1-ruby-3.2.2
66

77
.container:boot:sagittarius:
88
extends:
@@ -17,6 +17,7 @@
1717
variables:
1818
SAGITTARIUS_IMAGE: ghcr.io/code0-tech/reticulum/ci-builds/sagittarius:${CI_PIPELINE_ID}-${VARIANT}
1919
CURL_IMAGE: curlimages/curl:8.5.0
20+
DOCKER_ARGS: ""
2021
before_script:
2122
- docker network create boot
2223
- >
@@ -33,12 +34,16 @@
3334
- docker pull $CURL_IMAGE
3435
- >
3536
docker run
37+
--detach
3638
--name sagittarius
3739
--network boot
3840
--network-alias sagittarius
3941
--volume $(pwd)/container/sagittarius/sagittarius.yml:/sagittarius/config/sagittarius.yml
42+
$DOCKER_ARGS
4043
$SAGITTARIUS_IMAGE
41-
$SAGITTARIUS_CMD &
44+
$SAGITTARIUS_CMD
45+
- docker ps --all
46+
- docker logs -f sagittarius &
4247

4348
container:boot:sagittarius:rails-web:
4449
extends:
@@ -58,3 +63,17 @@ container:boot:sagittarius:rails-web:
5863
--retry-delay 3
5964
--retry-connrefused
6065
http://sagittarius:3000/health/liveness
66+
67+
container:boot:sagittarius:grpc:
68+
extends:
69+
- .container:boot:sagittarius
70+
variables:
71+
SAGITTARIUS_CMD: "bin/grpc_server"
72+
DOCKER_ARGS: "--publish 50051:50051 --env SAGITTARIUS_PREPARE_DATABASE=true"
73+
before_script:
74+
- bundle config set --local force_ruby_platform true
75+
- bundle install
76+
- !reference [.container:boot:sagittarius, before_script]
77+
script:
78+
- scripts/grpc_check_health --host docker:50051 --service liveness --retries 20
79+
- scripts/grpc_check_health --host docker:50051 --service readiness --retries 20

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
source "https://rubygems.org"
44

55
gem "erb"
6+
7+
gem "grpc", "~> 1.73"
8+
9+
gem "optparse", "~> 0.6.0"

Gemfile.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4+
bigdecimal (3.2.2)
45
erb (5.0.1)
6+
google-protobuf (4.31.1)
7+
bigdecimal
8+
rake (>= 13)
9+
googleapis-common-protos-types (1.20.0)
10+
google-protobuf (>= 3.18, < 5.a)
11+
grpc (1.73.0)
12+
google-protobuf (>= 3.25, < 5.0)
13+
googleapis-common-protos-types (~> 1.0)
14+
optparse (0.6.0)
15+
rake (13.3.0)
516

617
PLATFORMS
718
ruby
819

920
DEPENDENCIES
1021
erb
22+
grpc (~> 1.73)
23+
optparse (~> 0.6.0)
1124

1225
BUNDLED WITH
1326
2.6.6

scripts/grpc_check_health

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'grpc'
4+
require 'optparse'
5+
require 'grpc/health/v1/health_services_pb'
6+
7+
options = {
8+
retries: 5,
9+
backoff: 3,
10+
service: '',
11+
}
12+
13+
optparse = OptionParser.new do |opts|
14+
opts.banner = 'Usage: grpc_check_health [options]'
15+
16+
opts.on('-h', '--host [HOST]', String, 'Host of the grpc server to check') do |host|
17+
options[:host] = host
18+
end
19+
20+
opts.on('-r', '--retries [RETRIES]', Integer, "Amount of retries (Default: #{options[:retries]})") do |retries|
21+
options[:retries] = retries
22+
end
23+
24+
opts.on('-b', '--backoff [BACKOFF]', Integer, "Backoff in seconds for each attempt (Default: #{options[:backoff]})") do |backoff|
25+
options[:backoff] = backoff
26+
end
27+
28+
opts.on('-s', '--service [SERVICE]', String, "Service check health for (Default: '#{options[:service]}')") do |service|
29+
options[:service] = service
30+
end
31+
end
32+
optparse.parse!
33+
34+
missing = %i[host].select{ |param| options[param].nil? }
35+
unless missing.empty?
36+
puts "Missing arguments: #{missing.join(', ')}"
37+
puts
38+
puts optparse
39+
exit
40+
end
41+
42+
RetryException = Class.new(StandardError)
43+
44+
attempt = 1
45+
46+
begin
47+
puts
48+
puts "Attempt #{attempt}/#{options[:retries]} to check if '#{options[:service]}' on #{options[:host]} is serving"
49+
stub = Grpc::Health::V1::Health::Stub.new(options[:host], :this_channel_is_insecure)
50+
message = Grpc::Health::V1::HealthCheckRequest.new(service: options[:service])
51+
52+
response = stub.check(message)
53+
54+
if response.status == :SERVING
55+
puts "Service '#{options[:service]}' on #{options[:host]} is #{response.status}"
56+
else
57+
raise RetryException
58+
end
59+
rescue GRPC::BadStatus, RetryException => e
60+
if e.is_a?(GRPC::BadStatus)
61+
message = e.inspect
62+
else
63+
message = "Service #{options[:service]} on #{options[:host]} is not SERVING (status is #{response&.status})"
64+
end
65+
66+
puts message
67+
68+
if attempt < options[:retries]
69+
attempt += 1
70+
puts "Retrying in #{options[:backoff]}s"
71+
sleep options[:backoff]
72+
retry
73+
end
74+
75+
abort
76+
end

versions/sagittarius

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8387fcc7969e9e53ab28e04d9e8316b527d111b5
1+
02fd861ffe1465cba09b952532ac8d811639fbf7

0 commit comments

Comments
 (0)