fixup! fixup! Pritup pres PHP a docker
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
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 MANIFEST_PATH = 'manifest.yaml';
|
||||||
const TEMPLATES_DIRECTORY = __DIR__ . '/../templates';
|
const TEMPLATES_DIRECTORY = __DIR__ . '/../templates';
|
||||||
const FETCH_TIMEOUT_SECONDS = 5;
|
const FETCH_TIMEOUT_SECONDS = 5;
|
||||||
@@ -64,6 +63,22 @@ function renderScriptTemplate(string $templateName, array $placeholders): string
|
|||||||
return $script;
|
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) ?? '/';
|
$requestPath = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?? '/';
|
||||||
$name = trim(rawurldecode($requestPath), '/');
|
$name = trim(rawurldecode($requestPath), '/');
|
||||||
|
|
||||||
@@ -71,16 +86,24 @@ if ($name === '') {
|
|||||||
sendPlainTextError(400, 'Missing name of the installable item');
|
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);
|
$manifestYaml = fetchRaw(MANIFEST_PATH);
|
||||||
|
|
||||||
if ($manifestYaml === false) {
|
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);
|
$manifest = yaml_parse($manifestYaml);
|
||||||
|
|
||||||
if ($manifest === false) {
|
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;
|
$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'");
|
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 = [
|
$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']),
|
'TARGET_PATH' => resolveHomePath($entry['target']),
|
||||||
'POST_INSTALL' => $entry['post_install'] ?? '',
|
'POST_INSTALL' => $entry['post_install'] ?? '',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
services:
|
services:
|
||||||
get:
|
get:
|
||||||
build: .
|
build: .
|
||||||
|
environment:
|
||||||
|
REPO_RAW_BASE_URL: https://git.hell/lachtan/get/raw/branch/master/
|
||||||
|
PUBLIC_BASE_URL: https://get.fnet.cz/
|
||||||
ports:
|
ports:
|
||||||
- "${PORT:-8082}:80"
|
- "8082:80"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
Reference in New Issue
Block a user