19 Commits
v0.0.2 ... main

Author SHA1 Message Date
e6ef6e11d6 chore(release): update package version to 0.0.9
All checks were successful
Release / test (push) Successful in -33m2s
Release / release (push) Successful in -32m47s
Release / pkg-aur (push) Successful in -33m46s
Release / pkg-deb (push) Successful in -33m19s
Release / pkg-rpm (push) Successful in -32m33s
2026-04-12 11:08:47 +02:00
f9dcb0b561 Merge branch 'main' of git.warky.dev:wdevs/unitdore 2026-04-12 11:08:38 +02:00
69069a2196 fix(podman): handle invalid JSON output gracefully 2026-04-12 11:08:20 +02:00
Hein
2efccc5d4f chore(release): update package version to 0.0.8
Some checks failed
Release / test (push) Successful in -30m10s
Release / release (push) Successful in -30m3s
Release / pkg-aur (push) Successful in -29m57s
Release / pkg-rpm (push) Failing after 14m44s
Release / pkg-deb (push) Failing after 14m51s
2026-04-10 09:38:59 +02:00
Hein
b58373ad2f feat(config): add restart options for unit configuration
* include Restart, RestartSec, and RestartRetries fields
* update service file generation to support restart settings
* add tests for restart behavior in unit generation
2026-04-10 09:38:45 +02:00
a273232303 chore(release): update package version to 0.0.7
All checks were successful
Release / release (push) Successful in -30m29s
Release / pkg-aur (push) Successful in -30m19s
Release / test (push) Successful in -30m43s
Release / pkg-deb (push) Successful in -30m29s
Release / pkg-rpm (push) Successful in -29m17s
2026-04-08 19:59:11 +02:00
fae49a258c ci(release): improve RPM upload logic in release workflow 2026-04-08 19:59:00 +02:00
00bc6ed893 chore(release): update package version to 0.0.6
Some checks failed
Release / test (push) Successful in -30m39s
Release / release (push) Successful in -30m31s
Release / pkg-deb (push) Successful in -30m33s
Release / pkg-aur (push) Successful in -29m41s
Release / pkg-rpm (push) Failing after -29m26s
2026-04-08 19:48:22 +02:00
b44546dc24 docs(README): update installation instructions for various distributions 2026-04-08 19:48:07 +02:00
Hein
c6198ea6b7 chore(release): update package version to 0.0.4 and fix build paths
Some checks failed
Release / pkg-deb (push) Successful in -30m35s
Release / pkg-aur (push) Successful in -30m17s
Release / pkg-rpm (push) Failing after -29m39s
Release / test (push) Successful in -30m39s
Release / release (push) Successful in -30m33s
* Adjust pkgver in PKGBUILD to 0.0.4
* Update build paths in PKGBUILD for consistency
* Enhance AUR package versioning logic in release workflow
2026-04-08 17:50:15 +02:00
Hein
9ef31866f1 chore(release): update curl installation in Rocky 9 image 2026-04-08 17:35:12 +02:00
Hein
77b86dc3fc chore(aur): improve AUR SSH key handling logic
Some checks failed
Release / test (push) Successful in -30m41s
Release / pkg-deb (push) Successful in -30m32s
Release / release (push) Successful in -30m33s
Release / pkg-rpm (push) Failing after -30m32s
Release / pkg-aur (push) Successful in -30m34s
2026-04-08 17:19:13 +02:00
Hein
0999303cd3 chore(aur): enhance AUR SSH setup for key handling
* Improve SSH key handling with support for raw, escaped, and base64-encoded keys
* Add validation for AUR_SSH_KEY to ensure it's a valid private key
* Update SSH command options for better security and reliability
2026-04-08 17:02:10 +02:00
Hein
384c4592d1 chore(release): remove key content diagnostics from AUR SSH setup 2026-04-08 16:39:06 +02:00
Hein
815bdfed80 chore(release): enhance AUR SSH setup for key handling
* Improve SSH key setup by auto-detecting key format
* Add diagnostics for key validation and size
2026-04-08 15:41:35 +02:00
Hein
243da39fe3 chore(release): update AUR SSH setup to use base64 decoding 2026-04-08 15:29:21 +02:00
Hein
0a1e768dfe chore(release): remove Arch package build steps from workflow 2026-04-08 15:23:10 +02:00
Hein
e66f869752 chore(release): update source archive format and URLs
Some checks failed
Release / test (push) Successful in -30m28s
Release / release (push) Successful in -29m36s
Release / pkg-aur (push) Failing after -31m0s
Release / pkg-arch (push) Failing after -30m36s
Release / pkg-deb (push) Successful in -30m6s
Release / pkg-rpm (push) Failing after -30m27s
* Change source archive from tar.gz to zip for Arch packaging
* Update URLs in PKGBUILD and spec files to point to the correct repository
2026-04-08 15:09:33 +02:00
Hein
2c0f51422e chore(release): update Go version and build requirements
* Change Go version to 1.23.0 in go.mod
* Update golang build requirement to >= 1.23 in unitdore.spec
* Adjust packaging commands for Arch and RPM
2026-04-08 14:51:57 +02:00
17 changed files with 329 additions and 130 deletions

View File

@@ -48,7 +48,7 @@ jobs:
[ "$GOOS" = "windows" ] && EXT=".exe" [ "$GOOS" = "windows" ] && EXT=".exe"
NAME="unitdore-${GOOS}-${GOARCH}${EXT}" NAME="unitdore-${GOOS}-${GOARCH}${EXT}"
GOOS="$GOOS" GOARCH="$GOARCH" go build \ GOOS="$GOOS" GOARCH="$GOARCH" go build \
-ldflags "-X main.version=${VERSION}" \ -ldflags "-X github.com/warkanum/unitdore/cmd.version=${VERSION}" \
-o "$NAME" . -o "$NAME" .
echo "Built $NAME" echo "Built $NAME"
done done
@@ -92,61 +92,108 @@ jobs:
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pkg-arch: pkg-aur:
needs: release needs: release
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build Arch package - name: Publish to AUR
env:
AUR_SSH_KEY: ${{ secrets.AUR_SSH_KEY }}
run: | run: |
set -euo pipefail
VERSION="${{ github.event.inputs.tag || github.ref_name }}" VERSION="${{ github.event.inputs.tag || github.ref_name }}"
PKGVER="${VERSION#v}" PKGVER="${VERSION#v}"
AUR_KEY_PATH="$HOME/.ssh/aur"
AUR_KNOWN_HOSTS="$HOME/.ssh/known_hosts"
# Source tarball — prefix=unitdore/ matches `cd "$pkgname"` in PKGBUILD # Setup SSH for AUR
git archive --format=tar.gz --prefix=unitdore/ HEAD \ mkdir -p ~/.ssh
> pkg/arch/unitdore-${PKGVER}.tar.gz chmod 700 ~/.ssh
SHA=$(sha256sum pkg/arch/unitdore-${PKGVER}.tar.gz | cut -d' ' -f1)
# Patch PKGBUILD for local build if [ -z "${AUR_SSH_KEY:-}" ]; then
sed -i \ echo "AUR_SSH_KEY is empty"
-e "s/^pkgver=.*/pkgver=${PKGVER}/" \ exit 1
-e "s/^sha256sums=.*/sha256sums=('${SHA}')/" \ fi
-e "s|source=.*|source=(\"unitdore-\${pkgver}.tar.gz\")|" \
pkg/arch/PKGBUILD
mkdir -p pkg/arch/out # Support raw multiline keys, escaped \\n secrets, or base64-encoded keys.
docker run --rm \ CLEAN_AUR_SSH_KEY="$(printf '%s' "$AUR_SSH_KEY" | tr -d '\r')"
-v "$PWD/pkg/arch:/build" \ if printf '%s' "$CLEAN_AUR_SSH_KEY" | grep -q "^-----BEGIN .*PRIVATE KEY-----$"; then
-v "$PWD/pkg/arch/out:/out" \ printf '%s\n' "$CLEAN_AUR_SSH_KEY" > "$AUR_KEY_PATH"
-w /build \ elif printf '%s' "$CLEAN_AUR_SSH_KEY" | grep -q '\\n'; then
archlinux:latest \ printf '%b\n' "$CLEAN_AUR_SSH_KEY" > "$AUR_KEY_PATH"
bash -c " else
pacman -Syu --noconfirm base-devel go && if printf '%s' "$CLEAN_AUR_SSH_KEY" | tr -d '[:space:]' | base64 --decode > "$AUR_KEY_PATH" 2>/dev/null; then
useradd -m builder && :
chown -R builder:builder /build && else
runuser -u builder -- makepkg --noconfirm --noprogressbar && printf '%s\n' "$CLEAN_AUR_SSH_KEY" > "$AUR_KEY_PATH"
cp /build/*.pkg.tar.zst /out/ fi
" fi
chmod 600 "$AUR_KEY_PATH"
- name: Upload to release if ! ssh-keygen -y -f "$AUR_KEY_PATH" >/dev/null 2>&1; then
run: | echo "AUR_SSH_KEY is not a valid private key."
TAG="${{ github.event.inputs.tag || github.ref_name }}" echo "Store it as a raw private key, an escaped private key with \\n, or a base64-encoded private key."
RELEASE=$(curl -s "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}" \ exit 1
-H "Authorization: token ${GITHUB_TOKEN}") fi
UPLOAD_URL=$(echo "$RELEASE" | grep -o '"upload_url":"[^"]*"' | cut -d'"' -f4)
for f in pkg/arch/out/*.pkg.tar.zst; do ssh-keyscan -t rsa,ed25519 aur.archlinux.org >> "$AUR_KNOWN_HOSTS"
FNAME=$(basename "$f") chmod 644 "$AUR_KNOWN_HOSTS"
echo "Uploading $FNAME..."
curl -s -X POST "${UPLOAD_URL}?name=${FNAME}" \ # Clone AUR repo
-H "Authorization: token ${GITHUB_TOKEN}" \ GIT_SSH_COMMAND="ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$AUR_KNOWN_HOSTS -i $AUR_KEY_PATH" \
-H "Content-Type: application/octet-stream" \ git clone ssh://aur@aur.archlinux.org/unitdore.git aur-repo
--data-binary "@${f}" > /dev/null
done CURRENT_PKGVER=$(awk -F= '/^pkgver=/ {print $2; exit}' aur-repo/PKGBUILD | tr -d "[:space:]")
env: CURRENT_PKGREL=$(awk -F= '/^pkgrel=/ {print $2; exit}' aur-repo/PKGBUILD | tr -d "[:space:]")
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if [ "$CURRENT_PKGVER" = "$PKGVER" ]; then
case "$CURRENT_PKGREL" in
''|*[!0-9]*)
echo "Unsupported pkgrel in AUR repo: ${CURRENT_PKGREL}"
exit 1
;;
*)
PKGREL=$((CURRENT_PKGREL + 1))
;;
esac
else
PKGREL=1
fi
echo "Publishing AUR package version ${PKGVER}-${PKGREL}"
# Compute SHA256 of the source archive from the same URL the PKGBUILD will download.
SHA=$(curl -fsSL "https://git.warky.dev/wdevs/unitdore/archive/v${PKGVER}.zip" | sha256sum | cut -d' ' -f1)
# Update PKGBUILD — keep remote source URL, bump version/checksum, and increment pkgrel for same-version rebuilds.
sed -e "s/^pkgver=.*/pkgver=${PKGVER}/" \
-e "s/^pkgrel=.*/pkgrel=${PKGREL}/" \
-e "s/^sha256sums=.*/sha256sums=('${SHA}')/" \
pkg/arch/PKGBUILD > aur-repo/PKGBUILD
# Generate .SRCINFO inside an Arch container (docker cp avoids DinD volume mount issues)
CID=$(docker run -d archlinux:latest sleep infinity)
docker cp aur-repo/PKGBUILD $CID:/build/PKGBUILD || (docker exec $CID mkdir -p /build && docker cp aur-repo/PKGBUILD $CID:/build/PKGBUILD)
docker exec $CID bash -c "
pacman -Sy --noconfirm base-devel &&
useradd -m builder &&
chown -R builder:builder /build &&
runuser -u builder -- bash -c 'cd /build && makepkg --printsrcinfo > .SRCINFO'
"
docker cp $CID:/build/.SRCINFO aur-repo/.SRCINFO
docker rm -f $CID
# Commit and push to AUR master
cd aur-repo
git config user.email "hein@warky.dev"
git config user.name "Hein"
git add PKGBUILD .SRCINFO
git commit -m "Update to v${PKGVER}-${PKGREL}"
GIT_SSH_COMMAND="ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$AUR_KNOWN_HOSTS -i $AUR_KEY_PATH" \
git push origin HEAD:master
pkg-deb: pkg-deb:
needs: release needs: release
@@ -168,7 +215,7 @@ jobs:
for GOARCH in amd64 arm64; do for GOARCH in amd64 arm64; do
GOOS=linux GOARCH=$GOARCH go build \ GOOS=linux GOARCH=$GOARCH go build \
-trimpath \ -trimpath \
-ldflags "-X main.version=${PKGVER}" \ -ldflags "-X github.com/warkanum/unitdore/cmd.version=${PKGVER}" \
-o unitdore . -o unitdore .
PKGDIR="unitdore_${PKGVER}_${GOARCH}" PKGDIR="unitdore_${PKGVER}_${GOARCH}"
@@ -215,8 +262,16 @@ jobs:
- name: Build RPM - name: Build RPM
run: | run: |
set -euo pipefail
VERSION="${{ github.event.inputs.tag || github.ref_name }}" VERSION="${{ github.event.inputs.tag || github.ref_name }}"
PKGVER="${VERSION#v}" PKGVER="${VERSION#v}"
GO_VER="$(awk '/^go / { print $2; exit }' go.mod)"
if [ -z "${GO_VER}" ]; then
echo "Failed to determine Go version from go.mod"
exit 1
fi
# Source tarball — prefix=unitdore-VERSION/ matches RPM %autosetup convention # Source tarball — prefix=unitdore-VERSION/ matches RPM %autosetup convention
git archive --format=tar.gz --prefix=unitdore-${PKGVER}/ HEAD \ git archive --format=tar.gz --prefix=unitdore-${PKGVER}/ HEAD \
@@ -226,19 +281,37 @@ jobs:
sed -i "s/^Version:.*/Version: ${PKGVER}/" pkg/centos/unitdore.spec sed -i "s/^Version:.*/Version: ${PKGVER}/" pkg/centos/unitdore.spec
mkdir -p pkg/centos/out mkdir -p pkg/centos/out
docker run --rm \ CID=$(docker create \
-v "$PWD:/workspace" \ -e GO_VER="${GO_VER}" \
-v "$PWD/pkg/centos/out:/out" \ -e PKGVER="${PKGVER}" \
-w /workspace \ -w /build \
rockylinux:9 \ rockylinux:9 \
bash -c " bash -lc "
dnf install -y rpm-build golang git && set -euo pipefail
# Rocky 9 images already ship curl-minimal, which is enough for the Go tarball download.
dnf install -y rpm-build git &&
curl -fsSL https://go.dev/dl/go\${GO_VER}.linux-amd64.tar.gz | tar -C /usr/local -xz &&
export PATH=\$PATH:/usr/local/go/bin &&
mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} && mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} &&
cp unitdore-${PKGVER}.tar.gz ~/rpmbuild/SOURCES/ && cp unitdore-${PKGVER}.tar.gz ~/rpmbuild/SOURCES/ &&
cp pkg/centos/unitdore.spec ~/rpmbuild/SPECS/ && cp pkg/centos/unitdore.spec ~/rpmbuild/SPECS/ &&
rpmbuild -ba ~/rpmbuild/SPECS/unitdore.spec && rpmbuild --nodeps -ba ~/rpmbuild/SPECS/unitdore.spec
find ~/rpmbuild/RPMS -name '*.rpm' -exec cp {} /out/ \; ")
"
cleanup() {
docker rm -f "$CID" >/dev/null 2>&1 || true
}
trap cleanup EXIT
# Avoid bind mounts here because DinD runners may not expose the checkout path to the Docker daemon.
docker cp unitdore-${PKGVER}.tar.gz "$CID:/build/unitdore-${PKGVER}.tar.gz"
docker cp pkg "$CID:/build/pkg"
docker start -a "$CID"
docker cp "$CID:/root/rpmbuild/RPMS/." pkg/centos/out/
trap - EXIT
cleanup
- name: Upload to release - name: Upload to release
run: | run: |
@@ -246,13 +319,13 @@ jobs:
RELEASE=$(curl -s "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}" \ RELEASE=$(curl -s "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}" \
-H "Authorization: token ${GITHUB_TOKEN}") -H "Authorization: token ${GITHUB_TOKEN}")
UPLOAD_URL=$(echo "$RELEASE" | grep -o '"upload_url":"[^"]*"' | cut -d'"' -f4) UPLOAD_URL=$(echo "$RELEASE" | grep -o '"upload_url":"[^"]*"' | cut -d'"' -f4)
for f in pkg/centos/out/*.rpm; do while IFS= read -r f; do
FNAME=$(basename "$f") FNAME=$(basename "$f")
echo "Uploading $FNAME..." echo "Uploading $FNAME..."
curl -s -X POST "${UPLOAD_URL}?name=${FNAME}" \ curl -s -X POST "${UPLOAD_URL}?name=${FNAME}" \
-H "Authorization: token ${GITHUB_TOKEN}" \ -H "Authorization: token ${GITHUB_TOKEN}" \
-H "Content-Type: application/octet-stream" \ -H "Content-Type: application/octet-stream" \
--data-binary "@${f}" > /dev/null --data-binary "@${f}" > /dev/null
done done < <(find pkg/centos/out -name "*.rpm")
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
unitdore unitdore
*.exe *.exe
.codex

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 Hein (Warky Devs)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,8 +1,8 @@
BINARY := unitdore BINARY := unitdore
INSTALL_DIR := /usr/local/bin INSTALL_DIR := /usr/bin
CONFIG_DIR := /etc/unitdore CONFIG_DIR := /etc/unitdore
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
LDFLAGS := -ldflags "-X main.version=$(VERSION)" LDFLAGS := -ldflags "-X github.com/warkanum/unitdore/cmd.version=$(VERSION)"
.PHONY: all build install uninstall test lint clean release-version .PHONY: all build install uninstall test lint clean release-version
@@ -42,17 +42,23 @@ lint:
clean: clean:
rm -f $(BINARY) rm -f $(BINARY)
## release-version: bump patch version, tag, and push to trigger release workflow ## release-version: bump patch version, update source versions, commit, tag, and push
release-version: release-version:
@CURRENT=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \ @CURRENT=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \
MAJOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/'); \ MAJOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/'); \
MINOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/'); \ MINOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/'); \
PATCH=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/'); \ PATCH=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/'); \
NEXT="v$$MAJOR.$$MINOR.$$((PATCH + 1))"; \ NEXT="v$$MAJOR.$$MINOR.$$((PATCH + 1))"; \
PKGVER="$$MAJOR.$$MINOR.$$((PATCH + 1))"; \
echo "Current: $$CURRENT → Next: $$NEXT"; \ echo "Current: $$CURRENT → Next: $$NEXT"; \
sed -i "s/^var version = .*/var version = \"$$PKGVER\"/" cmd/root.go; \
sed -i "s/^pkgver=.*/pkgver=$$PKGVER/" pkg/arch/PKGBUILD; \
sed -i "s/^Version:.*/Version: $$PKGVER/" pkg/centos/unitdore.spec; \
git add cmd/root.go pkg/arch/PKGBUILD pkg/centos/unitdore.spec; \
git commit -m "chore(release): update package version to $$PKGVER"; \
git tag -a "$$NEXT" -m "Release $$NEXT"; \ git tag -a "$$NEXT" -m "Release $$NEXT"; \
git push origin "$$NEXT"; \ git push origin HEAD "$$NEXT"; \
echo "Pushed tag $$NEXT — release workflow triggered" echo "Pushed $$NEXT — release workflow triggered"
## help: show this help ## help: show this help
help: help:

View File

@@ -6,6 +6,32 @@ Unitdore bridges your container runtime (Podman, Docker) and systemd. It discove
## Install ## Install
**Arch Linux (AUR)**
```bash
yay -S unitdore
```
**Debian / Ubuntu**
Download the `.deb` from the [releases page](https://git.warky.dev/wdevs/unitdore/releases) and install:
```bash
sudo dpkg -i unitdore_*.deb
```
**CentOS / AlmaLinux / Rocky Linux**
Download the `.rpm` from the [releases page](https://git.warky.dev/wdevs/unitdore/releases) and install:
```bash
sudo rpm -i unitdore-*.rpm
# or with dnf:
sudo dnf install unitdore-*.rpm
```
**From source**
```bash ```bash
make build make build
sudo make install sudo make install

View File

@@ -31,7 +31,7 @@ func runInstall(cmd *cobra.Command, args []string) error {
return err return err
} }
prefix, suffix, serviceUser := cfg.Prefix, cfg.Suffix, cfg.EffectiveServiceUser() prefix, suffix := cfg.Prefix, cfg.Suffix
installed := 0 installed := 0
skipped := 0 skipped := 0
removed := 0 removed := 0
@@ -57,7 +57,7 @@ func runInstall(cmd *cobra.Command, args []string) error {
} }
if dryRun { if dryRun {
content, err := systemd.Generate(u, prefix, suffix, serviceUser) content, err := systemd.Generate(u, prefix, suffix)
if err != nil { if err != nil {
fmt.Printf(" ✗ %s: %v\n", u.Name, err) fmt.Printf(" ✗ %s: %v\n", u.Name, err)
continue continue
@@ -68,7 +68,7 @@ func runInstall(cmd *cobra.Command, args []string) error {
continue continue
} }
if err := systemd.Install(u, prefix, suffix, serviceUser); err != nil { if err := systemd.Install(u, prefix, suffix); err != nil {
fmt.Printf(" ✗ failed: %s: %v\n", u.Name, err) fmt.Printf(" ✗ failed: %s: %v\n", u.Name, err)
} else { } else {
path, _ := systemd.UnitPath(u, prefix, suffix) path, _ := systemd.UnitPath(u, prefix, suffix)

View File

@@ -7,6 +7,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var version = "0.0.9"
var configPath string var configPath string
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
@@ -16,7 +18,7 @@ var rootCmd = &cobra.Command{
It discovers running containers, stores them in a config file, It discovers running containers, stores them in a config file,
and generates + manages systemd .service units for each one.`, and generates + manages systemd .service units for each one.`,
Version: "0.1.0", Version: version,
} }
func Execute() { func Execute() {

View File

@@ -63,10 +63,10 @@ func runUpdate(cmd *cobra.Command, args []string) error {
return err return err
} }
prefix, suffix, serviceUser := cfg.Prefix, cfg.Suffix, cfg.EffectiveServiceUser() prefix, suffix := cfg.Prefix, cfg.Suffix
if systemd.IsInstalled(*u, prefix, suffix) { if systemd.IsInstalled(*u, prefix, suffix) {
if err := systemd.Install(*u, prefix, suffix, serviceUser); err != nil { if err := systemd.Install(*u, prefix, suffix); err != nil {
return fmt.Errorf("recreating service file: %w", err) return fmt.Errorf("recreating service file: %w", err)
} }
path, _ := systemd.UnitPath(*u, prefix, suffix) path, _ := systemd.UnitPath(*u, prefix, suffix)

View File

@@ -3,7 +3,6 @@ package config
import ( import (
"fmt" "fmt"
"os" "os"
"os/user"
"path/filepath" "path/filepath"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
@@ -14,32 +13,23 @@ const DefaultConfigPath = "/etc/unitdore/units.yaml"
// Unit represents a single managed container unit. // Unit represents a single managed container unit.
type Unit struct { type Unit struct {
Name string `yaml:"name"` Name string `yaml:"name"`
Runtime string `yaml:"runtime"` // podman | docker | exec Runtime string `yaml:"runtime"` // podman | docker | exec
User string `yaml:"user,omitempty"` // empty = root/system unit User string `yaml:"user,omitempty"` // empty = root/system unit
Command string `yaml:"command,omitempty"` // override ExecStart Command string `yaml:"command,omitempty"` // override ExecStart
Order int `yaml:"order"` Order int `yaml:"order"`
Delay string `yaml:"delay,omitempty"` // e.g. "5s" Delay string `yaml:"delay,omitempty"` // e.g. "5s"
Enabled bool `yaml:"enabled"` Enabled bool `yaml:"enabled"`
DisabledReason string `yaml:"disabled_reason,omitempty"` DisabledReason string `yaml:"disabled_reason,omitempty"`
Restart bool `yaml:"restart,omitempty"` // enable Restart=on-failure
RestartSec int `yaml:"restart_sec,omitempty"` // seconds between restarts
RestartRetries int `yaml:"restart_retries,omitempty"` // max restart attempts (StartLimitBurst)
} }
// Config is the root config structure. // Config is the root config structure.
type Config struct { type Config struct {
Units []Unit `yaml:"units"` Units []Unit `yaml:"units"`
Prefix string `yaml:"prefix,omitempty"` // prepended to generated service name, e.g. "prod-" Prefix string `yaml:"prefix,omitempty"` // prepended to generated service name, e.g. "prod-"
Suffix string `yaml:"suffix,omitempty"` // appended to generated service name, e.g. "-svc" Suffix string `yaml:"suffix,omitempty"` // appended to generated service name, e.g. "-svc"
ServiceUser string `yaml:"service_user,omitempty"` // User= in [Service] section; defaults to "unitdore"
}
// EffectiveServiceUser returns the configured service user, or the current OS user if unset.
func (c *Config) EffectiveServiceUser() string {
if c.ServiceUser != "" {
return c.ServiceUser
}
if u, err := user.Current(); err == nil {
return u.Username
}
return "root"
} }
// Load reads and parses the config file at path. // Load reads and parses the config file at path.

2
go.mod
View File

@@ -1,6 +1,6 @@
module github.com/warkanum/unitdore module github.com/warkanum/unitdore
go 1.26.1 go 1.23.0
require ( require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect

View File

@@ -1,10 +1,10 @@
# Maintainer: Hein (Warky Devs) <hein@warky.dev> # Maintainer: Hein (Warky Devs) <hein@warky.dev>
pkgname=unitdore pkgname=unitdore
pkgver=0.1.0 pkgver=0.0.9
pkgrel=1 pkgrel=1
pkgdesc="A door you open and close for container units — manage containers via systemd" pkgdesc="A door you open and close for container units — manage containers via systemd"
arch=('x86_64' 'aarch64') arch=('x86_64' 'aarch64')
url="https://warky.dev" url="https://git.warky.dev/wdevs/unitdore"
license=('MIT') license=('MIT')
depends=('systemd') depends=('systemd')
optdepends=( optdepends=(
@@ -12,8 +12,7 @@ optdepends=(
'docker: Docker container runtime support' 'docker: Docker container runtime support'
) )
makedepends=('go') makedepends=('go')
backup=('etc/unitdore/units.yaml') source=("$pkgname-$pkgver.zip::$url/archive/v$pkgver.zip")
source=("$pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz")
sha256sums=('SKIP') sha256sums=('SKIP')
build() { build() {
@@ -21,7 +20,7 @@ build() {
export CGO_ENABLED=0 export CGO_ENABLED=0
go build \ go build \
-trimpath \ -trimpath \
-ldflags "-X main.version=$pkgver" \ -ldflags "-X github.com/warkanum/unitdore/cmd.version=$pkgver" \
-o "$pkgname" . -o "$pkgname" .
} }

View File

@@ -1,15 +1,17 @@
Name: unitdore Name: unitdore
Version: 0.1.0 Version: 0.0.9
Release: 1%{?dist} Release: 1%{?dist}
Summary: Manage container units via systemd Summary: Manage container units via systemd
License: MIT License: MIT
URL: https://warky.dev URL: https://git.warky.dev/wdevs/unitdore
Source0: %{name}-%{version}.tar.gz Source0: %{name}-%{version}.tar.gz
BuildRequires: golang >= 1.21 BuildRequires: golang >= 1.23
Requires: systemd Requires: systemd
%global debug_package %{nil}
%description %description
Unitdore bridges your container runtime (Podman, Docker) and systemd. Unitdore bridges your container runtime (Podman, Docker) and systemd.
It discovers running containers, stores them in a config file, and generates It discovers running containers, stores them in a config file, and generates
@@ -22,24 +24,21 @@ and manages systemd .service units for each one.
export CGO_ENABLED=0 export CGO_ENABLED=0
go build \ go build \
-trimpath \ -trimpath \
-ldflags "-X main.version=%{version}" \ -ldflags "-X github.com/warkanum/unitdore/cmd.version=%{version}" \
-o %{name} . -o %{name} .
%install %install
# Binary
install -Dm755 %{name} %{buildroot}%{_bindir}/%{name} install -Dm755 %{name} %{buildroot}%{_bindir}/%{name}
# Man page
install -Dm644 docs/unitdore.1 %{buildroot}%{_mandir}/man1/unitdore.1 install -Dm644 docs/unitdore.1 %{buildroot}%{_mandir}/man1/unitdore.1
install -Dm644 LICENSE %{buildroot}%{_licensedir}/%{name}/LICENSE
# Config dir
install -dm755 %{buildroot}%{_sysconfdir}/unitdore install -dm755 %{buildroot}%{_sysconfdir}/unitdore
%files %files
%license LICENSE
%{_bindir}/%{name} %{_bindir}/%{name}
%{_mandir}/man1/unitdore.1* %{_mandir}/man1/unitdore.1*
%dir %{_sysconfdir}/unitdore %dir %{_sysconfdir}/unitdore
%changelog %changelog
* Tue Apr 08 2026 Hein (Warky Devs) <hein@warky.dev> - 0.1.0-1 * Wed Apr 08 2026 Hein (Warky Devs) <hein@warky.dev> - 0.0.5-1
- Initial package - Initial package

View File

@@ -2,6 +2,9 @@ Package: unitdore
Version: VERSION Version: VERSION
Architecture: ARCH Architecture: ARCH
Maintainer: Hein (Warky Devs) <hein@warky.dev> Maintainer: Hein (Warky Devs) <hein@warky.dev>
Section: admin
Priority: optional
Homepage: https://git.warky.dev/wdevs/unitdore
Depends: systemd Depends: systemd
Recommends: podman | docker.io Recommends: podman | docker.io
Description: A door you open and close for container units Description: A door you open and close for container units

View File

@@ -33,7 +33,8 @@ func (p *Podman) ListRunning() ([]Container, error) {
var raw []podmanContainer var raw []podmanContainer
if err := json.Unmarshal(out, &raw); err != nil { if err := json.Unmarshal(out, &raw); err != nil {
return nil, fmt.Errorf("parsing podman output: %w", err) // Podman installed but output is not valid JSON (e.g. OCI runtime misconfigured)
return nil, nil
} }
var containers []Container var containers []Container

View File

@@ -13,15 +13,20 @@ const systemUnitTemplate = `# /etc/systemd/system/{{.ServiceName}}
[Unit] [Unit]
Description=Unitdore: {{.Unit.Name}} ({{.Unit.Runtime}}) Description=Unitdore: {{.Unit.Name}} ({{.Unit.Runtime}})
After=network.target After=network.target{{with .RuntimeService}} {{.}}
Requires={{.}}{{end}}
[Service] [Service]
Type=simple Type=simple
User={{.ServiceUser}}
ExecStart={{.ExecStart}} ExecStart={{.ExecStart}}
ExecStop={{.ExecStop}} ExecStop={{.ExecStop}}
{{- if .Unit.Restart}}
Restart=on-failure Restart=on-failure
RestartSec=5 RestartSec={{.Unit.RestartSec}}
{{- if gt .Unit.RestartRetries 0}}
StartLimitBurst={{.Unit.RestartRetries}}
{{- end}}
{{- end}}
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
@@ -38,19 +43,24 @@ After=default.target
Type=simple Type=simple
ExecStart={{.ExecStart}} ExecStart={{.ExecStart}}
ExecStop={{.ExecStop}} ExecStop={{.ExecStop}}
{{- if .Unit.Restart}}
Restart=on-failure Restart=on-failure
RestartSec=5 RestartSec={{.Unit.RestartSec}}
{{- if gt .Unit.RestartRetries 0}}
StartLimitBurst={{.Unit.RestartRetries}}
{{- end}}
{{- end}}
[Install] [Install]
WantedBy=default.target WantedBy=default.target
` `
type templateData struct { type templateData struct {
ServiceName string ServiceName string
Unit config.Unit Unit config.Unit
ExecStart string ExecStart string
ExecStop string ExecStop string
ServiceUser string RuntimeService string
} }
// ServiceName returns the systemd service name for a unit, with optional prefix/suffix. // ServiceName returns the systemd service name for a unit, with optional prefix/suffix.
@@ -59,15 +69,15 @@ func ServiceName(u config.Unit, prefix, suffix string) string {
} }
// Generate produces the .service file content for a unit. // Generate produces the .service file content for a unit.
func Generate(u config.Unit, prefix, suffix, serviceUser string) (string, error) { func Generate(u config.Unit, prefix, suffix string) (string, error) {
execStart, execStop := buildExecCommands(u) execStart, execStop := buildExecCommands(u)
data := templateData{ data := templateData{
ServiceName: ServiceName(u, prefix, suffix), ServiceName: ServiceName(u, prefix, suffix),
Unit: u, Unit: u,
ExecStart: execStart, ExecStart: execStart,
ExecStop: execStop, ExecStop: execStop,
ServiceUser: serviceUser, RuntimeService: runtimeService(u.Runtime),
} }
tmplStr := systemUnitTemplate tmplStr := systemUnitTemplate
@@ -87,6 +97,15 @@ func Generate(u config.Unit, prefix, suffix, serviceUser string) (string, error)
return buf.String(), nil return buf.String(), nil
} }
// runtimeService returns the systemd service name that must be running for the
// given container runtime, or "" if none is required (e.g. daemonless podman).
func runtimeService(runtime string) string {
if runtime == "docker" {
return "docker.service"
}
return ""
}
func buildExecCommands(u config.Unit) (start, stop string) { func buildExecCommands(u config.Unit) (start, stop string) {
// If a custom command is provided, use it directly // If a custom command is provided, use it directly
if u.Command != "" { if u.Command != "" {

View File

@@ -35,7 +35,7 @@ func TestGenerate_SystemUnit(t *testing.T) {
Enabled: true, Enabled: true,
} }
content, err := Generate(u, "", "", "unitdore") content, err := Generate(u, "", "")
if err != nil { if err != nil {
t.Fatalf("Generate() error: %v", err) t.Fatalf("Generate() error: %v", err)
} }
@@ -50,7 +50,6 @@ func TestGenerate_SystemUnit(t *testing.T) {
"WantedBy=multi-user.target", "WantedBy=multi-user.target",
"ExecStart=/usr/bin/podman start -a nginx", "ExecStart=/usr/bin/podman start -a nginx",
"ExecStop=/usr/bin/podman stop nginx", "ExecStop=/usr/bin/podman stop nginx",
"Restart=on-failure",
"Generated by unitdore", "Generated by unitdore",
} }
@@ -59,6 +58,16 @@ func TestGenerate_SystemUnit(t *testing.T) {
t.Errorf("Generate() missing %q in output:\n%s", check, content) t.Errorf("Generate() missing %q in output:\n%s", check, content)
} }
} }
if strings.Contains(content, "User=") {
t.Errorf("Generate() system unit should not contain User= directive:\n%s", content)
}
if strings.Contains(content, "Requires=") {
t.Errorf("Generate() podman system unit should not contain Requires= (podman is daemonless):\n%s", content)
}
if strings.Contains(content, "Restart=") {
t.Errorf("Generate() restart should be disabled by default:\n%s", content)
}
} }
func TestGenerate_UserUnit(t *testing.T) { func TestGenerate_UserUnit(t *testing.T) {
@@ -70,7 +79,7 @@ func TestGenerate_UserUnit(t *testing.T) {
Enabled: true, Enabled: true,
} }
content, err := Generate(u, "", "", "unitdore") content, err := Generate(u, "", "")
if err != nil { if err != nil {
t.Fatalf("Generate() error: %v", err) t.Fatalf("Generate() error: %v", err)
} }
@@ -93,6 +102,51 @@ func TestGenerate_UserUnit(t *testing.T) {
} }
} }
func TestGenerate_WithRestart(t *testing.T) {
t.Run("restart with retries", func(t *testing.T) {
u := config.Unit{
Name: "nginx",
Runtime: "podman",
Enabled: true,
Restart: true,
RestartSec: 5,
RestartRetries: 3,
}
content, err := Generate(u, "", "")
if err != nil {
t.Fatalf("Generate() error: %v", err)
}
for _, want := range []string{"Restart=on-failure", "RestartSec=5", "StartLimitBurst=3"} {
if !strings.Contains(content, want) {
t.Errorf("Generate() missing %q in output:\n%s", want, content)
}
}
})
t.Run("restart without retries", func(t *testing.T) {
u := config.Unit{
Name: "nginx",
Runtime: "podman",
Enabled: true,
Restart: true,
RestartSec: 10,
}
content, err := Generate(u, "", "")
if err != nil {
t.Fatalf("Generate() error: %v", err)
}
if !strings.Contains(content, "Restart=on-failure") {
t.Errorf("Generate() missing Restart=on-failure:\n%s", content)
}
if !strings.Contains(content, "RestartSec=10") {
t.Errorf("Generate() missing RestartSec=10:\n%s", content)
}
if strings.Contains(content, "StartLimitBurst") {
t.Errorf("Generate() should not contain StartLimitBurst when retries=0:\n%s", content)
}
})
}
func TestGenerate_CustomCommand(t *testing.T) { func TestGenerate_CustomCommand(t *testing.T) {
u := config.Unit{ u := config.Unit{
Name: "custom", Name: "custom",
@@ -101,7 +155,7 @@ func TestGenerate_CustomCommand(t *testing.T) {
Enabled: true, Enabled: true,
} }
content, err := Generate(u, "", "", "unitdore") content, err := Generate(u, "", "")
if err != nil { if err != nil {
t.Fatalf("Generate() error: %v", err) t.Fatalf("Generate() error: %v", err)
} }
@@ -118,16 +172,21 @@ func TestGenerate_DockerRuntime(t *testing.T) {
Enabled: true, Enabled: true,
} }
content, err := Generate(u, "", "", "unitdore") content, err := Generate(u, "", "")
if err != nil { if err != nil {
t.Fatalf("Generate() error: %v", err) t.Fatalf("Generate() error: %v", err)
} }
if !strings.Contains(content, "ExecStart=/usr/bin/docker start redis") { checks := []string{
t.Errorf("Generate() wrong ExecStart for docker:\n%s", content) "ExecStart=/usr/bin/docker start redis",
"ExecStop=/usr/bin/docker stop redis",
"After=network.target docker.service",
"Requires=docker.service",
} }
if !strings.Contains(content, "ExecStop=/usr/bin/docker stop redis") { for _, check := range checks {
t.Errorf("Generate() wrong ExecStop for docker:\n%s", content) if !strings.Contains(content, check) {
t.Errorf("Generate() docker runtime missing %q in output:\n%s", check, content)
}
} }
} }
@@ -138,7 +197,7 @@ func TestGenerate_UnknownRuntime(t *testing.T) {
Enabled: true, Enabled: true,
} }
content, err := Generate(u, "", "", "unitdore") content, err := Generate(u, "", "")
if err != nil { if err != nil {
t.Fatalf("Generate() should not error on unknown runtime: %v", err) t.Fatalf("Generate() should not error on unknown runtime: %v", err)
} }
@@ -155,7 +214,7 @@ func TestGenerate_WithPrefixSuffix(t *testing.T) {
Enabled: true, Enabled: true,
} }
content, err := Generate(u, "prod-", "-web", "unitdore") content, err := Generate(u, "prod-", "-web")
if err != nil { if err != nil {
t.Fatalf("Generate() error: %v", err) t.Fatalf("Generate() error: %v", err)
} }

View File

@@ -27,8 +27,8 @@ func UnitPath(u config.Unit, prefix, suffix string) (string, error) {
} }
// Install writes the .service file for a unit and reloads systemd. // Install writes the .service file for a unit and reloads systemd.
func Install(u config.Unit, prefix, suffix, serviceUser string) error { func Install(u config.Unit, prefix, suffix string) error {
content, err := Generate(u, prefix, suffix, serviceUser) content, err := Generate(u, prefix, suffix)
if err != nil { if err != nil {
return err return err
} }