diff --git a/inventory/group_vars/copr_aws b/inventory/group_vars/copr_aws index 89fbde5016..2572e26ef9 100644 --- a/inventory/group_vars/copr_aws +++ b/inventory/group_vars/copr_aws @@ -202,3 +202,5 @@ rsnapshot_push: ssh_pub_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCeTO0ddXuhDZYM9HyM0a47aeV2yIVWhTpddrQ7/RAIs99XyrsicQLABzmdMBfiZnP0FnHBF/e+2xEkT8hHJpX6bX81jjvs2bb8KP18Nh8vaXI3QospWrRygpu1tjzqZT0Llh4ZVFscum8TrMw4VWXclzdDw6x7csCBjSttqq8F3iTJtQ9XM9/5tCAAOzGBKJrsGKV1CNIrfUo5CSzY+IUVIr8XJ93IB2ZQVASK34T/49egmrWlNB32fqAbDMC+XNmobgn6gO33Yq5Ly7Dk4kqTUx2TEaqDkZfhsVu0YcwV81bmqsltRvpj6bIXrEoMeav7nbuqKcPLTxWEY/2icePF" deployment_type: prod + +pulp_content_url: "https://console.redhat.com/api/pulp-content/public-copr" diff --git a/inventory/group_vars/copr_dev_aws b/inventory/group_vars/copr_dev_aws index 7873b5a2a7..fabb2faaa5 100644 --- a/inventory/group_vars/copr_dev_aws +++ b/inventory/group_vars/copr_dev_aws @@ -179,3 +179,5 @@ root_auth_users: msuchy frostyx praiskup nikromen aws_cloudfront_distribution: EX55ITR8LVMOH nrpe_client_uid: 500 + +pulp_content_url: "https://pulp.stage.devshift.net/api/pulp-content/copr" diff --git a/roles/copr/backend/tasks/main.yml b/roles/copr/backend/tasks/main.yml index 89fb03d5eb..b487a436f3 100644 --- a/roles/copr/backend/tasks/main.yml +++ b/roles/copr/backend/tasks/main.yml @@ -101,8 +101,14 @@ - config - lighttpd_config -- name: Add gzip content-encoding header by lua script - ansible.builtin.template: src="lighttpd/content-encoding-gzip-if-exists.lua" dest=/etc/lighttpd/content-encoding-gzip-if-exists.lua owner=root group=root mode=0644 +- name: Create a txt file with Pulp redirects + file: state=file dest=/var/lib/copr/pulp-redirect.txt owner=copr group=copr mode=644 + +- name: Add custom lighttpd lua scripts + ansible.builtin.template: src="lighttpd/{{ item }}.j2" dest="/etc/lighttpd/{{ item }}" owner=root group=root mode=644 + with_items: + - content-encoding-gzip-if-exists.lua + - pulp-redirect.lua notify: - restart lighttpd tags: diff --git a/roles/copr/backend/templates/lighttpd/content-encoding-gzip-if-exists.lua b/roles/copr/backend/templates/lighttpd/content-encoding-gzip-if-exists.lua.j2 similarity index 100% rename from roles/copr/backend/templates/lighttpd/content-encoding-gzip-if-exists.lua rename to roles/copr/backend/templates/lighttpd/content-encoding-gzip-if-exists.lua.j2 diff --git a/roles/copr/backend/templates/lighttpd/lighttpd.conf b/roles/copr/backend/templates/lighttpd/lighttpd.conf index f13f8a37df..7e4ad8540e 100644 --- a/roles/copr/backend/templates/lighttpd/lighttpd.conf +++ b/roles/copr/backend/templates/lighttpd/lighttpd.conf @@ -544,6 +544,10 @@ $HTTP["url"] !~ "^/archive/spacewalk($|/)" { } } +$HTTP["url"] =~ "\.(xml.*|rpm)$" { + magnet.attract-physical-path-to = ( "/etc/lighttpd/pulp-redirect.lua" ) +} + # https://pagure.io/copr/copr/issue/762 $HTTP["url"] =~ "\.log$" { setenv.add-response-header = ( "Cache-Control" => "no-store") diff --git a/roles/copr/backend/templates/lighttpd/pulp-redirect.lua.j2 b/roles/copr/backend/templates/lighttpd/pulp-redirect.lua.j2 new file mode 100644 index 0000000000..58c3a726c3 --- /dev/null +++ b/roles/copr/backend/templates/lighttpd/pulp-redirect.lua.j2 @@ -0,0 +1,54 @@ +-- Redirect to Pulp so that old backend URLs still work + +pulp_content_url = "{{ pulp_content_url }}" + +-- SQLite claims to be 35% faster than reading blobs from filesystem +-- https://www.sqlite.org/fasterthanfs.html +-- Worth trying out once we hit a bottleneck for reading the file +file_with_redirects = "/var/lib/copr/pulp-redirect.txt" + + +function line_in_file(searched, file) + -- Is searched line in a file? + for line in io.lines(file) do + if line == searched then + return true + end + end + return false +end + + +function uri_to_fullname(uri) + -- Take an URI which can look like this + -- /results/@copr/copr-dev/.../copr-cli-1.112-1.fc41.noarch.rpm + -- and parse only the project fullname from it, e.g. @copr/copr-dev + local first = string.find(uri, "/", 2) + local mid = string.find(uri, "/", first + 1) + local last = string.find(uri, ":") + if not last then + last = string.find(uri, "/", mid + 1) + end + return string.sub(uri, first + 1, last - 1) +end + + +function redirect(url) + lighty.header["Location"] = url + return 301 +end + + +function pulp_url(copr_path) + if string.sub(copr_path, 1, 9) == "/results/" then + copr_path = string.sub(copr_path, 10) + end + return pulp_content_url .. copr_path +end + + +local uri = lighty.env["uri.path"] +local project = uri_to_fullname(uri) +if line_in_file(project, file_with_redirects) then + return redirect(pulp_url(uri)) +end diff --git a/roles/copr/frontend/templates/copr.conf b/roles/copr/frontend/templates/copr.conf index 05565c07ce..6cd56b5fbd 100644 --- a/roles/copr/frontend/templates/copr.conf +++ b/roles/copr/frontend/templates/copr.conf @@ -264,8 +264,4 @@ USAGE_TREEMAP_TEAMS = { "Python-team": ["@python", "thrnciar", "torsava", "encukou", "cstratak", "churchyard"], } -{% if env == "production" %} -PULP_CONTENT_URL = "https://console.redhat.com/api/pulp-content/public-copr" -{% else %} -PULP_CONTENT_URL = "https://pulp.stage.devshift.net/api/pulp-content/copr" -{% endif %} +PULP_CONTENT_URL = "{{ pulp_content_url }}"