diff --git a/.gitignore b/.gitignore index 312382f7..9ffdd25a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .bundle -db/*.sqlite3 +db/*.sqlite3* log/*.log tmp/ .DS_Store diff --git a/app/models/report.rb b/app/models/report.rb index 538747b2..13157214 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -155,15 +155,15 @@ def branch_opts end def loguri - server.uri.chomp('/') + datetime.strftime("/#{depsuffixed_name}/log/%Y%m%dT%H%M%SZ.log.html.gz") + server.log_base_uri + datetime.strftime("/#{depsuffixed_name}/log/%Y%m%dT%H%M%SZ.log.html.gz") end def diffuri - server.uri.chomp('/') + datetime.strftime("/#{depsuffixed_name}/log/%Y%m%dT%H%M%SZ.diff.html.gz") + server.log_base_uri + datetime.strftime("/#{depsuffixed_name}/log/%Y%m%dT%H%M%SZ.diff.html.gz") end def failuri - meta&.[]('compressed_failhtml_relpath') ? "#{server.uri.chomp('/')}/#{depsuffixed_name}/#{meta['compressed_failhtml_relpath']}" : nil + meta&.[]('compressed_failhtml_relpath') ? "#{server.log_base_uri}/#{depsuffixed_name}/#{meta['compressed_failhtml_relpath']}" : nil end def recenturi diff --git a/app/models/server.rb b/app/models/server.rb index 92d59b32..bd085a6c 100644 --- a/app/models/server.rb +++ b/app/models/server.rb @@ -5,6 +5,9 @@ class Server < ApplicationRecord RUBYCI_S3_HOST = 'rubyci.s3.amazonaws.com' RUBYCI_S3_URI = %r{\Ahttps?://#{Regexp.escape(RUBYCI_S3_HOST)}/} + # Fastly in front of the same bucket. Object keys are unchanged, so only the + # host is swapped. + RUBYCI_LOGS_URL = 'https://logs.rubyci.org' # Most rows still carry the http:// form these URIs were first registered # with, so both schemes have to match. Keep the Ruby and SQL forms together @@ -18,7 +21,13 @@ def rubyci_s3? RUBYCI_S3_URI.match?(uri.to_s) end + # Base for the log links shown to users. Bucket-backed servers go through the + # CDN; every other server keeps the URI it was registered with. + def log_base_uri + uri.sub(RUBYCI_S3_URI, "#{RUBYCI_LOGS_URL}/").chomp('/') + end + def recent_uri(branch) - "#{uri.chomp('/')}/ruby-#{branch}/recent.html" + "#{log_base_uri}/ruby-#{branch}/recent.html" end end diff --git a/config/routes.rb b/config/routes.rb index 9d7afd5a..95fbc269 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,8 +19,8 @@ end end - get "/coverage" => redirect("https://rubyci.s3.amazonaws.com/coverage-latest-html/index.html") - get "/doxygen" => redirect("https://rubyci.s3.amazonaws.com/doxygen-latest-html/index.html") + get "/coverage" => redirect("#{Server::RUBYCI_LOGS_URL}/coverage-latest-html/index.html") + get "/doxygen" => redirect("#{Server::RUBYCI_LOGS_URL}/doxygen-latest-html/index.html") #resources :logs, only: [:show], constraints: {id: /.*/} end diff --git a/test/models/report_test.rb b/test/models/report_test.rb index 15267e5d..e70da6bf 100644 --- a/test/models/report_test.rb +++ b/test/models/report_test.rb @@ -63,6 +63,18 @@ def build_report(attrs = {}) assert_equal SHA, report.sha1 end + test "log links go through the CDN" do + report = build_report( + server: create_server("cdn-links"), + datetime: Time.utc(2026, 1, 21, 18, 30, 3), + ltsv: "depsuffixed_name:ruby-master\tcompressed_failhtml_relpath:log/20260121T183003Z.fail.html.gz", + ) + assert_equal "https://logs.rubyci.org/cdn-links/ruby-master/log/20260121T183003Z.log.html.gz", report.loguri + assert_equal "https://logs.rubyci.org/cdn-links/ruby-master/log/20260121T183003Z.diff.html.gz", report.diffuri + assert_equal "https://logs.rubyci.org/cdn-links/ruby-master/log/20260121T183003Z.fail.html.gz", report.failuri + assert_equal "https://logs.rubyci.org/cdn-links/ruby-master/recent.html", report.recenturi + end + test "extract_full_sha" do assert_equal SHA, Report.extract_full_sha("https://github.com/ruby/ruby:#{SHA}") assert_equal SHA, Report.extract_full_sha(%["https\\x3A//github.com/ruby/ruby":#{SHA}]) diff --git a/test/models/server_test.rb b/test/models/server_test.rb index b2e32ffa..5af95e28 100644 --- a/test/models/server_test.rb +++ b/test/models/server_test.rb @@ -18,6 +18,20 @@ def create_server(uri) assert_not create_server("http://ci.rvm.jp/chkbuild/logs/").rubyci_s3? end + test "log_base_uri points bucket-backed servers at the CDN" do + assert_equal "https://logs.rubyci.org/ubuntu", create_server("https://rubyci.s3.amazonaws.com/ubuntu/").log_base_uri + assert_equal "https://logs.rubyci.org/rhel9", create_server("http://rubyci.s3.amazonaws.com/rhel9").log_base_uri + end + + test "log_base_uri keeps other servers as registered" do + assert_equal "http://ci.rvm.jp/chkbuild/logs", create_server("http://ci.rvm.jp/chkbuild/logs/").log_base_uri + end + + test "recent_uri uses the CDN host" do + server = create_server("https://rubyci.s3.amazonaws.com/debian/") + assert_equal "https://logs.rubyci.org/debian/ruby-master/recent.html", server.recent_uri("master") + end + test "rubyci_s3 scope selects the same servers as rubyci_s3?" do servers = [ create_server("https://rubyci.s3.amazonaws.com/scope-https/"),