Pritup pres PHP a docker

This commit is contained in:
Martin Blazik
2026-08-16 20:09:42 +02:00
parent 5b8e535be0
commit d2099b9a6c
7 changed files with 178 additions and 2 deletions

37
.claude/settings.json Normal file
View File

@@ -0,0 +1,37 @@
{
"env": {
"CLAUDE_CODE_SCROLL_SPEED": "3",
"ANTHROPIC_MODEL": "sonnet"
},
"model": "opus[1m]",
"effortLevel": "high",
"autoUpdatesChannel": "latest",
"tui": "fullscreen",
"showMessageTimestamps": true,
"permissions": {
"defaultMode": "auto",
"allow": [],
"additionalDirectories": []
},
"enabledPlugins": {
"superpowers@claude-plugins-official": true,
"context7@claude-plugins-official": true,
"core@nicecode": true
},
"extraKnownMarketplaces": {
"nicecode": {
"source": {
"source": "github",
"repo": "lachtan/nicecode"
}
}
},
"spinnerVerbs": {
"mode": "replace",
"verbs": [
"Analyzing code",
"Crafting solutions",
"Working hard"
]
}
}

9
Caddyfile Normal file
View File

@@ -0,0 +1,9 @@
{
frankenphp
}
:80 {
root * /app/app/public
encode gzip
php_server
}

7
Dockerfile Normal file
View File

@@ -0,0 +1,7 @@
FROM dunglas/frankenphp:1-php8.3
RUN install-php-extensions curl yaml
WORKDIR /app
COPY app ./app
COPY Caddyfile /etc/frankenphp/Caddyfile

109
app/public/index.php Normal file
View File

@@ -0,0 +1,109 @@
<?php
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;
function sendPlainTextError(int $statusCode, string $message): never
{
http_response_code($statusCode);
header('Content-Type: text/plain; charset=utf-8');
echo $message . "\n";
exit;
}
function fetchRaw(string $relativePath): string|false
{
$url = REPO_RAW_BASE_URL . ltrim($relativePath, '/');
$curl = curl_init($url);
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FAILONERROR => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 3,
CURLOPT_TIMEOUT => FETCH_TIMEOUT_SECONDS,
]);
$content = curl_exec($curl);
return is_string($content) ? $content : false;
}
function escapeForDoubleQuotedShellString(string $value): string
{
return str_replace(['\\', '"', '$', '`'], ['\\\\', '\\"', '\\$', '\\`'], $value);
}
function resolveHomePath(string $path): string
{
if ($path === '~' || str_starts_with($path, '~/')) {
return '$HOME' . escapeForDoubleQuotedShellString(substr($path, 1));
}
return escapeForDoubleQuotedShellString($path);
}
function renderScriptTemplate(string $templateName, array $placeholders): string|false
{
$path = TEMPLATES_DIRECTORY . '/' . $templateName . '.sh.tpl';
if (!is_file($path)) {
return false;
}
$script = file_get_contents($path);
foreach ($placeholders as $key => $value) {
$script = str_replace('{{' . $key . '}}', $value, $script);
}
return $script;
}
$requestPath = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?? '/';
$name = trim(rawurldecode($requestPath), '/');
if ($name === '') {
sendPlainTextError(400, 'Missing name of the installable item');
}
$manifestYaml = fetchRaw(MANIFEST_PATH);
if ($manifestYaml === false) {
sendPlainTextError(502, 'Failed to fetch the manifest from git.fnet.cz');
}
$manifest = yaml_parse($manifestYaml);
if ($manifest === false) {
sendPlainTextError(502, 'Failed to parse the manifest from git.fnet.cz');
}
$entry = $manifest[$name] ?? null;
if ($entry === null) {
sendPlainTextError(404, "Unknown item '$name'");
}
if (!is_string($entry['source'] ?? null) || !is_string($entry['target'] ?? null) || !is_string($entry['template'] ?? null)) {
sendPlainTextError(500, "Malformed manifest entry for item '$name'");
}
$variables = [
'SOURCE_URL' => REPO_RAW_BASE_URL . escapeForDoubleQuotedShellString(ltrim($entry['source'], '/')),
'TARGET_PATH' => resolveHomePath($entry['target']),
'POST_INSTALL' => $entry['post_install'] ?? '',
];
$script = renderScriptTemplate($entry['template'], $variables);
if ($script === false) {
sendPlainTextError(500, 'Template for this item is missing');
}
header('Content-Type: text/x-shellscript; charset=utf-8');
echo $script;

View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail
readonly SOURCE_URL="{{SOURCE_URL}}"
readonly TARGET_PATH="{{TARGET_PATH}}"
mkdir -p "$(dirname "$TARGET_PATH")"
curl -fsSL "$SOURCE_URL" -o "$TARGET_PATH"
echo "Configuration installed: $TARGET_PATH"
{{POST_INSTALL}}

View File

@@ -1,8 +1,7 @@
# tmux config - screen-like key bindings # tmux config - screen-like key bindings
# ============================================ # ============================================
# mkdir -p $HOME/.config/tmux # mkdir -p $HOME/.config/tmux && curl https://git.fnet.cz/lachtan/get/raw/branch/master/conf/tmux.conf -o $HOME/.config/tmux/tmux.conf
# curl https://git.fnet.cz/lachtan/get/raw/branch/master/conf/tmux.conf -o $HOME/.config/tmux/tmux.conf
# Searched in this oreder: # Searched in this oreder:
# /etc/tmux.conf # /etc/tmux.conf

4
manifest.yaml Normal file
View File

@@ -0,0 +1,4 @@
tmux:
template: config
source: conf/tmux.conf
target: ~/.config/tmux/tmux.conf