copr-be: conditionally redirect backend URLs to Pulp
See https://github.com/fedora-copr/copr/issues/3504
This commit is contained in:
parent
fb06fb5d5c
commit
b7be52dd87
7 changed files with 71 additions and 7 deletions
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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")
|
||||
|
|
54
roles/copr/backend/templates/lighttpd/pulp-redirect.lua.j2
Normal file
54
roles/copr/backend/templates/lighttpd/pulp-redirect.lua.j2
Normal file
|
@ -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
|
|
@ -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 }}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue