Merge pull request 'Merge testing in main: 1.0.0 Release' (#14) from testing into main
Main Release & Publish / Build, Publish Packages (Stable) & Create Release (push) Successful in 52s
Main Release & Publish / Build, Publish Packages (Stable) & Create Release (push) Successful in 52s
Reviewed-on: #14
This commit was merged in pull request #14.
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
name: Main Release & Publish
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
release-and-publish:
|
||||
name: Build, Publish Packages (Stable) & Create Release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v7
|
||||
|
||||
- name: Install Rust Toolchain
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
cache: false
|
||||
|
||||
- name: Install Packaging Tools (Prebuilt Binaries)
|
||||
run: |
|
||||
mkdir -p ~/.cargo/bin
|
||||
curl -fsSL https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz | tar -xz -C ~/.cargo/bin
|
||||
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
|
||||
~/.cargo/bin/cargo-binstall -y --no-symlinks cargo-deb cargo-generate-rpm
|
||||
|
||||
- name: Run Tests
|
||||
run: |
|
||||
cargo test
|
||||
|
||||
- name: Build Release Binary
|
||||
run: |
|
||||
cargo build --release
|
||||
|
||||
- name: Build Debian Package (.deb)
|
||||
run: |
|
||||
cargo deb
|
||||
|
||||
- name: Build Fedora / RPM Package (.rpm)
|
||||
run: |
|
||||
cargo generate-rpm
|
||||
|
||||
- name: Build Arch Linux Package (.pkg.tar.zst)
|
||||
run: |
|
||||
python3 scripts/package-arch.py
|
||||
|
||||
- name: Publish Packages to Gitea Package Registry
|
||||
env:
|
||||
GITEA_URL: ${{ gitea.server_url || github.server_url }}
|
||||
REPO_OWNER: ${{ gitea.repository_owner || github.repository_owner }}
|
||||
TOKEN: ${{ secrets.PACKAGE_TOKEN || secrets.RELEASE_TOKEN || secrets.PUBLISH_TOKEN || secrets.API_TOKEN || secrets.PAT_TOKEN || secrets.CUSTOM_TOKEN || secrets.GITEA_TOKEN || secrets.GITHUB_TOKEN || github.token }}
|
||||
run: |
|
||||
echo "Veröffentliche Debian-Paket (Distribution: stable, Component: main)..."
|
||||
for deb in target/debian/*.deb; do
|
||||
[ -f "$deb" ] || continue
|
||||
curl -f -s -S -X PUT \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
--upload-file "$deb" \
|
||||
"${GITEA_URL}/api/packages/${REPO_OWNER}/debian/pool/stable/main/upload"
|
||||
done
|
||||
|
||||
echo "Veröffentliche Fedora/RPM-Paket (Gruppe: stable)..."
|
||||
for rpm in target/generate-rpm/*.rpm; do
|
||||
[ -f "$rpm" ] || continue
|
||||
curl -f -s -S -X PUT \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
--upload-file "$rpm" \
|
||||
"${GITEA_URL}/api/packages/${REPO_OWNER}/rpm/stable/upload"
|
||||
done
|
||||
|
||||
echo "Veröffentliche Arch Linux-Paket (Repository: stable)..."
|
||||
for pkg in target/arch/*.pkg.tar.zst; do
|
||||
[ -f "$pkg" ] || continue
|
||||
curl -f -s -S -X PUT \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
--upload-file "$pkg" \
|
||||
"${GITEA_URL}/api/packages/${REPO_OWNER}/arch/stable"
|
||||
done
|
||||
|
||||
- name: Create Gitea Release and Upload Assets
|
||||
env:
|
||||
GITEA_URL: ${{ gitea.server_url || github.server_url }}
|
||||
REPO: ${{ gitea.repository || github.repository }}
|
||||
TOKEN: ${{ secrets.PACKAGE_TOKEN || secrets.RELEASE_TOKEN || secrets.PUBLISH_TOKEN || secrets.API_TOKEN || secrets.PAT_TOKEN || secrets.CUSTOM_TOKEN || secrets.GITEA_TOKEN || secrets.GITHUB_TOKEN || github.token }}
|
||||
run: |
|
||||
VERSION="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)"
|
||||
TAG_NAME="v${VERSION}"
|
||||
RELEASE_TITLE="Release ${TAG_NAME}"
|
||||
RELEASE_NOTES="Automatisches Release für docker-update ${VERSION}."
|
||||
|
||||
echo "Erstelle oder hole Release für Tag ${TAG_NAME} in ${REPO}..."
|
||||
|
||||
GET_RESP=$(curl -s -w "\n%{http_code}" \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
"${GITEA_URL}/api/v1/repos/${REPO}/releases/tags/${TAG_NAME}")
|
||||
HTTP_CODE=$(echo "$GET_RESP" | tail -n1)
|
||||
BODY=$(echo "$GET_RESP" | sed '$d')
|
||||
|
||||
RELEASE_ID=""
|
||||
if [ "$HTTP_CODE" -eq 200 ]; then
|
||||
RELEASE_ID=$(echo "$BODY" | jq -r '.id // empty' 2>/dev/null || echo "$BODY" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)
|
||||
echo "Bestehendes Release gefunden (ID: ${RELEASE_ID})."
|
||||
else
|
||||
echo "Erstelle neues Release ${TAG_NAME}..."
|
||||
CREATE_PAYLOAD=$(cat <<EOF
|
||||
{
|
||||
"tag_name": "${TAG_NAME}",
|
||||
"target_commitish": "main",
|
||||
"name": "${RELEASE_TITLE}",
|
||||
"body": "${RELEASE_NOTES}",
|
||||
"draft": false,
|
||||
"prerelease": false
|
||||
}
|
||||
EOF
|
||||
)
|
||||
CREATE_RESP=$(curl -f -s -S -X POST \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$CREATE_PAYLOAD" \
|
||||
"${GITEA_URL}/api/v1/repos/${REPO}/releases")
|
||||
RELEASE_ID=$(echo "$CREATE_RESP" | jq -r '.id // empty' 2>/dev/null || echo "$CREATE_RESP" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)
|
||||
echo "Neues Release erstellt (ID: ${RELEASE_ID})."
|
||||
fi
|
||||
|
||||
if [ -z "$RELEASE_ID" ]; then
|
||||
echo "Fehler: Release-ID konnte nicht ermittelt werden!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
EXISTING_ASSETS_JSON=$(curl -s \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
"${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets" || echo "[]")
|
||||
|
||||
for file in target/debian/*.deb target/generate-rpm/*.rpm target/arch/*.pkg.tar.zst; do
|
||||
[ -f "$file" ] || continue
|
||||
filename="$(basename "$file")"
|
||||
echo "Lade Release-Asset hoch: $filename"
|
||||
|
||||
ASSET_ID=$(echo "$EXISTING_ASSETS_JSON" | jq -r --arg name "$filename" '.[]? | select(.name == $name) | .id' 2>/dev/null | head -n1 || true)
|
||||
if [ -n "$ASSET_ID" ] && [ "$ASSET_ID" != "null" ]; then
|
||||
echo "Lösche altes Asset mit ID ${ASSET_ID}..."
|
||||
curl -s -X DELETE \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
"${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets/${ASSET_ID}" || true
|
||||
fi
|
||||
|
||||
curl -f -s -S -X POST \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-F "attachment=@${file}" \
|
||||
"${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${filename}"
|
||||
echo "Asset ${filename} erfolgreich hochgeladen."
|
||||
done
|
||||
@@ -0,0 +1,154 @@
|
||||
name: Testing Build, Publish & Preview Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- testing
|
||||
|
||||
jobs:
|
||||
build-and-publish:
|
||||
name: Build, Publish Packages (Testing) & Create Preview Release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v7
|
||||
|
||||
- name: Install Rust Toolchain
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
cache: false
|
||||
|
||||
- name: Install Packaging Tools (Prebuilt Binaries)
|
||||
run: |
|
||||
mkdir -p ~/.cargo/bin
|
||||
curl -fsSL https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz | tar -xz -C ~/.cargo/bin
|
||||
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
|
||||
~/.cargo/bin/cargo-binstall -y --no-symlinks cargo-deb cargo-generate-rpm
|
||||
|
||||
- name: Run Tests
|
||||
run: |
|
||||
cargo test
|
||||
|
||||
- name: Build Release Binary
|
||||
run: |
|
||||
cargo build --release
|
||||
|
||||
- name: Build Debian Package (.deb)
|
||||
run: |
|
||||
cargo deb
|
||||
|
||||
- name: Build Fedora / RPM Package (.rpm)
|
||||
run: |
|
||||
cargo generate-rpm
|
||||
|
||||
- name: Build Arch Linux Package (.pkg.tar.zst)
|
||||
run: |
|
||||
python3 scripts/package-arch.py
|
||||
|
||||
- name: Publish Packages to Gitea Package Registry
|
||||
env:
|
||||
GITEA_URL: ${{ gitea.server_url || github.server_url }}
|
||||
REPO_OWNER: ${{ gitea.repository_owner || github.repository_owner }}
|
||||
TOKEN: ${{ secrets.PACKAGE_TOKEN || secrets.RELEASE_TOKEN || secrets.PUBLISH_TOKEN || secrets.API_TOKEN || secrets.PAT_TOKEN || secrets.CUSTOM_TOKEN || secrets.GITEA_TOKEN || secrets.GITHUB_TOKEN || github.token }}
|
||||
run: |
|
||||
echo "Veröffentliche Debian-Paket (Distribution: testing, Component: main)..."
|
||||
for deb in target/debian/*.deb; do
|
||||
[ -f "$deb" ] || continue
|
||||
curl -f -s -S -X PUT \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
--upload-file "$deb" \
|
||||
"${GITEA_URL}/api/packages/${REPO_OWNER}/debian/pool/testing/main/upload"
|
||||
done
|
||||
|
||||
echo "Veröffentliche Fedora/RPM-Paket (Gruppe: testing)..."
|
||||
for rpm in target/generate-rpm/*.rpm; do
|
||||
[ -f "$rpm" ] || continue
|
||||
curl -f -s -S -X PUT \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
--upload-file "$rpm" \
|
||||
"${GITEA_URL}/api/packages/${REPO_OWNER}/rpm/testing/upload"
|
||||
done
|
||||
|
||||
echo "Veröffentliche Arch Linux-Paket (Repository: testing)..."
|
||||
for pkg in target/arch/*.pkg.tar.zst; do
|
||||
[ -f "$pkg" ] || continue
|
||||
curl -f -s -S -X PUT \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
--upload-file "$pkg" \
|
||||
"${GITEA_URL}/api/packages/${REPO_OWNER}/arch/testing"
|
||||
done
|
||||
|
||||
- name: Create Gitea Pre-Release and Upload Assets
|
||||
env:
|
||||
GITEA_URL: ${{ gitea.server_url || github.server_url }}
|
||||
REPO: ${{ gitea.repository || github.repository }}
|
||||
TOKEN: ${{ secrets.PACKAGE_TOKEN || secrets.RELEASE_TOKEN || secrets.PUBLISH_TOKEN || secrets.API_TOKEN || secrets.PAT_TOKEN || secrets.CUSTOM_TOKEN || secrets.GITEA_TOKEN || secrets.GITHUB_TOKEN || github.token }}
|
||||
run: |
|
||||
VERSION="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)"
|
||||
TAG_NAME="v${VERSION}-preview"
|
||||
RELEASE_TITLE="Preview Release ${TAG_NAME}"
|
||||
RELEASE_NOTES="Automatisches Preview-Release für docker-update ${VERSION} (Branch: Testing)."
|
||||
|
||||
echo "Erstelle oder hole Preview-Release für Tag ${TAG_NAME} in ${REPO}..."
|
||||
|
||||
GET_RESP=$(curl -s -w "\n%{http_code}" \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
"${GITEA_URL}/api/v1/repos/${REPO}/releases/tags/${TAG_NAME}")
|
||||
HTTP_CODE=$(echo "$GET_RESP" | tail -n1)
|
||||
BODY=$(echo "$GET_RESP" | sed '$d')
|
||||
|
||||
RELEASE_ID=""
|
||||
if [ "$HTTP_CODE" -eq 200 ]; then
|
||||
RELEASE_ID=$(echo "$BODY" | jq -r '.id // empty' 2>/dev/null || echo "$BODY" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)
|
||||
echo "Bestehendes Release gefunden (ID: ${RELEASE_ID})."
|
||||
else
|
||||
echo "Erstelle neues Preview-Release ${TAG_NAME}..."
|
||||
CREATE_PAYLOAD=$(cat <<EOF
|
||||
{
|
||||
"tag_name": "${TAG_NAME}",
|
||||
"target_commitish": "testing",
|
||||
"name": "${RELEASE_TITLE}",
|
||||
"body": "${RELEASE_NOTES}",
|
||||
"draft": false,
|
||||
"prerelease": true
|
||||
}
|
||||
EOF
|
||||
)
|
||||
CREATE_RESP=$(curl -f -s -S -X POST \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$CREATE_PAYLOAD" \
|
||||
"${GITEA_URL}/api/v1/repos/${REPO}/releases")
|
||||
RELEASE_ID=$(echo "$CREATE_RESP" | jq -r '.id // empty' 2>/dev/null || echo "$CREATE_RESP" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)
|
||||
echo "Neues Preview-Release erstellt (ID: ${RELEASE_ID})."
|
||||
fi
|
||||
|
||||
if [ -z "$RELEASE_ID" ]; then
|
||||
echo "Fehler: Release-ID konnte nicht ermittelt werden!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
EXISTING_ASSETS_JSON=$(curl -s \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
"${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets" || echo "[]")
|
||||
|
||||
for file in target/debian/*.deb target/generate-rpm/*.rpm target/arch/*.pkg.tar.zst; do
|
||||
[ -f "$file" ] || continue
|
||||
filename="$(basename "$file")"
|
||||
echo "Lade Release-Asset hoch: $filename"
|
||||
|
||||
ASSET_ID=$(echo "$EXISTING_ASSETS_JSON" | jq -r --arg name "$filename" '.[]? | select(.name == $name) | .id' 2>/dev/null | head -n1 || true)
|
||||
if [ -n "$ASSET_ID" ] && [ "$ASSET_ID" != "null" ]; then
|
||||
echo "Lösche altes Asset mit ID ${ASSET_ID}..."
|
||||
curl -s -X DELETE \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
"${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets/${ASSET_ID}" || true
|
||||
fi
|
||||
|
||||
curl -f -s -S -X POST \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-F "attachment=@${file}" \
|
||||
"${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${filename}"
|
||||
echo "Asset ${filename} erfolgreich hochgeladen."
|
||||
done
|
||||
Generated
+10
@@ -0,0 +1,10 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Ignored default folder with query files
|
||||
/queries/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
Generated
+11
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="EMPTY_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
Generated
+28
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JsonSchemaMappingsProjectConfiguration">
|
||||
<state>
|
||||
<map>
|
||||
<entry key="GitHub Workflow">
|
||||
<value>
|
||||
<SchemaInfo>
|
||||
<option name="name" value="GitHub Workflow" />
|
||||
<option name="relativePathToSchema" value="https://www.schemastore.org/github-workflow.json" />
|
||||
<option name="applicationDefined" value="true" />
|
||||
<option name="patterns">
|
||||
<list>
|
||||
<Item>
|
||||
<option name="path" value=".gitea/workflows/testing.yaml" />
|
||||
</Item>
|
||||
<Item>
|
||||
<option name="path" value=".gitea/workflows/main.yaml" />
|
||||
</Item>
|
||||
</list>
|
||||
</option>
|
||||
</SchemaInfo>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</state>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+4
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GHAISettings">{}</component>
|
||||
</project>
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/DockerUpdater.iml" filepath="$PROJECT_DIR$/.idea/DockerUpdater.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RsVcsConfiguration">
|
||||
<option name="rustFmt" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,129 @@
|
||||
# AGENTS.md — Entwickler- und Agenten-Dokumentation für DockerUpdate
|
||||
|
||||
Diese Datei dient als Leitfaden und Kontextdokumentation für autonome Agenten und Entwickler, die an der Codebasis von
|
||||
`docker-update` arbeiten.
|
||||
|
||||
---
|
||||
|
||||
## 1. Projektübersicht
|
||||
|
||||
`docker-update` ist ein schlankes CLI-Werkzeug für **Linux-Server** (Rust 2024 Edition). Es durchsucht Verzeichnisse mit
|
||||
Docker-Compose-Dateien (standardmäßig `/var/apps`), prüft definierte Services mit `:latest`-Images auf neuere Versionen,
|
||||
lädt diese herunter, startet betroffene Services neu und bereinigt ungenutzte Zwischen-Images.
|
||||
|
||||
### Wichtige Rahmenbedingungen & Prinzipien
|
||||
|
||||
- **Reines Linux-Projekt**: Die Anwendung ist ausschließlich für Linux vorgesehen. Es dürfen keine Windows-spezifischen
|
||||
Konstrukte oder bedingten Nicht-Linux-Kompilierungen (`#[cfg(target_os = ...)]`) hinzugefügt werden.
|
||||
- **Root-Rechte**: Die Anwendung erfordert Root-Rechte zur Verwaltung von Docker und Compose-Services. Fehlen diese,
|
||||
eskaliert sie via `sudo`.
|
||||
- **Keine Unicode-Emojis im Logging**: Das Logging-Modul (`src/log.rs`) verwendet einheitliche ASCII-Präfixe (`[!]`
|
||||
Error, `[?]` Warn, `[i]` Info, `[d]` Debug).
|
||||
- **Lizenz**: GNU General Public License v3.0 or later (`GPL-3.0-or-later`).
|
||||
|
||||
---
|
||||
|
||||
## 2. Modul- und Codestruktur
|
||||
|
||||
```text
|
||||
DockerUpdate/
|
||||
├── .gitea/
|
||||
│ └── workflows/
|
||||
│ ├── testing.yaml # CI/CD für testing-Branch (Tests, Testing-Packages & Preview-Release)
|
||||
│ └── main.yaml # CI/CD für main-Branch (Tests, Stable-Packages & Release)
|
||||
├── scripts/
|
||||
│ └── package-arch.py # Hilfsskript zur Arch-Linux-Paketerstellung (.pkg.tar.zst)
|
||||
├── Cargo.toml # Rust-Manifest, Abhängigkeiten und Metadaten für deb / generate-rpm / arch
|
||||
├── Cargo.lock
|
||||
├── LICENSE # GPL-3.0 Lizenztext
|
||||
├── README.md # Projektdokumentation für Endanwender und Administratoren
|
||||
├── AGENTS.md # Richtlinien und Dokumentation für Agenten
|
||||
└── src/
|
||||
├── main.rs # Einstiegspunkt, Root-Prüfung, Ausführung
|
||||
├── program.rs # Hilfsfunktion zur Programmnamensermittlung
|
||||
├── sudo.rs # Root-Prüfung (geteuid == 0) und Re-Exec via sudo
|
||||
├── config.rs # Konfigurationsverwaltung (confy / TOML)
|
||||
├── log.rs # Threadsicheres Logging (Terminal + Datei im Temp-Verzeichnis)
|
||||
└── updater.rs # Scan-, Pull-, Restart- und Bereinigungslogik für Compose-Apps
|
||||
```
|
||||
|
||||
### Modulverantwortlichkeiten
|
||||
|
||||
- **`src/main.rs`**:
|
||||
Initialer Startpunkt. Prüft mit `sudo::is_run_as_root()`, ob Root-Rechte vorliegen. Wenn nicht, wird mit
|
||||
`sudo::run_as_root()` neu gestartet. Ruft anschließend `updater::run_updates()` auf.
|
||||
- **`src/updater.rs`**:
|
||||
- Sucht in Unterverzeichnissen von `apps_dir` nach Compose-Dateien (`docker-compose.yaml`, `docker-compose.yml`,
|
||||
`compose.yaml`, `compose.yml`).
|
||||
- Parst Services via `serde_yaml` und filtert mit `is_latest_image()` nach Services mit `:latest`-Images oder ohne
|
||||
expliziten Tag.
|
||||
- Führt `docker pull` für jedes gefundene Image aus und vergleicht Vorher/Nachher-Image-IDs via
|
||||
`docker image inspect`.
|
||||
- Startet bei Änderungen Services neu (`docker compose up -d` mit Fallback auf `docker-compose up -d`).
|
||||
- Führt nach Updates `docker image prune -f` aus.
|
||||
- **`src/config.rs`**:
|
||||
- Lädt und speichert die Konfiguration (`AppConfig`, `General` mit `apps_dir` und `log_level`).
|
||||
- Standardpfade: `/etc/docker-update/config.toml` (Root) bzw. `~/.config/docker-update/config.toml` (Benutzer).
|
||||
- **`src/log.rs`**:
|
||||
- Formatiert Logmeldungen nach Schema `[Präfix][Zeitstempel][LEVEL][Tag]: Nachricht`.
|
||||
- Gibt auf Konsole aus und schreibt zusätzlich in tagesbasierte Logdateien im Temp-Verzeichnis
|
||||
(`/tmp/docker-update-.../log-YYYY-MM-DD.log`).
|
||||
- **`src/sudo.rs`**:
|
||||
- `is_run_as_root()`: Nutzt `libc::geteuid() == 0`.
|
||||
- `run_as_root()`: Führt `sudo <args>` per `exec` aus.
|
||||
- **`.gitea/workflows/`**:
|
||||
- `testing.yaml`: Führt bei Push auf `testing` Tests und Builds durch, veröffentlicht Pakete in der Gitea Package
|
||||
Registry
|
||||
(`distribution: testing`, `component: main` bzw. Gruppe/Repo `testing`) und erstellt ein Gitea Preview-Release mit
|
||||
den Paketen als Assets.
|
||||
- `main.yaml`: Führt bei Push auf `main` Tests und Builds durch, veröffentlicht Pakete in der Gitea Package Registry
|
||||
(`distribution: stable`, `component: main` bzw. Gruppe/Repo `stable`) und erstellt ein Gitea Release mit den
|
||||
Paketen als Assets.
|
||||
|
||||
---
|
||||
|
||||
## 3. Build-, Test- und Prüfbefehle
|
||||
|
||||
Vor jedem Commit oder Abschluss einer Aufgabe müssen folgende Befehle erfolgreich durchlaufen:
|
||||
|
||||
```bash
|
||||
# 1. Compiler- und Typ-Prüfung für alle Targets
|
||||
cargo check --all-targets
|
||||
|
||||
# 2. Ausführen aller Unit-Tests
|
||||
cargo test
|
||||
|
||||
# 3. Release-Build kompilieren
|
||||
cargo build --release
|
||||
```
|
||||
|
||||
### Optionale Paketierungsbefehle (lokale Validierung)
|
||||
|
||||
```bash
|
||||
# Debian-Paket (.deb) erstellen (benötigt cargo-deb)
|
||||
cargo deb
|
||||
|
||||
# Fedora / RPM-Paket (.rpm) erstellen (benötigt cargo-generate-rpm)
|
||||
cargo generate-rpm
|
||||
|
||||
# Arch Linux-Paket (.pkg.tar.zst) erstellen
|
||||
python3 scripts/package-arch.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Richtlinien für Änderungen
|
||||
|
||||
1. **Abwärtskompatibilität & Pfade**:
|
||||
Der Standard-Apps-Pfad `/var/apps` und die Konfigurationspfade dürfen nicht ohne triftigen Grund geändert werden.
|
||||
2. **Paketierungsdefinitionen in Cargo.toml pflegen**:
|
||||
Alle Paketierungsdefinitionen für Debian, RPM und Arch Linux werden zentral in `Cargo.toml` verwaltet
|
||||
(`[package.metadata.deb]`, `[package.metadata.generate-rpm]`, `[package.metadata.arch]`). Es wird kein separater
|
||||
`packaging/`-Ordner benötigt.
|
||||
3. **Automatisierung**:
|
||||
Die empfohlene Automatisierungsmethode ist **Cron** (`/etc/cron.d/docker-update` oder `crontab -e`).
|
||||
4. **Keine Mocking-Bypässe**:
|
||||
Tests dürfen nicht gelöscht, ignoriert oder durch leere Dummy-Assertions ersetzt werden.
|
||||
5. **CI/CD & Release-Konsistenz**:
|
||||
Workflows in `.gitea/workflows/` müssen bei strukturellen Paket- oder Release-Anpassungen konsistent zu `Cargo.toml`
|
||||
gehalten werden.
|
||||
Generated
+416
@@ -0,0 +1,416 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "confy"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8807c397789cbe02bbdb1a27ea5f345584132808697b2a3f957c829829ee4814"
|
||||
dependencies = [
|
||||
"etcetera",
|
||||
"lazy_static",
|
||||
"serde",
|
||||
"thiserror",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deranged"
|
||||
version = "0.5.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c"
|
||||
|
||||
[[package]]
|
||||
name = "docker-update"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"confy",
|
||||
"libc 1.0.0-alpha.4",
|
||||
"serde",
|
||||
"serde_yaml",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "etcetera"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26c7b13d0780cb82722fd59f6f57f925e143427e4a75313a6c77243bf5326ae6"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"home",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
||||
|
||||
[[package]]
|
||||
name = "home"
|
||||
version = "0.5.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d"
|
||||
dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.189"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "1.0.0-alpha.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d0f24f33af482526a4e3f9b47f0abb2c6377a1713c8aa4a8106994689a4cfa5"
|
||||
|
||||
[[package]]
|
||||
name = "num-conv"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441"
|
||||
|
||||
[[package]]
|
||||
name = "num_threads"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9"
|
||||
dependencies = [
|
||||
"libc 0.2.189",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "powerfmt"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_spanned"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_yaml"
|
||||
version = "0.9.34+deprecated"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
"unsafe-libyaml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "3.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"libc 0.2.189",
|
||||
"num-conv",
|
||||
"num_threads",
|
||||
"powerfmt",
|
||||
"serde_core",
|
||||
"time-core",
|
||||
"time-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time-core"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109"
|
||||
|
||||
[[package]]
|
||||
name = "time-macros"
|
||||
version = "0.2.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7e689342a48d2ea927c87ea50cabf8594854bf940e9310208848d680d668ed85"
|
||||
dependencies = [
|
||||
"num-conv",
|
||||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.9.12+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf92845e79fc2e2def6a5d828f0801e29a2f8acc037becc5ab08595c7d5e9863"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde_core",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"toml_parser",
|
||||
"toml_writer",
|
||||
"winnow 0.7.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.7.5+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_parser"
|
||||
version = "1.1.3+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d38ac1cf9b95face32296c0a3ede1fdc270627c9d9c02a7274dd6d960dc4d56"
|
||||
dependencies = [
|
||||
"winnow 1.0.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_writer"
|
||||
version = "1.1.2+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||
|
||||
[[package]]
|
||||
name = "unsafe-libyaml"
|
||||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.59.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.61.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.7.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81"
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
[package]
|
||||
name = "docker-update"
|
||||
version = "1.0.0"
|
||||
edition = "2024"
|
||||
authors = ['DragonSlayer_14']
|
||||
readme = "README.md"
|
||||
license = "GPL-3.0-or-later"
|
||||
repository = "https://gitea.creative-dragonslayer.de/Linuxapps/DockerUpdate"
|
||||
description = "Automatisches Aktualisieren von Docker-Compose-Anwendungen in /var/apps mit :latest-Images"
|
||||
|
||||
[dependencies]
|
||||
time = { version="0.3.41", features = ["formatting", "macros", "local-offset"] }
|
||||
serde = { version="1.0.219", features = ["derive"] }
|
||||
serde_yaml = "0.9"
|
||||
confy = "2.0.0"
|
||||
libc = "1.0.0-alpha.1"
|
||||
|
||||
[profile.release]
|
||||
debug = "none"
|
||||
|
||||
[package.metadata.deb]
|
||||
name = "docker-update"
|
||||
maintainer = "DragonSlayer_14"
|
||||
copyright = "2026 Linuxapps"
|
||||
section = "utils"
|
||||
priority = "optional"
|
||||
depends = "$auto, sudo, docker-ce-cli, docker-compose-plugin"
|
||||
extended-description = """\
|
||||
DockerUpdate durchsucht Verzeichnisse (standardmäßig in /var/apps) nach
|
||||
Docker-Compose-Dateien mit ':latest'-Images, prüft auf neuere Images,
|
||||
lädt diese herunter und startet die betroffenen Container automatisch neu.\
|
||||
"""
|
||||
assets = [
|
||||
["target/release/docker-update", "usr/bin/docker-update", "755"],
|
||||
["README.md", "usr/share/doc/docker-update/README.md", "644"],
|
||||
["LICENSE", "usr/share/doc/docker-update/copyright", "644"],
|
||||
]
|
||||
|
||||
[package.metadata.generate-rpm]
|
||||
assets = [
|
||||
{ source = "target/release/docker-update", dest = "/usr/bin/docker-update", mode = "755" },
|
||||
{ source = "README.md", dest = "/usr/share/doc/docker-update/README.md", mode = "644", doc = true },
|
||||
{ source = "LICENSE", dest = "/usr/share/licenses/docker-update/LICENSE", mode = "644", license = true },
|
||||
]
|
||||
requires = { "sudo" = "*", "docker" = "*" }
|
||||
|
||||
[package.metadata.arch]
|
||||
pkgrel = "1"
|
||||
arch = "x86_64"
|
||||
depends = ["gcc-libs", "glibc", "sudo", "docker-ce-cli", "docker-compose-plugin"]
|
||||
optdepends = ["docker-compose: Unterstützung für Docker Compose v1"]
|
||||
@@ -1,3 +1,343 @@
|
||||
# DockerUpdater
|
||||
# DockerUpdate (`docker-update`)
|
||||
|
||||
Hilft dabei installierte Anwendungen über docker-compose.yaml in /var/apps aktuell zu halten.
|
||||
`docker-update` ist ein schlankes CLI-Werkzeug für Linux-Server, das Docker-Compose-basierte Applikationen automatisch
|
||||
auf neuere Versionen prüft, aktualisiert und neu startet.
|
||||
|
||||
## Funktionsweise
|
||||
|
||||
1. **Durchsuchen von Applikationsverzeichnissen**:
|
||||
Standardmäßig scannt `docker-update` alle Unterverzeichnisse in `/var/apps/` (konfigurierbar) nach gültigen
|
||||
Compose-Dateien (`docker-compose.yaml`, `docker-compose.yml`, `compose.yaml`, `compose.yml`).
|
||||
2. **Erkennung von `:latest`-Images**:
|
||||
Services in den Compose-Dateien werden analysiert. Es werden gezielt Services berücksichtigt, deren Image das
|
||||
`:latest`-Tag nutzt oder implizit auf `latest` verweist (kein Tag angegeben).
|
||||
3. **Prüfung auf neuere Images & Download**:
|
||||
Das Programm führt für jedes betroffene Image einen `docker pull` durch und vergleicht die Image-IDs vor und nach dem
|
||||
Pull.
|
||||
4. **Automatischer Neustart**:
|
||||
Wurde ein neues Image heruntergeladen, wird die Applikation im jeweiligen Verzeichnis über `docker compose up -d`
|
||||
(mit Fallback auf `docker-compose up -d`) aktualisiert und neu gestartet.
|
||||
5. **Bereinigung**:
|
||||
Nach erfolgreichen Aktualisierungen werden ungenutzte Zwischen-Images automatisch mittels `docker image prune -f`
|
||||
bereinigt.
|
||||
6. **Berechtigungen & Logging**:
|
||||
Wird das Programm ohne Root-Rechte gestartet, startet es sich automatisch über `sudo` mit erhöhten Rechten neu.
|
||||
Ausgaben werden auf der Konsole formatiert und zusätzlich tagesbasiert im System-Temp-Verzeichnis protokolliert (z.
|
||||
B. `/tmp/docker-update-.../log-YYYY-MM-DD.log`).
|
||||
|
||||
---
|
||||
|
||||
## Voraussetzungen
|
||||
|
||||
- **Betriebssystem**: Linux (x86_64, aarch64)
|
||||
- **Laufzeit-Abhängigkeiten**:
|
||||
- `docker` (inkl. Docker Compose Plugin `docker compose` oder Standalone `docker-compose`)
|
||||
- `sudo`
|
||||
- **Build-Abhängigkeiten** (nur zum Kompilieren/Paketieren):
|
||||
- Rust & Cargo (Rust 2024 Edition / 1.85+)
|
||||
|
||||
---
|
||||
|
||||
## Installation aus der Gitea-Paket-Registry
|
||||
|
||||
Über die CI/CD-Pipelines werden bei jedem Push auf den `main`-Branch (Release / Stable) und `testing`-Branch (Preview /
|
||||
Testing) automatisch Pakete für **Debian/Ubuntu**, **Fedora/RHEL** und **Arch Linux** in der Gitea-Paket-Registry
|
||||
bereitgestellt.
|
||||
|
||||
### 1. Debian / Ubuntu (`apt`)
|
||||
|
||||
#### Stable (Produktiv)
|
||||
|
||||
Füge das Repository zu deinen APT-Quellen hinzu:
|
||||
|
||||
```bash
|
||||
# Keyring installieren
|
||||
sudo curl https://gitea.creative-dragonslayer.de/api/packages/Linuxapps/debian/repository.key -o /etc/apt/keyrings/gitea-Linuxapps.asc
|
||||
# Repository-Eintrag anlegen
|
||||
echo "deb [signed-by=/etc/apt/keyrings/gitea-Linuxapps.asc] https://gitea.creative-dragonslayer.de/api/packages/Linuxapps/debian stable main" | sudo tee -a /etc/apt/sources.list.d/gitea.list
|
||||
|
||||
# Paketliste aktualisieren und installieren
|
||||
sudo apt update
|
||||
sudo apt install docker-update
|
||||
```
|
||||
|
||||
#### Testing (Vorschau / Testing)
|
||||
|
||||
```bash
|
||||
# Keyring installieren
|
||||
sudo curl https://gitea.creative-dragonslayer.de/api/packages/Linuxapps/debian/repository.key -o /etc/apt/keyrings/gitea-Linuxapps.asc
|
||||
# Testing-Repository-Eintrag anlegen
|
||||
echo "deb [signed-by=/etc/apt/keyrings/gitea-Linuxapps.asc] https://gitea.creative-dragonslayer.de/api/packages/Linuxapps/debian testing main" | sudo tee -a /etc/apt/sources.list.d/gitea.list
|
||||
|
||||
# Paketliste aktualisieren und installieren
|
||||
sudo apt update
|
||||
sudo apt install docker-update
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2. RedHat / Fedora / SUSE
|
||||
|
||||
#### Stable (Produktiv)
|
||||
|
||||
Repository einrichten:
|
||||
```bash
|
||||
# auf RedHat-basierten Distributionen
|
||||
dnf config-manager --add-repo https://gitea.creative-dragonslayer.de/api/packages/Linuxapps/rpm/stable.repo
|
||||
|
||||
# Fedora 41+ (DNF5)
|
||||
dnf config-manager addrepo --from-repofile=https://gitea.creative-dragonslayer.de/api/packages/Linuxapps/rpm/stable.repo
|
||||
|
||||
# auf SUSE-basierten Distributionen
|
||||
zypper addrepo https://gitea.creative-dragonslayer.de/api/packages/Linuxapps/rpm/stable.repo
|
||||
```
|
||||
|
||||
Paket installieren:
|
||||
|
||||
```bash
|
||||
# auf RedHat-basierten Distributionen
|
||||
dnf install docker-update
|
||||
|
||||
# auf SUSE-basierten Distributionen
|
||||
zypper install docker-update
|
||||
```
|
||||
|
||||
#### Testing (Vorschau / Testing)
|
||||
|
||||
Repository einrichten:
|
||||
```bash
|
||||
# auf RedHat-basierten Distributionen
|
||||
dnf config-manager --add-repo https://gitea.creative-dragonslayer.de/api/packages/Linuxapps/rpm/testing.repo
|
||||
|
||||
# Fedora 41+ (DNF5)
|
||||
dnf config-manager addrepo --from-repofile=https://gitea.creative-dragonslayer.de/api/packages/Linuxapps/rpm/testing.repo
|
||||
|
||||
# auf SUSE-basierten Distributionen
|
||||
zypper addrepo https://gitea.creative-dragonslayer.de/api/packages/Linuxapps/rpm/testing.repo
|
||||
```
|
||||
|
||||
Paket installieren:
|
||||
|
||||
```bash
|
||||
# auf RedHat-basierten Distributionen
|
||||
dnf install docker-update
|
||||
|
||||
# auf SUSE-basierten Distributionen
|
||||
zypper install docker-update
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3. Arch Linux (`pacman`)
|
||||
|
||||
### Installiere den GPG-Key für das Repository
|
||||
|
||||
Key herunterladen:
|
||||
|
||||
```bash
|
||||
wget https://gitea.creative-dragonslayer.de/api/packages/Linuxapps/arch/repository.key
|
||||
```
|
||||
|
||||
ID des Keys anzeigen lassen:
|
||||
|
||||
```bash
|
||||
gpg --show-keys repository.key
|
||||
```
|
||||
|
||||
Key zu pacman hinzufügen und signieren:
|
||||
|
||||
```
|
||||
pacman-key --add repository.key
|
||||
pacman-key --lsign-key {key id}
|
||||
```
|
||||
|
||||
{key id} = ID aus dem vorherigen Schritt
|
||||
|
||||
#### Stable (Produktiv)
|
||||
|
||||
Füge das Repository in `/etc/pacman.conf` ein:
|
||||
```ini
|
||||
[stable]
|
||||
SigLevel = Optional TrustAll
|
||||
Server = https://gitea.creative-dragonslayer.de/api/packages/Linuxapps/arch/stable/x86_64
|
||||
```
|
||||
|
||||
Installiere das Paket anschließend:
|
||||
|
||||
```bash
|
||||
sudo pacman -Sy docker-update
|
||||
```
|
||||
|
||||
#### Testing (Vorschau / Testing)
|
||||
|
||||
Füge das Testing-Repository in `/etc/pacman.conf` ein:
|
||||
|
||||
```ini
|
||||
[testing]
|
||||
SigLevel = Optional TrustAll
|
||||
Server = https://gitea.creative-dragonslayer.de/api/packages/Linuxapps/arch/testing/x86_64
|
||||
```
|
||||
|
||||
Installiere das Paket:
|
||||
|
||||
```bash
|
||||
sudo pacman -Sy docker-update
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Download vorgefertigter Pakete (Releases)
|
||||
|
||||
Alternativ können vorkompilierte Pakete (`.deb`, `.rpm`, `.pkg.tar.zst`) auch direkt aus den Releases heruntergeladen
|
||||
und manuell installiert werden:
|
||||
|
||||
- **Stable-Releases**: [Gitea Releases](https://gitea.creative-dragonslayer.de/Linuxapps/DockerUpdate/releases)
|
||||
- **Preview-Releases (Testing)**: Markiert als Vorabveröffentlichung (*Pre-release*) mit dem Tag `v<VERSION>-preview`.
|
||||
|
||||
---
|
||||
|
||||
## Manuelle Installation (Build from Source)
|
||||
|
||||
```bash
|
||||
# Repository klonen
|
||||
git clone https://gitea.creative-dragonslayer.de/Linuxapps/DockerUpdate.git
|
||||
cd DockerUpdate
|
||||
|
||||
# Release-Binary kompilieren
|
||||
cargo build --release
|
||||
|
||||
# Binary ins Systemverzeichnis installieren
|
||||
sudo install -m 755 target/release/docker-update /usr/bin/docker-update
|
||||
```
|
||||
|
||||
Anschließend kann das Programm direkt über `docker-update` ausgeführt werden:
|
||||
|
||||
```bash
|
||||
docker-update
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Konfiguration
|
||||
|
||||
Die Konfigurationsdatei wird standardmäßig unter folgendem Pfad abgelegt:
|
||||
|
||||
- **Root-Ausführung**: `/etc/docker-update/config.toml`
|
||||
- **Benutzer-Ausführung**: `~/.config/docker-update/config.toml`
|
||||
|
||||
Wird keine Datei gefunden, verwendet `docker-update` die Standardwerte.
|
||||
|
||||
### Beispiel-Konfiguration (`config.toml`)
|
||||
|
||||
```toml
|
||||
[general]
|
||||
# Verzeichnis, in dem sich die Applikationsordner mit Compose-Dateien befinden
|
||||
apps_dir = "/var/apps"
|
||||
|
||||
# Log-Level: "error", "warn", "info", "debug"
|
||||
log_level = "info"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Paketerstellung
|
||||
|
||||
Für gängige Linux-Distributionen stehen vorbereitete Paketierungsdefinitionen zur Verfügung.
|
||||
|
||||
### 1. Debian / Ubuntu (`.deb`)
|
||||
|
||||
Das Debian-Paket kann mithilfe von [`cargo-deb`](https://github.com/kornelski/cargo-deb) erstellt werden:
|
||||
|
||||
```bash
|
||||
# cargo-deb installieren (falls noch nicht vorhanden)
|
||||
cargo install cargo-deb
|
||||
|
||||
# Release-Build und Debian-Paket erstellen
|
||||
cargo deb
|
||||
|
||||
# Installation des erstellten Pakets
|
||||
sudo dpkg -i target/debian/docker-update_*.deb
|
||||
```
|
||||
|
||||
Die Paketkonfiguration und Abhängigkeiten (`sudo`, `docker.io | docker-ce`) sind in `Cargo.toml` unter
|
||||
`[package.metadata.deb]` definiert.
|
||||
|
||||
---
|
||||
|
||||
### 2. Arch Linux (`.pkg.tar.zst`)
|
||||
|
||||
Die Paketmetadaten und Abhängigkeiten für Arch Linux sind direkt in `Cargo.toml` unter `[package.metadata.arch]`
|
||||
hinterlegt. Das Paket kann nach dem Kompilieren des Release-Builds über das Skript `scripts/package-arch.py` (analog zu
|
||||
CI/CD) erzeugt
|
||||
werden:
|
||||
|
||||
```bash
|
||||
# Release kompilieren
|
||||
cargo build --release
|
||||
|
||||
# Arch Linux-Paket (.pkg.tar.zst) erstellen
|
||||
python3 scripts/package-arch.py
|
||||
|
||||
# Installation des erstellten Pakets
|
||||
sudo pacman -U target/arch/docker-update-*.pkg.tar.zst
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3. Fedora / RHEL / CentOS (`.rpm`)
|
||||
|
||||
Das RPM-Paket wird mithilfe von [`cargo-generate-rpm`](https://github.com/cat-in-136/cargo-generate-rpm) direkt aus den
|
||||
Metadaten in `Cargo.toml` (`[package.metadata.generate-rpm]`) erstellt:
|
||||
|
||||
```bash
|
||||
# cargo-generate-rpm installieren (falls noch nicht vorhanden)
|
||||
cargo install cargo-generate-rpm
|
||||
|
||||
# Release bauen und RPM erzeugen
|
||||
cargo build --release
|
||||
cargo generate-rpm
|
||||
|
||||
# Installation des erstellten RPM-Pakets
|
||||
sudo dnf install target/generate-rpm/docker-update-*.rpm
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Automatisierung (Cron)
|
||||
|
||||
Um `docker-update` regelmäßig (z. B. täglich nachts um 03:30 Uhr) automatisch auszuführen, kann ein Cronjob eingerichtet
|
||||
werden. Da `docker-update` Root-Rechte benötigt, sollte der Cronjob mit Root-Rechten ausgeführt werden.
|
||||
|
||||
### Option A: Über `/etc/cron.d/docker-update` (Empfohlen für Server)
|
||||
|
||||
Erstelle eine Datei `/etc/cron.d/docker-update`:
|
||||
|
||||
```bash
|
||||
sudo tee /etc/cron.d/docker-update << 'EOF'
|
||||
# Täglich um 03:30 Uhr docker-update als root ausführen
|
||||
30 3 * * * root /usr/bin/docker-update >/dev/null 2>&1
|
||||
EOF
|
||||
|
||||
sudo chmod 644 /etc/cron.d/docker-update
|
||||
```
|
||||
|
||||
### Option B: Über die Root-Crontab (`crontab -e`)
|
||||
|
||||
Öffne die Crontab des Root-Benutzers:
|
||||
|
||||
```bash
|
||||
sudo crontab -e
|
||||
```
|
||||
|
||||
Füge folgende Zeile ein:
|
||||
|
||||
```cron
|
||||
30 3 * * * /usr/bin/docker-update >/dev/null 2>&1
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Lizenz
|
||||
|
||||
Dieses Projekt ist unter der **GNU General Public License v3.0 or later (GPL-3.0-or-later)** lizenziert. Weitere
|
||||
Informationen finden sich in der Datei [LICENSE](LICENSE).
|
||||
|
||||
Executable
+71
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
|
||||
def main():
|
||||
metadata = json.loads(subprocess.check_output(["cargo", "metadata", "--format-version", "1", "--no-deps"]))
|
||||
pkg = metadata["packages"][0]
|
||||
name = pkg["name"]
|
||||
version = pkg["version"]
|
||||
description = pkg.get("description", "")
|
||||
license_name = pkg.get("license", "")
|
||||
repository = pkg.get("repository", "")
|
||||
authors = pkg.get("authors", [])
|
||||
author = authors[0] if authors else "Unknown"
|
||||
|
||||
arch_meta = pkg.get("metadata", {}).get("arch", {})
|
||||
pkgrel = arch_meta.get("pkgrel", "1")
|
||||
arch = arch_meta.get("arch", "x86_64")
|
||||
depends = arch_meta.get("depends", ["gcc-libs", "glibc", "sudo", "docker-ce-cli", "docker-compose-plugin"])
|
||||
optdepends = arch_meta.get("optdepends", ["docker-compose: Unterstützung für Docker Compose v1"])
|
||||
|
||||
with tempfile.TemporaryDirectory() as build_dir:
|
||||
bin_dir = os.path.join(build_dir, "usr/bin")
|
||||
doc_dir = os.path.join(build_dir, f"usr/share/doc/{name}")
|
||||
lic_dir = os.path.join(build_dir, f"usr/share/licenses/{name}")
|
||||
os.makedirs(bin_dir, exist_ok=True)
|
||||
os.makedirs(doc_dir, exist_ok=True)
|
||||
os.makedirs(lic_dir, exist_ok=True)
|
||||
|
||||
subprocess.run(["install", "-m", "755", f"target/release/{name}", f"{bin_dir}/{name}"], check=True)
|
||||
if os.path.exists("LICENSE"):
|
||||
subprocess.run(["install", "-m", "644", "LICENSE", f"{lic_dir}/LICENSE"], check=True)
|
||||
if os.path.exists("README.md"):
|
||||
subprocess.run(["install", "-m", "644", "README.md", f"{doc_dir}/README.md"], check=True)
|
||||
|
||||
installed_size = subprocess.check_output(["du", "-sb", build_dir]).decode().split()[0]
|
||||
builddate = str(int(time.time()))
|
||||
|
||||
pkginfo_lines = [
|
||||
f"pkgname = {name}",
|
||||
f"pkgbase = {name}",
|
||||
f"pkgver = {version}-{pkgrel}",
|
||||
f"pkgdesc = {description}",
|
||||
f"url = {repository}",
|
||||
f"builddate = {builddate}",
|
||||
f"packager = {author}",
|
||||
f"size = {installed_size}",
|
||||
f"arch = {arch}",
|
||||
f"license = {license_name}",
|
||||
]
|
||||
for dep in depends:
|
||||
pkginfo_lines.append(f"depend = {dep}")
|
||||
for optdep in optdepends:
|
||||
pkginfo_lines.append(f"optdepend = {optdep}")
|
||||
pkginfo_lines.append("makepkgopt = strip\n")
|
||||
|
||||
with open(os.path.join(build_dir, ".PKGINFO"), "w") as f:
|
||||
f.write("\n".join(pkginfo_lines))
|
||||
|
||||
os.makedirs("target/arch", exist_ok=True)
|
||||
output_file = os.path.abspath(f"target/arch/{name}-{version}-{pkgrel}-{arch}.pkg.tar.zst")
|
||||
subprocess.run(["tar", "--zstd", "-cf", output_file, ".PKGINFO", "usr"], cwd=build_dir, check=True)
|
||||
print(f"Arch-Paket erfolgreich erstellt: {output_file}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
//! Modul für die Konfigurationsverwaltung der Anwendung.
|
||||
//!
|
||||
//! Dieses Modul stellt die Funktionalität zum Laden, Speichern und Verwalten
|
||||
//! der Anwendungskonfiguration bereit. Die Konfiguration wird in einer Datei gespeichert
|
||||
//! und beim Programmstart automatisch geladen.
|
||||
|
||||
use crate::program;
|
||||
use crate::sudo::is_run_as_root;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::OnceLock;
|
||||
|
||||
/// Hauptkonfigurationsstruktur der Anwendung.
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct AppConfig {
|
||||
/// Allgemeine Einstellungen
|
||||
pub general: General,
|
||||
}
|
||||
|
||||
impl Default for AppConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
general: General::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Allgemeine Konfigurationseinstellungen.
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct General {
|
||||
/// Log-Level für die Anwendung (error, warn, info, debug)
|
||||
pub log_level: String,
|
||||
/// Pfad zum Verzeichnis mit den Docker-Applikationen
|
||||
pub apps_dir: String,
|
||||
}
|
||||
|
||||
impl Default for General {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
log_level: "info".to_string(),
|
||||
apps_dir: "/var/apps".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static CONFIG_NAME: &str = "config";
|
||||
static CONFIG: OnceLock<AppConfig> = OnceLock::new();
|
||||
|
||||
/// Gibt die aktuelle Konfiguration zurück.
|
||||
///
|
||||
/// Lädt die Konfiguration beim ersten Aufruf und speichert sie zwischen.
|
||||
/// Nachfolgende Aufrufe geben die gespeicherte Konfiguration zurück.
|
||||
pub fn get_config() -> &'static AppConfig {
|
||||
CONFIG.get_or_init(|| {
|
||||
load_config()
|
||||
})
|
||||
}
|
||||
|
||||
/// Modifiziert die aktuelle Konfiguration mit der übergebenen Mutator-Funktion.
|
||||
///
|
||||
/// Die Funktion lädt die Konfiguration neu von der Festplatte, wendet die Mutator-Funktion an
|
||||
/// und speichert die geänderte Konfiguration anschließend wieder.
|
||||
#[allow(dead_code)]
|
||||
pub fn modify_config<F>(mutator: F)
|
||||
where
|
||||
F: FnOnce(&mut AppConfig),
|
||||
{
|
||||
// Immer frisch von Disk laden, damit Änderungen konsistent sind
|
||||
let mut cfg = load_config();
|
||||
mutator(&mut cfg);
|
||||
save_config(cfg);
|
||||
}
|
||||
|
||||
/// Lädt die Konfiguration aus der Konfigurationsdatei.
|
||||
fn load_config() -> AppConfig {
|
||||
if is_run_as_root() {
|
||||
return confy::load_path(format!("/etc/{}/{}.toml", program::program_name(), CONFIG_NAME)).unwrap_or_default();
|
||||
}
|
||||
confy::load(&*program::program_name(), CONFIG_NAME).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Speichert die übergebene Konfiguration in der Konfigurationsdatei.
|
||||
#[allow(dead_code)]
|
||||
fn save_config(config: AppConfig) {
|
||||
if is_run_as_root() {
|
||||
let _ = confy::store_path(format!("/etc/{}/{}.toml", program::program_name(), CONFIG_NAME), config);
|
||||
return;
|
||||
}
|
||||
let _ = confy::store(&*program::program_name(), CONFIG_NAME, config);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_default_config() {
|
||||
let config = AppConfig::default();
|
||||
assert_eq!(config.general.apps_dir, "/var/apps");
|
||||
assert_eq!(config.general.log_level, "info");
|
||||
}
|
||||
}
|
||||
+254
@@ -0,0 +1,254 @@
|
||||
//! Einfaches, threadsicheres Logging-Modul.
|
||||
//!
|
||||
//! Merkmale:
|
||||
//! - Ausgabe auf Standard-Streams (stdout/stderr) und zusätzlich in eine Logdatei im temporären Verzeichnis.
|
||||
//! - Nachrichtenvorlage: `[DD.MM.YYYY HH:MM:SS.mmm][LEVEL][TAG]: <Text>` mit Präfix ([!]/[?]/[i]/[d]).
|
||||
//! - Der aktuell verwendete Schweregradfilter ist statisch (`LOG_LEVEL`) und wird zur Laufzeit nicht geändert.
|
||||
//! - Dateihandle wird lazily initialisiert und zwischengespeichert (`OnceLock`).
|
||||
//!
|
||||
//! Hinweise:
|
||||
//! - Bei einem leeren `tag` wird ein leerer Tag-Abschnitt erzeugt.
|
||||
//! - Die Logdatei wird unterhalb eines prozessspezifischen Ordners im System-Temp-Verzeichnis abgelegt und nach Datum
|
||||
//! benannt (z. B. `log-2025-08-18.log`). Es wird im Append-Modus geschrieben.
|
||||
//!
|
||||
//! Beispiel (ohne Ausführung in Doctests):
|
||||
//! ```rust,no_run
|
||||
//! use crate::log::{log, LogLevel};
|
||||
//!
|
||||
//! log("startup", "Dienst wird initialisiert...", LogLevel::Info);
|
||||
//! log("db", "Verbindung unterbrochen!", LogLevel::Warn);
|
||||
//! log("core", "Unerwarteter Fehler", LogLevel::Error);
|
||||
//! ```
|
||||
|
||||
use std::env;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::fs::{File, OpenOptions, create_dir_all};
|
||||
use std::io::Write;
|
||||
use std::sync::{Mutex, OnceLock};
|
||||
|
||||
use crate::config;
|
||||
use crate::program;
|
||||
use time::{OffsetDateTime, macros::format_description};
|
||||
|
||||
/// Schweregrade für Logeinträge in aufsteigender Detailtiefe.
|
||||
///
|
||||
/// Die Reihenfolge bestimmt den Filter: Nur Einträge mit `log_level <= LOG_LEVEL` werden ausgegeben.
|
||||
///
|
||||
/// Anzeige (Display):
|
||||
/// - `Error` -> `ERROR`
|
||||
/// - `Warn` -> `WARN`
|
||||
/// - `Info` -> `INFO`
|
||||
/// - `Debug` -> `DEBUG`
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Copy, Clone)]
|
||||
pub enum LogLevel {
|
||||
/// Kritische Fehler, gehen zusätzlich auf `stderr`.
|
||||
Error = 1,
|
||||
/// Wichtige Warnungen über potenzielle Probleme.
|
||||
Warn = 2,
|
||||
/// Allgemeine Betriebsinformationen.
|
||||
Info = 3,
|
||||
/// Ausführliche Diagnoseausgaben für die Entwicklung.
|
||||
Debug = 4,
|
||||
}
|
||||
|
||||
impl Display for LogLevel {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
LogLevel::Error => write!(f, "ERROR"),
|
||||
LogLevel::Warn => write!(f, "WARN"),
|
||||
LogLevel::Info => write!(f, "INFO"),
|
||||
LogLevel::Debug => write!(f, "DEBUG"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<String> for LogLevel {
|
||||
type Error = LogLevel;
|
||||
|
||||
fn try_from(value: String) -> Result<Self, Self> {
|
||||
match value.to_lowercase().as_str() {
|
||||
"error" => Ok(LogLevel::Error),
|
||||
"warn" => Ok(LogLevel::Warn),
|
||||
"info" => Ok(LogLevel::Info),
|
||||
"debug" => Ok(LogLevel::Debug),
|
||||
_ => Err(LogLevel::Info),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Globaler Schweregradfilter für Ausgabe.
|
||||
static LOG_LEVEL: OnceLock<LogLevel> = OnceLock::new();
|
||||
|
||||
/// Lazy-initialisiertes Handle zur Logdatei; kann `None` sein, falls das Öffnen fehlschlug.
|
||||
static LOG_FILE: OnceLock<Mutex<Option<File>>> = OnceLock::new();
|
||||
|
||||
/// Protokolliert eine Nachricht abhängig vom angegebenen Schweregrad.
|
||||
///
|
||||
/// Verhalten:
|
||||
/// - Wenn `log_level` größer als der globale Filter ist, wird nichts ausgegeben.
|
||||
/// - `Error`-Meldungen gehen nach `stderr`, alle anderen nach `stdout`.
|
||||
/// - Zusätzlich wird in eine tägliche Logdatei im Temp-Verzeichnis geschrieben (wenn erfolgreich geöffnet).
|
||||
///
|
||||
/// Parameter:
|
||||
/// - `tag`: Kurzer Kontext (z. B. Modulname).
|
||||
/// - `message`: Die eigentliche Nachricht (eine Zeile).
|
||||
/// - `log_level`: Schweregrad der Nachricht.
|
||||
///
|
||||
/// Thread-Sicherheit:
|
||||
/// - Dateischreibzugriffe sind über `Mutex` serialisiert.
|
||||
///
|
||||
/// Beispiel:
|
||||
/// ```rust,no_run
|
||||
/// # use crate::log::{log, LogLevel};
|
||||
/// log("http", "Server gestartet auf Port 8080", LogLevel::Info);
|
||||
/// ```
|
||||
pub fn log(tag: &str, message: &str, log_level: LogLevel) {
|
||||
if log_level <= get_log_level() {
|
||||
let message: String = format_message(tag, message, &log_level);
|
||||
|
||||
if log_level == LogLevel::Error {
|
||||
eprintln!("{}", message);
|
||||
} else {
|
||||
println!("{}", message);
|
||||
}
|
||||
|
||||
let file_lock = get_or_init_log_file();
|
||||
if let Ok(mut guard) = file_lock.lock() {
|
||||
if let Some(f) = guard.as_mut() {
|
||||
let _ = writeln!(f, "{}", message);
|
||||
let _ = f.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Liefert das einmalig initialisierte Log-Level für die Filterung.
|
||||
///
|
||||
/// Ermittelt das konfigurierte Log-Level aus der Config-Datei.
|
||||
/// Wenn ungültig oder nicht vorhanden, wird LogLevel::Info als Fallback verwendet.
|
||||
///
|
||||
/// Rückgabe:
|
||||
/// - `LogLevel`: Das zu verwendende Log-Level als enum-Wert.
|
||||
fn get_log_level() -> LogLevel {
|
||||
*LOG_LEVEL.get_or_init(|| {
|
||||
let log_level = &config::get_config().general.log_level;
|
||||
LogLevel::try_from(log_level.to_string()).unwrap_or(LogLevel::Info)
|
||||
})
|
||||
}
|
||||
|
||||
/// Formatiert eine Lognachricht mit Zeitstempel, Level, Tag und Präfix.
|
||||
///
|
||||
/// Format:
|
||||
/// - Datum/Zeit lokal (Fallback: UTC) im Format `DD.MM.YYYY HH:MM:SS.mmm`.
|
||||
/// - Level als Text (`ERROR`, `WARN`, `INFO`, `DEBUG`).
|
||||
/// - Tag in eckigen Klammern; bei leerem Tag entsteht ein leeres `[]`.
|
||||
/// - Präfix pro Level: `[!]` (Error), `[?]` (Warn), `[i]` (Info), `[d]` (Debug).
|
||||
///
|
||||
/// Beispielausgabe:
|
||||
/// - `[i][18.08.2025 14:23:45.012][INFO][init]: Fertig`
|
||||
///
|
||||
/// Hinweis:
|
||||
/// - Diese Funktion formatiert nur; sie führt keinen I/O aus.
|
||||
fn format_message(tag: &str, message: &str, log_level: &LogLevel) -> String {
|
||||
let mut prefix: String = String::new();
|
||||
|
||||
let now_local: OffsetDateTime =
|
||||
OffsetDateTime::now_local().unwrap_or(OffsetDateTime::now_utc());
|
||||
let fmt =
|
||||
format_description!("[day].[month].[year] [hour]:[minute]:[second].[subsecond digits:3]");
|
||||
|
||||
if tag != "" {
|
||||
prefix = format!("[{}]", tag);
|
||||
}
|
||||
|
||||
let message = format!(
|
||||
"[{}][{}]{}: {}",
|
||||
now_local.format(fmt).unwrap(),
|
||||
log_level.to_string(),
|
||||
prefix,
|
||||
message
|
||||
);
|
||||
|
||||
match log_level {
|
||||
&LogLevel::Error => format!("[!]{}", message),
|
||||
&LogLevel::Warn => format!("[?]{}", message),
|
||||
&LogLevel::Info => format!("[i]{}", message),
|
||||
&LogLevel::Debug => format!("[d]{}", message),
|
||||
}
|
||||
}
|
||||
|
||||
/// Initialisiert das Logdatei-Handle beim ersten Aufruf und liefert eine Referenz darauf.
|
||||
///
|
||||
/// Rückgabe:
|
||||
/// - `&'static Mutex<Option<File>>`: Das Mutex schützt den optionalen Dateihandler.
|
||||
/// `None` bedeutet, dass das Öffnen fehlgeschlagen ist (z. B. fehlende Rechte).
|
||||
fn get_or_init_log_file() -> &'static Mutex<Option<File>> {
|
||||
LOG_FILE.get_or_init(|| {
|
||||
let file = open_log_file().ok();
|
||||
Mutex::new(file)
|
||||
})
|
||||
}
|
||||
|
||||
/// Öffnet (und erstellt bei Bedarf) die tagesbasierte Logdatei im Temp-Verzeichnis.
|
||||
///
|
||||
/// Pfadaufbau:
|
||||
/// - Basis: `std::env::temp_dir()`
|
||||
/// - Unterordner: `<programmname>-<konstante-uuid>`
|
||||
/// - Datei: `log-YYYY-MM-DD.log` im Append-Modus
|
||||
///
|
||||
/// Rückgabe:
|
||||
/// - `Ok(File)`, wenn der Ordner erstellt/gefunden und die Datei geöffnet/angelegt werden konnte.
|
||||
/// - `Err(std::io::Error)`, wenn ein I/O-Fehler auftrat.
|
||||
///
|
||||
/// Fehler:
|
||||
/// - Gibt I/O-Fehler unverändert weiter (z. B. beim Erstellen des Ordners oder Öffnen der Datei).
|
||||
fn open_log_file() -> std::io::Result<File> {
|
||||
let program = program::program_name();
|
||||
let rand = "13692bbf-a93b-43e9-9cc6-f05f94a8cfb6";
|
||||
|
||||
let mut dir = env::temp_dir();
|
||||
dir.push(format!("{}-{}", program, rand));
|
||||
create_dir_all(&dir)?;
|
||||
|
||||
let today_fmt = format_description!("[year]-[month]-[day]");
|
||||
let date_str = OffsetDateTime::now_local()
|
||||
.unwrap_or(OffsetDateTime::now_utc())
|
||||
.format(today_fmt)
|
||||
.unwrap_or_else(|_| "0000-00-00".to_string());
|
||||
|
||||
let file_name = format!("log-{}.log", date_str);
|
||||
dir.push(file_name);
|
||||
|
||||
OpenOptions::new().create(true).append(true).open(dir)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_format_message_prefixes() {
|
||||
let msg_info = format_message("test", "Info message", &LogLevel::Info);
|
||||
assert!(msg_info.starts_with("[i]"));
|
||||
assert!(msg_info.contains("[INFO][test]: Info message"));
|
||||
|
||||
let msg_err = format_message("test", "Error message", &LogLevel::Error);
|
||||
assert!(msg_err.starts_with("[!]"));
|
||||
assert!(msg_err.contains("[ERROR][test]: Error message"));
|
||||
|
||||
let msg_warn = format_message("test", "Warn message", &LogLevel::Warn);
|
||||
assert!(msg_warn.starts_with("[?]"));
|
||||
assert!(msg_warn.contains("[WARN][test]: Warn message"));
|
||||
|
||||
let msg_debug = format_message("test", "Debug message", &LogLevel::Debug);
|
||||
assert!(msg_debug.starts_with("[d]"));
|
||||
assert!(msg_debug.contains("[DEBUG][test]: Debug message"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_message_empty_tag() {
|
||||
let msg = format_message("", "No tag message", &LogLevel::Info);
|
||||
assert!(msg.starts_with("[i]"));
|
||||
assert!(msg.contains("[INFO]: No tag message"));
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
mod program;
|
||||
mod sudo;
|
||||
mod log;
|
||||
mod config;
|
||||
mod updater;
|
||||
|
||||
use crate::log::{log, LogLevel};
|
||||
|
||||
fn main() {
|
||||
if !sudo::is_run_as_root() {
|
||||
log("auth", "Root-Rechte erforderlich. Starte mit sudo neu...", LogLevel::Info);
|
||||
sudo::run_as_root();
|
||||
return;
|
||||
}
|
||||
|
||||
log("main", "docker-update gestartet.", LogLevel::Info);
|
||||
updater::run_updates();
|
||||
log("main", "docker-update beendet.", LogLevel::Info);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
use std::env;
|
||||
|
||||
/// Liefert den Programmnamen (Dateistamm der aktuellen ausführbaren Datei).
|
||||
///
|
||||
/// Rückgabe:
|
||||
/// - Dateistamm der aktuellen Executable als `String`.
|
||||
/// - Fallback `"app"`, wenn der Name nicht ermittelt werden kann.
|
||||
pub(crate) fn program_name() -> String {
|
||||
env::current_exe()
|
||||
.ok()
|
||||
.and_then(|p| p.file_stem().map(|s| s.to_string_lossy().to_string()))
|
||||
.filter(|s| !s.is_empty())
|
||||
.unwrap_or_else(|| "app".to_string())
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
use crate::log::{LogLevel, log};
|
||||
use std::env;
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::process::{Command, exit};
|
||||
|
||||
/// Prüft, ob das Programm mit Root-/Administrator-Rechten ausgeführt wird.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `true` - Das Programm läuft mit erhöhten Rechten
|
||||
/// * `false` - Das Programm läuft mit normalen Benutzerrechten
|
||||
pub fn is_run_as_root() -> bool {
|
||||
unsafe { libc::geteuid() == 0 }
|
||||
}
|
||||
|
||||
/// Startet das Programm mit Root-Rechten über `sudo` neu.
|
||||
///
|
||||
/// Diese Funktion versucht das Programm mit erhöhten Rechten neu zu starten.
|
||||
pub fn run_as_root() {
|
||||
let commandline_args: Vec<String> = env::args().collect();
|
||||
let err = Command::new("sudo").args(&commandline_args).exec();
|
||||
log(
|
||||
"auth",
|
||||
&format!("Fehler beim Ausführen von 'sudo': {}", err),
|
||||
LogLevel::Error,
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
+485
@@ -0,0 +1,485 @@
|
||||
use crate::config;
|
||||
use crate::log::{LogLevel, log};
|
||||
use serde::Deserialize;
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Output};
|
||||
|
||||
const COMPOSE_FILENAMES: &[&str] = &[
|
||||
"docker-compose.yaml",
|
||||
"docker-compose.yml",
|
||||
"compose.yaml",
|
||||
"compose.yml",
|
||||
];
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct ComposeFile {
|
||||
#[serde(default)]
|
||||
services: HashMap<String, ServiceConfig>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct ServiceConfig {
|
||||
#[serde(default)]
|
||||
image: Option<String>,
|
||||
}
|
||||
|
||||
/// Prüft, ob ein Image-Tag auf `:latest` zeigt (oder implizit `:latest` ist, weil kein Tag angegeben wurde).
|
||||
pub fn is_latest_image(image: &str) -> bool {
|
||||
let image = image.trim();
|
||||
if image.is_empty() {
|
||||
return false;
|
||||
}
|
||||
// Wenn das Image an einen Digest gepinnt ist (z. B. image@sha256:...), ist es kein dynamisches latest-Tag.
|
||||
if image.contains('@') {
|
||||
return false;
|
||||
}
|
||||
// Den Tag-Teil nach dem letzten Schrägstrich ermitteln (um Host:Port/Repo nicht fälschlich als Tag zu werten)
|
||||
let repo_and_tag = image.rsplit('/').next().unwrap_or(image);
|
||||
if let Some((_, tag)) = repo_and_tag.split_once(':') {
|
||||
tag.eq_ignore_ascii_case("latest")
|
||||
} else {
|
||||
// Kein Tag angegeben bedeutet bei Docker implizit `:latest`
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/// Sucht in einem Verzeichnis nach einer gültigen Docker-Compose-Datei.
|
||||
pub fn find_compose_file(dir: &Path) -> Option<PathBuf> {
|
||||
for filename in COMPOSE_FILENAMES {
|
||||
let path = dir.join(filename);
|
||||
if path.is_file() {
|
||||
return Some(path);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Liest eine Compose-Datei ein und liefert eine Liste von (Service-Name, Image-Name).
|
||||
pub fn parse_compose_services(compose_path: &Path) -> Result<Vec<(String, String)>, String> {
|
||||
let content = fs::read_to_string(compose_path).map_err(|e| {
|
||||
format!(
|
||||
"Fehler beim Lesen der Datei '{}': {}",
|
||||
compose_path.display(),
|
||||
e
|
||||
)
|
||||
})?;
|
||||
|
||||
let compose: ComposeFile = serde_yaml::from_str(&content).map_err(|e| {
|
||||
format!(
|
||||
"Fehler beim Parsen der YAML-Datei '{}': {}",
|
||||
compose_path.display(),
|
||||
e
|
||||
)
|
||||
})?;
|
||||
|
||||
let mut services = Vec::new();
|
||||
for (service_name, config) in compose.services {
|
||||
if let Some(image) = config.image {
|
||||
let image = image.trim().to_string();
|
||||
if !image.is_empty() {
|
||||
services.push((service_name, image));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(services)
|
||||
}
|
||||
|
||||
/// Führt einen Docker-Befehl aus und liefert die Ausgabe.
|
||||
fn run_docker_command(args: &[&str]) -> std::io::Result<Output> {
|
||||
Command::new("docker").args(args).output()
|
||||
}
|
||||
|
||||
/// Führt einen Docker-Compose-Befehl im angegebenen Verzeichnis aus.
|
||||
/// Versucht zuerst `docker compose` und fällt bei Nichtverfügbarkeit auf `docker-compose` zurück.
|
||||
pub fn run_compose_command(dir: &Path, args: &[&str]) -> std::io::Result<Output> {
|
||||
let mut compose_args = vec!["compose"];
|
||||
compose_args.extend_from_slice(args);
|
||||
|
||||
let output = Command::new("docker")
|
||||
.current_dir(dir)
|
||||
.args(&compose_args)
|
||||
.output();
|
||||
|
||||
match output {
|
||||
Ok(out) => {
|
||||
let stderr = String::from_utf8_lossy(&out.stderr);
|
||||
let is_unavailable = !out.status.success()
|
||||
&& (stderr.contains("is not a docker command")
|
||||
|| stderr.contains("unknown command \"compose\"")
|
||||
|| stderr.contains("unknown command: compose"));
|
||||
|
||||
if is_unavailable {
|
||||
if let Ok(fallback_out) = Command::new("docker-compose")
|
||||
.current_dir(dir)
|
||||
.args(args)
|
||||
.output()
|
||||
{
|
||||
return Ok(fallback_out);
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
|
||||
// docker-Binary nicht gefunden, versuche docker-compose
|
||||
Command::new("docker-compose")
|
||||
.current_dir(dir)
|
||||
.args(args)
|
||||
.output()
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
/// Ermittelt die lokale Image-ID für ein gegebenes Docker-Image.
|
||||
pub fn get_local_image_id(image: &str) -> Option<String> {
|
||||
let output = run_docker_command(&["image", "inspect", "--format", "{{.Id}}", image]).ok()?;
|
||||
if output.status.success() {
|
||||
let id = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
||||
if !id.is_empty() {
|
||||
return Some(id);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Zieht ein Docker-Image herunter und gibt zurück, ob ein neueres Image heruntergeladen wurde.
|
||||
pub fn pull_image(image: &str) -> Result<bool, String> {
|
||||
let old_id = get_local_image_id(image);
|
||||
|
||||
let output = run_docker_command(&["pull", image])
|
||||
.map_err(|e| format!("Fehler beim Ausführen von 'docker pull {}': {}", image, e))?;
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
|
||||
return Err(format!(
|
||||
"'docker pull {}' fehlgeschlagen: {}",
|
||||
image, stderr
|
||||
));
|
||||
}
|
||||
|
||||
let stdout_str = String::from_utf8_lossy(&output.stdout);
|
||||
let new_id = get_local_image_id(image);
|
||||
|
||||
let updated = match (&old_id, &new_id) {
|
||||
(Some(old), Some(new)) => old != new,
|
||||
(None, Some(_)) => true,
|
||||
_ => stdout_str.contains("Downloaded newer image") || stdout_str.contains("Pull complete"),
|
||||
};
|
||||
|
||||
Ok(updated)
|
||||
}
|
||||
|
||||
/// Aktualisiert und startet die Docker-Compose-Services im angegebenen Verzeichnis neu.
|
||||
pub fn restart_compose_service(dir: &Path, service_name: Option<&str>) -> Result<(), String> {
|
||||
let mut args = vec!["up", "-d"];
|
||||
if let Some(service) = service_name {
|
||||
args.push(service);
|
||||
}
|
||||
|
||||
let output = run_compose_command(dir, &args)
|
||||
.map_err(|e| format!("Fehler beim Ausführen von 'docker compose up -d': {}", e))?;
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
|
||||
return Err(format!("Neustart fehlgeschlagen: {}", stderr));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Bereinigt ungenutzte Zwischen-Images via `docker image prune -f`.
|
||||
pub fn prune_images() -> Result<(), String> {
|
||||
let output = run_docker_command(&["image", "prune", "-f"])
|
||||
.map_err(|e| format!("Fehler beim Ausführen von 'docker image prune -f': {}", e))?;
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
|
||||
return Err(format!(
|
||||
"'docker image prune -f' fehlgeschlagen: {}",
|
||||
stderr
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Prüft alle Unterverzeichnisse im konfigurierten Apps-Verzeichnis auf Aktualisierungen.
|
||||
pub fn run_updates() {
|
||||
let config = config::get_config();
|
||||
let apps_dir_path = Path::new(&config.general.apps_dir);
|
||||
|
||||
log(
|
||||
"scanner",
|
||||
&format!(
|
||||
"Überprüfe Anwendungsverzeichnis: {}",
|
||||
apps_dir_path.display()
|
||||
),
|
||||
LogLevel::Info,
|
||||
);
|
||||
|
||||
if !apps_dir_path.exists() {
|
||||
log(
|
||||
"scanner",
|
||||
&format!("Verzeichnis '{}' existiert nicht.", apps_dir_path.display()),
|
||||
LogLevel::Warn,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let entries = match fs::read_dir(apps_dir_path) {
|
||||
Ok(e) => e,
|
||||
Err(e) => {
|
||||
log(
|
||||
"scanner",
|
||||
&format!("Fehler beim Lesen von '{}': {}", apps_dir_path.display(), e),
|
||||
LogLevel::Error,
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let mut app_dirs: Vec<PathBuf> = entries
|
||||
.filter_map(|res| res.ok().map(|e| e.path()))
|
||||
.filter(|p| p.is_dir())
|
||||
.collect();
|
||||
|
||||
app_dirs.sort();
|
||||
|
||||
if app_dirs.is_empty() {
|
||||
log(
|
||||
"scanner",
|
||||
&format!(
|
||||
"Keine Unterverzeichnisse in '{}' gefunden.",
|
||||
apps_dir_path.display()
|
||||
),
|
||||
LogLevel::Info,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
for app_dir in app_dirs {
|
||||
let app_name = app_dir.file_name().unwrap_or_default().to_string_lossy();
|
||||
log(
|
||||
"scanner",
|
||||
&format!("Untersuche Anwendung '{}'...", app_name),
|
||||
LogLevel::Info,
|
||||
);
|
||||
|
||||
let compose_file = match find_compose_file(&app_dir) {
|
||||
Some(f) => f,
|
||||
None => {
|
||||
log(
|
||||
"scanner",
|
||||
&format!(
|
||||
"Keine Docker-Compose-Datei in '{}' gefunden. Überspringe.",
|
||||
app_dir.display()
|
||||
),
|
||||
LogLevel::Debug,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
log(
|
||||
"compose",
|
||||
&format!("Gefundene Compose-Datei: {}", compose_file.display()),
|
||||
LogLevel::Debug,
|
||||
);
|
||||
|
||||
let services = match parse_compose_services(&compose_file) {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
log(
|
||||
"compose",
|
||||
&format!(
|
||||
"Fehler beim Analysieren von '{}': {}",
|
||||
compose_file.display(),
|
||||
e
|
||||
),
|
||||
LogLevel::Warn,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let mut updated_any = false;
|
||||
|
||||
for (service_name, image) in services {
|
||||
if !is_latest_image(&image) {
|
||||
log(
|
||||
"updater",
|
||||
&format!(
|
||||
"Service '{}' verwendet kein :latest-Image ('{}'). Überspringe.",
|
||||
service_name, image
|
||||
),
|
||||
LogLevel::Debug,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
log(
|
||||
"updater",
|
||||
&format!(
|
||||
"Prüfe auf neues Image für Service '{}' ('{}')...",
|
||||
service_name, image
|
||||
),
|
||||
LogLevel::Info,
|
||||
);
|
||||
|
||||
match pull_image(&image) {
|
||||
Ok(true) => {
|
||||
log(
|
||||
"updater",
|
||||
&format!(
|
||||
"Neueres Image für Service '{}' ('{}') gefunden und heruntergeladen.",
|
||||
service_name, image
|
||||
),
|
||||
LogLevel::Info,
|
||||
);
|
||||
updated_any = true;
|
||||
}
|
||||
Ok(false) => {
|
||||
log(
|
||||
"updater",
|
||||
&format!(
|
||||
"Image für Service '{}' ('{}') ist bereits aktuell.",
|
||||
service_name, image
|
||||
),
|
||||
LogLevel::Info,
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
log(
|
||||
"updater",
|
||||
&format!("Fehler beim Aktualisieren von Image '{}': {}", image, e),
|
||||
LogLevel::Error,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if updated_any {
|
||||
log(
|
||||
"updater",
|
||||
&format!(
|
||||
"Starte Anwendung '{}' neu mit aktualisierten Images...",
|
||||
app_name
|
||||
),
|
||||
LogLevel::Info,
|
||||
);
|
||||
match restart_compose_service(&app_dir, None) {
|
||||
Ok(_) => {
|
||||
log(
|
||||
"updater",
|
||||
&format!(
|
||||
"Anwendung '{}' erfolgreich aktualisiert und neu gestartet.",
|
||||
app_name
|
||||
),
|
||||
LogLevel::Info,
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
log(
|
||||
"updater",
|
||||
&format!("Fehler beim Neustarten der Anwendung '{}': {}", app_name, e),
|
||||
LogLevel::Error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
log(
|
||||
"updater",
|
||||
"Bereinige ungenutzte Docker-Images...",
|
||||
LogLevel::Info,
|
||||
);
|
||||
if let Err(e) = prune_images() {
|
||||
log(
|
||||
"updater",
|
||||
&format!("Fehler beim Bereinigen ungenutzter Docker-Images: {}", e),
|
||||
LogLevel::Warn,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log(
|
||||
"scanner",
|
||||
"Aktualisierungsvorgang abgeschlossen.",
|
||||
LogLevel::Info,
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
#[test]
|
||||
fn test_is_latest_image() {
|
||||
assert!(is_latest_image("nginx"));
|
||||
assert!(is_latest_image("nginx:latest"));
|
||||
assert!(is_latest_image("nginx:LATEST"));
|
||||
assert!(is_latest_image("gitea/gitea"));
|
||||
assert!(is_latest_image("gitea/gitea:latest"));
|
||||
assert!(is_latest_image("localhost:5000/my-app"));
|
||||
assert!(is_latest_image("localhost:5000/my-app:latest"));
|
||||
|
||||
assert!(!is_latest_image("nginx:alpine"));
|
||||
assert!(!is_latest_image("gitea/gitea:1.20"));
|
||||
assert!(!is_latest_image("postgres:15-alpine"));
|
||||
assert!(!is_latest_image("localhost:5000/my-app:v1.0"));
|
||||
assert!(!is_latest_image("nginx@sha256:1234567890abcdef"));
|
||||
assert!(!is_latest_image(""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_compose_services() {
|
||||
let temp_dir = std::env::temp_dir().join("docker_update_test_compose");
|
||||
let _ = fs::create_dir_all(&temp_dir);
|
||||
let compose_path = temp_dir.join("docker-compose.yaml");
|
||||
|
||||
let yaml_content = r#"
|
||||
services:
|
||||
gitea:
|
||||
image: gitea/gitea:latest
|
||||
ports:
|
||||
- "3000:3000"
|
||||
db:
|
||||
image: postgres:15
|
||||
environment:
|
||||
POSTGRES_DB: gitea
|
||||
"#;
|
||||
let mut file = File::create(&compose_path).unwrap();
|
||||
file.write_all(yaml_content.as_bytes()).unwrap();
|
||||
|
||||
let services = parse_compose_services(&compose_path).unwrap();
|
||||
assert_eq!(services.len(), 2);
|
||||
|
||||
let gitea_svc = services.iter().find(|(s, _)| s == "gitea").unwrap();
|
||||
assert_eq!(gitea_svc.1, "gitea/gitea:latest");
|
||||
|
||||
let db_svc = services.iter().find(|(s, _)| s == "db").unwrap();
|
||||
assert_eq!(db_svc.1, "postgres:15");
|
||||
|
||||
let _ = fs::remove_dir_all(&temp_dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_compose_file() {
|
||||
let temp_dir = std::env::temp_dir().join("docker_update_test_find");
|
||||
let _ = fs::create_dir_all(&temp_dir);
|
||||
|
||||
assert_eq!(find_compose_file(&temp_dir), None);
|
||||
|
||||
let compose_path = temp_dir.join("docker-compose.yaml");
|
||||
File::create(&compose_path).unwrap();
|
||||
|
||||
assert_eq!(find_compose_file(&temp_dir), Some(compose_path));
|
||||
|
||||
let _ = fs::remove_dir_all(&temp_dir);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user