fixup! fixup! Pritup pres PHP a docker

This commit is contained in:
lachtan obecny
2026-08-17 21:18:32 +02:00
parent 4ae2da01c2
commit 3126173f82
2 changed files with 43 additions and 5 deletions

View File

@@ -2,7 +2,6 @@
declare(strict_types=1);
define('REPO_RAW_BASE_URL', getenv('REPO_RAW_BASE_URL') ?: 'https://git.fnet.cz/lachtan/get/raw/branch/master/');
const MANIFEST_PATH = 'manifest.yaml';
const TEMPLATES_DIRECTORY = __DIR__ . '/../templates';
const FETCH_TIMEOUT_SECONDS = 5;
@@ -64,6 +63,22 @@ function renderScriptTemplate(string $templateName, array $placeholders): string
return $script;
}
$repoRawBaseUrl = getenv('REPO_RAW_BASE_URL');
if ($repoRawBaseUrl === false || $repoRawBaseUrl === '') {
sendPlainTextError(500, 'REPO_RAW_BASE_URL is not configured');
}
define('REPO_RAW_BASE_URL', $repoRawBaseUrl);
$publicBaseUrl = getenv('PUBLIC_BASE_URL');
if ($publicBaseUrl === false || $publicBaseUrl === '') {
sendPlainTextError(500, 'PUBLIC_BASE_URL is not configured');
}
define('PUBLIC_BASE_URL', $publicBaseUrl);
$requestPath = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?? '/';
$name = trim(rawurldecode($requestPath), '/');
@@ -71,16 +86,24 @@ if ($name === '') {
sendPlainTextError(400, 'Missing name of the installable item');
}
$isRawRequest = str_starts_with($name, 'raw/');
if ($isRawRequest) {
$name = substr($name, strlen('raw/'));
}
$repoHost = parse_url(REPO_RAW_BASE_URL, PHP_URL_HOST);
$manifestYaml = fetchRaw(MANIFEST_PATH);
if ($manifestYaml === false) {
sendPlainTextError(502, 'Failed to fetch the manifest from git.fnet.cz');
sendPlainTextError(502, "Failed to fetch the manifest from $repoHost");
}
$manifest = yaml_parse($manifestYaml);
if ($manifest === false) {
sendPlainTextError(502, 'Failed to parse the manifest from git.fnet.cz');
sendPlainTextError(502, "Failed to parse the manifest from $repoHost");
}
$entry = $manifest[$name] ?? null;
@@ -93,8 +116,20 @@ if (!is_string($entry['source'] ?? null) || !is_string($entry['target'] ?? null)
sendPlainTextError(500, "Malformed manifest entry for item '$name'");
}
if ($isRawRequest) {
$content = fetchRaw($entry['source']);
if ($content === false) {
sendPlainTextError(502, "Failed to fetch the file from $repoHost");
}
header('Content-Type: application/octet-stream');
echo $content;
exit;
}
$variables = [
'SOURCE_URL' => REPO_RAW_BASE_URL . escapeForDoubleQuotedShellString(ltrim($entry['source'], '/')),
'SOURCE_URL' => rtrim(PUBLIC_BASE_URL, '/') . '/raw/' . rawurlencode($name),
'TARGET_PATH' => resolveHomePath($entry['target']),
'POST_INSTALL' => $entry['post_install'] ?? '',
];

View File

@@ -1,6 +1,9 @@
services:
get:
build: .
environment:
REPO_RAW_BASE_URL: https://git.hell/lachtan/get/raw/branch/master/
PUBLIC_BASE_URL: https://get.fnet.cz/
ports:
- "${PORT:-8082}:80"
- "8082:80"
restart: unless-stopped