perf(ci): transfer artifacts locally instead of through FRP
Gitea CI / Check code and tests (pull_request) Successful in 6m9s
Gitea CI / Build Android APK (pull_request) Successful in 3m35s
Gitea CI / Build Windows x64 app (pull_request) Successful in 7m45s
Gitea CI / Audit and package Windows x64 (pull_request) Failing after 1m41s
Gitea CI / Assemble and validate CI artifacts (pull_request) Skipped
Gitea CI / Gitea CI passed (pull_request) Failing after 2s
Gitea CI / Check code and tests (pull_request) Successful in 6m9s
Gitea CI / Build Android APK (pull_request) Successful in 3m35s
Gitea CI / Build Windows x64 app (pull_request) Successful in 7m45s
Gitea CI / Audit and package Windows x64 (pull_request) Failing after 1m41s
Gitea CI / Assemble and validate CI artifacts (pull_request) Skipped
Gitea CI / Gitea CI passed (pull_request) Failing after 2s
This commit is contained in:
1 parent
e06590dc82
commit
8e523f0e89
6 files changed
+83
-2
No files matched your search
@@ -15,6 +15,19 @@ SERVER = 'https://git.orangraph.com'
|
||||
RETRY_DELAYS = (5, 15)
|
||||
|
||||
|
||||
def transport_url(url):
|
||||
"""Route this host's Gitea traffic locally when the runner opts in."""
|
||||
internal = os.environ.get('CUTDEX_GITEA_INTERNAL_URL', '').rstrip('/')
|
||||
if not internal:
|
||||
return url
|
||||
if internal != 'http://127.0.0.1:3000':
|
||||
raise ValueError('Unexpected internal Gitea endpoint')
|
||||
parsed = urllib.parse.urlparse(url)
|
||||
if parsed.scheme != 'https' or parsed.netloc != 'git.orangraph.com':
|
||||
raise ValueError('Unexpected Gitea transport origin')
|
||||
return urllib.parse.urlunparse(parsed._replace(scheme='http', netloc='127.0.0.1:3000'))
|
||||
|
||||
|
||||
def transient(error):
|
||||
if isinstance(error, urllib.error.HTTPError):
|
||||
if error.code == 404 and error.headers.get('Content-Type', '').split(';')[0].lower() == 'text/html':
|
||||
@@ -45,7 +58,7 @@ def request(url, data=None, method=None, content_type='application/json'):
|
||||
headers['Content-Type'] = content_type
|
||||
if isinstance(data, dict):
|
||||
data = json.dumps(data).encode()
|
||||
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
||||
req = urllib.request.Request(transport_url(url), data=data, headers=headers, method=method)
|
||||
with urllib.request.urlopen(req, timeout=300) as response:
|
||||
body = response.read()
|
||||
return json.loads(body) if body and 'application/json' in response.headers.get('Content-Type', '') else body
|
||||
@@ -61,7 +74,7 @@ def attachment_url(asset):
|
||||
def fingerprint(asset):
|
||||
"""Hash one remote attachment in chunks, keeping memory usage bounded."""
|
||||
sha256, sha1, size = hashlib.sha256(), hashlib.sha1(), 0
|
||||
req = urllib.request.Request(attachment_url(asset),
|
||||
req = urllib.request.Request(transport_url(attachment_url(asset)),
|
||||
headers={'Authorization': 'token ' + os.environ['GITEA_TOKEN']})
|
||||
with urllib.request.urlopen(req, timeout=300) as response:
|
||||
while chunk := response.read(1024 * 1024):
|
||||
|
||||
@@ -9,6 +9,51 @@ import release_transport as transfers
|
||||
|
||||
|
||||
class TransferToolsTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
environment = patch.dict('os.environ', {'CUTDEX_GITEA_INTERNAL_URL': ''})
|
||||
environment.start()
|
||||
self.addCleanup(environment.stop)
|
||||
|
||||
def test_local_api_transport_preserves_authenticated_request_and_public_identity(self):
|
||||
class Response(io.BytesIO):
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
with patch.dict('os.environ', {'CUTDEX_GITEA_INTERNAL_URL': 'http://127.0.0.1:3000/',
|
||||
'GITEA_TOKEN': 'test-token'}), \
|
||||
patch.object(transfers.urllib.request, 'urlopen', return_value=Response(b'{"id":3}')) as open_url:
|
||||
result = transfers.request(transfers.SERVER + '/api/v1/releases?name=a%20b',
|
||||
data=b'package', method='POST', content_type='application/octet-stream')
|
||||
request = open_url.call_args.args[0]
|
||||
self.assertEqual(result, {'id': 3})
|
||||
self.assertEqual(request.full_url, 'http://127.0.0.1:3000/api/v1/releases?name=a%20b')
|
||||
self.assertEqual(request.get_method(), 'POST')
|
||||
self.assertEqual(request.get_header('Authorization'), 'token test-token')
|
||||
self.assertEqual(request.data, b'package')
|
||||
self.assertEqual(transfers.SERVER, 'https://git.orangraph.com')
|
||||
|
||||
def test_local_verification_routes_validated_attachment_without_changing_its_public_url(self):
|
||||
asset = {'browser_download_url': 'https://git.orangraph.com/attachments/example'}
|
||||
with patch.dict('os.environ', {'CUTDEX_GITEA_INTERNAL_URL': 'http://127.0.0.1:3000',
|
||||
'GITEA_TOKEN': 'test-token'}), \
|
||||
patch.object(transfers.urllib.request, 'urlopen', return_value=io.BytesIO(b'app')) as open_url:
|
||||
result = transfers.fingerprint(asset)
|
||||
self.assertEqual(open_url.call_args.args[0].full_url, 'http://127.0.0.1:3000/attachments/example')
|
||||
self.assertEqual(result['sha256'], hashlib.sha256(b'app').hexdigest())
|
||||
self.assertEqual(asset['browser_download_url'], 'https://git.orangraph.com/attachments/example')
|
||||
|
||||
def test_local_transport_rejects_unexpected_endpoint_or_origin_before_sending_credentials(self):
|
||||
for internal, url, message in [
|
||||
('http://example.com:3000', transfers.SERVER + '/api/v1/releases', 'internal Gitea endpoint'),
|
||||
('http://127.0.0.1:3000', 'https://example.com/file', 'transport origin'),
|
||||
('http://127.0.0.1:3000', 'http://git.orangraph.com/file', 'transport origin'),
|
||||
]:
|
||||
with self.subTest(internal=internal, url=url), \
|
||||
patch.dict('os.environ', {'CUTDEX_GITEA_INTERNAL_URL': internal, 'GITEA_TOKEN': 'test-token'}), \
|
||||
patch.object(transfers.urllib.request, 'urlopen') as open_url:
|
||||
with self.assertRaisesRegex(ValueError, message):
|
||||
transfers.request(url)
|
||||
open_url.assert_not_called()
|
||||
|
||||
def test_frp_tunnel_not_found_page_is_retried_as_a_temporary_failure(self):
|
||||
calls = 0
|
||||
|
||||
|
||||
Reference in new issue
Block a user