Skip to content

Implement service to retrieve latest Runner releases

What does this MR do and why?

Describe in detail what your merge request does and why.

This MR introduces a singleton service that fetches and holds the latest releases of the https://gitlab.com/gitlab-org/gitlab-runner project. It will be used by a subsequent MR to determine if a CI runner needs to be updated or not.

Releases are refreshed at most once a day, if they are requested. If an error happens during the last fetch, there is a 5 second backoff period before the request is tried again.

Screenshots or screen recordings

These are strongly recommended to assist reviewers and reduce the time to merge your change.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

In the GDK console:

> Gitlab::Ci::RunnerReleases.instance.releases
=> [#<Gitlab::VersionInfo:0x00007fd134374350 @major=14, @minor=1, @patch=0>,
 #<Gitlab::VersionInfo:0x00007fd134376ec0 @major=14, @minor=2, @patch=0>,
 #<Gitlab::VersionInfo:0x00007fd134375110 @major=14, @minor=2, @patch=0>,
 #<Gitlab::VersionInfo:0x00007fd1343706b0 @major=14, @minor=3, @patch=0>,
 #<Gitlab::VersionInfo:0x00007fd1343722d0 @major=14, @minor=3, @patch=0>,
 #<Gitlab::VersionInfo:0x00007fd134373180 @major=14, @minor=3, @patch=1>,
 #<Gitlab::VersionInfo:0x00007fd134373810 @major=14, @minor=3, @patch=2>,
 #<Gitlab::VersionInfo:0x00007fd13436d820 @major=14, @minor=4, @patch=0>,
 #<Gitlab::VersionInfo:0x00007fd13436fd50 @major=14, @minor=4, @patch=0>,
 #<Gitlab::VersionInfo:0x00007fd1343686b8 @major=14, @minor=5, @patch=0>,
 #<Gitlab::VersionInfo:0x00007fd134369ba8 @major=14, @minor=5, @patch=0>,
 #<Gitlab::VersionInfo:0x00007fd13436ad50 @major=14, @minor=6, @patch=0>,
 #<Gitlab::VersionInfo:0x00007fd134362150 @major=14, @minor=6, @patch=1>,
 #<Gitlab::VersionInfo:0x00007fd13436b6d8 @major=14, @minor=7, @patch=0>,
 #<Gitlab::VersionInfo:0x00007fd134358650 @major=14, @minor=7, @patch=1>,
 #<Gitlab::VersionInfo:0x00007fd134364298 @major=14, @minor=8, @patch=0>,
 #<Gitlab::VersionInfo:0x00007fd1343667a0 @major=14, @minor=8, @patch=1>,
 #<Gitlab::VersionInfo:0x00007fd134363f50 @major=14, @minor=8, @patch=2>,
 #<Gitlab::VersionInfo:0x00007fd134359140 @major=14, @minor=9, @patch=0>,
 #<Gitlab::VersionInfo:0x00007fd134359780 @major=14, @minor=9, @patch=1>]

Database migrations

bin/rails db:migrate
== 20220324171254 AddPublicGitLabRunnerReleasesUrlToApplicationSettings: migrating
-- add_column(:application_settings, :public_runner_releases_url, :text, {:null=>false, :default=>"https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab-runner/releases"})
   -> 0.0143s
== 20220324171254 AddPublicGitLabRunnerReleasesUrlToApplicationSettings: migrated (0.0144s)

== 20220324173554 AddTextLimitToPublicGitLabRunnerReleasesUrlApplicationSettings: migrating
-- transaction_open?()
   -> 0.0000s
-- current_schema()
   -> 0.0004s
-- transaction_open?()
   -> 0.0000s
-- execute("ALTER TABLE application_settings\nADD CONSTRAINT check_8dca35398a\nCHECK ( char_length(public_runner_releases_url) <= 255 )\nNOT VALID;\n")
   -> 0.0050s
-- current_schema()
   -> 0.0003s
-- execute("SET statement_timeout TO 0")
   -> 0.0009s
-- execute("ALTER TABLE application_settings VALIDATE CONSTRAINT check_8dca35398a;")
   -> 0.0021s
-- execute("RESET statement_timeout")
   -> 0.0009s
== 20220324173554 AddTextLimitToPublicGitLabRunnerReleasesUrlApplicationSettings: migrated (0.0324s)
bin/rails db:rollback
== 20220324173554 AddTextLimitToPublicGitLabRunnerReleasesUrlApplicationSettings: reverting
-- transaction_open?()
   -> 0.0000s
-- transaction_open?()
   -> 0.0000s
-- execute("ALTER TABLE application_settings\nDROP CONSTRAINT IF EXISTS check_8dca35398a\n")
   -> 0.0028s
== 20220324173554 AddTextLimitToPublicGitLabRunnerReleasesUrlApplicationSettings: reverted (0.0176s)

== 20220324171254 AddPublicGitLabRunnerReleasesUrlToApplicationSettings: reverting
-- remove_column(:application_settings, :public_runner_releases_url, :text, {:null=>false, :default=>"https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab-runner/releases"})
   -> 0.0058s
== 20220324171254 AddPublicGitLabRunnerReleasesUrlToApplicationSettings: reverted (0.0093s)```
</details>

## MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability. 

* [x] I have evaluated the [MR acceptance checklist](https://docs.gitlab.com/ee/development/code_review.html#acceptance-checklist) for this MR.

Part of #356689

Merge request reports