6
.gitignore
vendored
6
.gitignore
vendored
@@ -22,3 +22,9 @@ cover*
|
|||||||
# nsis
|
# nsis
|
||||||
nsis/*.dll
|
nsis/*.dll
|
||||||
nsis/*.exe
|
nsis/*.exe
|
||||||
|
|
||||||
|
doc/share
|
||||||
|
__pycache__
|
||||||
|
|
||||||
|
.rpmmacros
|
||||||
|
*.gpg
|
||||||
|
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2022-2024 Patrice Ferlet
|
Copyright (c) 2022-2025 The Katenary authors
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
315
Makefile
315
Makefile
@@ -1,58 +1,89 @@
|
|||||||
|
# Strict mode
|
||||||
|
SHELL := bash
|
||||||
|
.SHELLFLAGS := -eu -o pipefail -c
|
||||||
|
.ONESHELL:
|
||||||
|
.DELETE_ON_ERROR:
|
||||||
|
.PHONY: help dist-clean dist package build install test doc nsis
|
||||||
|
MAKEFLAGS += --warn-undefined-variables
|
||||||
|
MAKEFLAGS += --no-builtin-rules
|
||||||
|
|
||||||
|
# Get a version string from git
|
||||||
CUR_SHA=$(shell git log -n1 --pretty='%h')
|
CUR_SHA=$(shell git log -n1 --pretty='%h')
|
||||||
CUR_BRANCH=$(shell git branch --show-current)
|
CUR_BRANCH=$(shell git branch --show-current)
|
||||||
VERSION=$(shell git describe --exact-match --tags $(CUR_SHA) 2>/dev/null || echo $(CUR_BRANCH)-$(CUR_SHA))
|
VERSION=$(shell git describe --exact-match --tags $(CUR_SHA) 2>/dev/null || echo $(CUR_BRANCH)-$(CUR_SHA))# use by golang flags
|
||||||
|
|
||||||
# get the container (podman is preferred, but docker is also supported)
|
|
||||||
# TODO: prpose nerdctl
|
|
||||||
CTN:=$(shell which podman 2>&1 1>/dev/null && echo "podman" || echo "docker")
|
|
||||||
PREFIX=~/.local
|
|
||||||
|
|
||||||
|
# Go build command and environment variables for target OS and architecture
|
||||||
GOVERSION=1.24
|
GOVERSION=1.24
|
||||||
GO=container
|
GO=container# container, local
|
||||||
OUT=katenary
|
OUTPUT=katenary
|
||||||
|
|
||||||
MODE=default
|
|
||||||
RELEASE=""
|
|
||||||
# if release mode
|
|
||||||
ifeq ($(MODE),release)
|
|
||||||
VERSION:=release-$(VERSION)
|
|
||||||
endif
|
|
||||||
|
|
||||||
BLD_CMD=go build -ldflags="-X 'katenary/generator.Version=$(VERSION)'" -o $(OUT) ./cmd/katenary
|
|
||||||
GOOS=linux
|
GOOS=linux
|
||||||
GOARCH=amd64
|
GOARCH=amd64
|
||||||
CGO_ENABLED=0
|
CGO_ENABLED=0
|
||||||
|
PREFIX=~/.local
|
||||||
|
|
||||||
# GPG signer
|
|
||||||
SIGNER=metal3d@gmail.com
|
|
||||||
|
|
||||||
# upx compression
|
warn-docker:
|
||||||
|
@echo -e "\033[1;31mWarning: Docker is not recommended, use Podman instead.\033[0m"
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
# Get the container (Podman is preferred, but docker can be used too. It may failed with Docker.)
|
||||||
|
# TODO: prpose nerdctl
|
||||||
|
CTN:=$(shell which podman 2>&1 1>/dev/null && echo "podman" || echo "docker")
|
||||||
|
ifeq ($(CTN),podman)
|
||||||
|
CTN_USERMAP=--userns=keep-id
|
||||||
|
else
|
||||||
|
$(MAKE) warn-docker
|
||||||
|
CTN_USERMAP=--user=$(shell id -u):$(shell id -g) -e HOME=/tmp
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
# Packaging OCI image, to build rpm, deb, pacman, tar packages
|
||||||
|
# We changes the keep-id uid/gid for Podman, so that the user inside the container is the same as the user outside.
|
||||||
|
# For Docker, as it doesn't support userns, we use common options, but it may fail...
|
||||||
|
PKG_OCI_IMAGE=packaging:fedora
|
||||||
|
ifeq ($(CTN),podman)
|
||||||
|
# podman
|
||||||
|
PKG_OCI_OPTS:=--rm -it \
|
||||||
|
-v ./:/opt/katenary:z \
|
||||||
|
--userns keep-id:uid=1001,gid=1001 \
|
||||||
|
$(PKG_OCI_IMAGE)
|
||||||
|
else
|
||||||
|
# docker
|
||||||
|
PKG_OCI_OPTS:=--rm -it \
|
||||||
|
-v ./:/opt/katenary:z \
|
||||||
|
-e HOME=/tmp \
|
||||||
|
$(CTN_USERMAP) \
|
||||||
|
$(PKG_OCI_IMAGE)
|
||||||
|
endif
|
||||||
|
GO_BUILD=go build -ldflags="-X 'katenary/generator.Version=$(VERSION)'" -o $(OUTPUT) ./cmd/katenary
|
||||||
|
|
||||||
|
|
||||||
|
# UPX compression
|
||||||
UPX_OPTS =
|
UPX_OPTS =
|
||||||
UPX ?= upx $(UPX_OPTS)
|
UPX ?= upx $(UPX_OPTS)
|
||||||
|
|
||||||
BUILD_IMAGE=docker.io/golang:$(GOVERSION)
|
BUILD_IMAGE=docker.io/golang:$(GOVERSION)
|
||||||
# SHELL=/bin/bash
|
|
||||||
|
|
||||||
# List of source files
|
# List of source files
|
||||||
SOURCES=$(wildcard ./*.go ./*/*.go ./*/*/*.go)
|
SOURCES=$(shell find -name "*.go" -or -name "*.tpl" -type f | grep -v -P "^./example|^./vendor")
|
||||||
# List of binaries to build and sign
|
# List of binaries to build and sign
|
||||||
BINARIES=dist/katenary-linux-amd64 dist/katenary-linux-arm64 dist/katenary.exe dist/katenary-darwin-amd64 dist/katenary-freebsd-amd64 dist/katenary-freebsd-arm64
|
BINARIES=\
|
||||||
BINARIES += dist/katenary-windows-setup.exe
|
dist/katenary-linux-amd64\
|
||||||
# installer
|
dist/katenary-linux-arm64\
|
||||||
|
dist/katenary-darwin-amd64\
|
||||||
|
dist/katenary-freebsd-amd64\
|
||||||
|
dist/katenary-freebsd-arm64\
|
||||||
|
dist/katenary.exe\
|
||||||
|
dist/katenary-windows-setup.exe
|
||||||
|
|
||||||
|
## GPG
|
||||||
# List of signatures to build
|
# List of signatures to build
|
||||||
ASC_BINARIES=$(patsubst %,%.asc,$(BINARIES))
|
ASC_BINARIES=$(patsubst %,%.asc,$(BINARIES))
|
||||||
|
# GPG signer
|
||||||
|
SIGNER=metal3d@gmail.com
|
||||||
|
|
||||||
# defaults
|
# Browser command to see coverage report after tests
|
||||||
BROWSER=$(shell command -v epiphany || echo xdg-open)
|
BROWSER=$(shell command -v epiphany || echo xdg-open)
|
||||||
SHELL := bash
|
|
||||||
# strict mode
|
|
||||||
.SHELLFLAGS := -eu -o pipefail -c
|
|
||||||
# One session per target
|
|
||||||
.ONESHELL:
|
|
||||||
.DELETE_ON_ERROR:
|
|
||||||
MAKEFLAGS += --warn-undefined-variables
|
|
||||||
MAKEFLAGS += --no-builtin-rules
|
|
||||||
.PHONY: help dist-clean build install tests test doc nsis
|
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
@@ -95,6 +126,7 @@ help:
|
|||||||
|
|
||||||
## BUILD
|
## BUILD
|
||||||
|
|
||||||
|
# Simply build the binary for the current OS and architecture
|
||||||
build: pull katenary
|
build: pull katenary
|
||||||
|
|
||||||
pull:
|
pull:
|
||||||
@@ -103,64 +135,70 @@ ifneq ($(GO),local)
|
|||||||
@$(CTN) pull $(BUILD_IMAGE)
|
@$(CTN) pull $(BUILD_IMAGE)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
katenary: $(SOURCES) Makefile go.mod go.sum
|
katenary: $(SOURCES) go.mod go.sum
|
||||||
ifeq ($(GO),local)
|
ifeq ($(GO),local)
|
||||||
@echo "=> Build on host using go"
|
@echo "=> Build on host using go"
|
||||||
$(BLD_CMD)
|
$(GO_BUILD)
|
||||||
else ifeq ($(CTN),podman)
|
|
||||||
@echo "=> Build in container using" $(CTN)
|
|
||||||
@podman run -e CGO_ENABLED=$(CGO_ENABLED) -e GOOS=$(GOOS) -e GOARCH=$(GOARCH) \
|
|
||||||
--rm -v $(PWD):/go/src/katenary:z -w /go/src/katenary --userns keep-id $(BUILD_IMAGE) $(BLD_CMD)
|
|
||||||
else
|
else
|
||||||
@echo "=> Build in container using" $(CTN)
|
@echo "=> Build in container using" $(CTN)
|
||||||
@docker run -e CGO_ENABLED=$(CGO_ENABLED) -e GOOS=$(GOOS) -e GOARCH=$(GOARCH) \
|
@$(CTN) run \
|
||||||
--rm -v $(PWD):/go/src/katenary:z -w /go/src/katenary --user $(shell id -u):$(shell id -g) -e HOME=/tmp $(BUILD_IMAGE) $(BLD_CMD)
|
-e CGO_ENABLED=$(CGO_ENABLED) \
|
||||||
|
-e GOOS=$(GOOS) \
|
||||||
|
-e GOARCH=$(GOARCH) \
|
||||||
|
--rm -v $(PWD):/go/src/katenary:z \
|
||||||
|
-w /go/src/katenary \
|
||||||
|
-v ./.cache:/go/pkg/mod:z \
|
||||||
|
$(CTN_USERMAP) \
|
||||||
|
$(BUILD_IMAGE) $(GO_BUILD)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
# Make dist, build executables for all platforms, sign them, and compress them with upx if possible.
|
# Make dist, build executables for all platforms, sign them, and compress them with upx if possible.
|
||||||
# Also generate the windows installer.
|
# Also generate the windows installer.
|
||||||
dist: prepare $(BINARIES) upx gpg-sign check-sign
|
dist: prepare $(BINARIES) upx packages
|
||||||
|
dist-full: dist-clean dist gpg-sign check-sign rpm-sign check-dist-all
|
||||||
|
|
||||||
prepare: pull
|
prepare: pull packager-oci-image
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
|
|
||||||
dist/katenary-linux-amd64:
|
dist/katenary-linux-amd64: $(SOURCES) go.mod go.sum
|
||||||
@echo
|
@echo
|
||||||
@echo -e "\033[1;32mBuilding katenary $(VERSION) for linux-amd64...\033[0m"
|
@echo -e "\033[1;32mBuilding katenary $(VERSION) for linux-amd64...\033[0m"
|
||||||
$(MAKE) katenary GOOS=linux GOARCH=amd64 OUT=$@
|
$(MAKE) katenary GOOS=linux GOARCH=amd64 OUTPUT=$@
|
||||||
strip $@
|
strip $@
|
||||||
|
|
||||||
dist/katenary-linux-arm64:
|
dist/katenary-linux-arm64: $(SOURCES) go.mod go.sum
|
||||||
@echo
|
@echo
|
||||||
@echo -e "\033[1;32mBuilding katenary $(VERSION) for linux-arm...\033[0m"
|
@echo -e "\033[1;32mBuilding katenary $(VERSION) for linux-arm...\033[0m"
|
||||||
$(MAKE) katenary GOOS=linux GOARCH=arm64 OUT=$@
|
$(MAKE) katenary GOOS=linux GOARCH=arm64 OUTPUT=$@
|
||||||
|
|
||||||
dist/katenary.exe:
|
dist/katenary.exe: $(SOURCES) go.mod go.sum
|
||||||
@echo
|
@echo
|
||||||
@echo -e "\033[1;32mBuilding katenary $(VERSION) for windows...\033[0m"
|
@echo -e "\033[1;32mBuilding katenary $(VERSION) for windows...\033[0m"
|
||||||
$(MAKE) katenary GOOS=windows GOARCH=amd64 OUT=$@
|
$(MAKE) katenary GOOS=windows GOARCH=amd64 OUTPUT=$@
|
||||||
|
|
||||||
dist/katenary-darwin-amd64:
|
dist/katenary-darwin-amd64: $(SOURCES) go.mod go.sum
|
||||||
@echo
|
@echo
|
||||||
@echo -e "\033[1;32mBuilding katenary $(VERSION) for darwin...\033[0m"
|
@echo -e "\033[1;32mBuilding katenary $(VERSION) for darwin...\033[0m"
|
||||||
$(MAKE) katenary GOOS=darwin GOARCH=amd64 OUT=$@
|
$(MAKE) katenary GOOS=darwin GOARCH=amd64 OUTPUT=$@
|
||||||
|
|
||||||
dist/katenary-freebsd-amd64:
|
dist/katenary-freebsd-amd64: $(SOURCES) go.mod go.sum
|
||||||
@echo
|
@echo
|
||||||
@echo -e "\033[1;32mBuilding katenary $(VERSION) for freebsd...\033[0m"
|
@echo -e "\033[1;32mBuilding katenary $(VERSION) for freebsd...\033[0m"
|
||||||
$(MAKE) katenary GOOS=freebsd GOARCH=amd64 OUT=$@
|
$(MAKE) katenary GOOS=freebsd GOARCH=amd64 OUTPUT=$@
|
||||||
strip $@
|
strip $@
|
||||||
|
|
||||||
dist/katenary-freebsd-arm64:
|
dist/katenary-freebsd-arm64: $(SOURCES) go.mod go.sum
|
||||||
@echo
|
@echo
|
||||||
@echo -e "\033[1;32mBuilding katenary $(VERSION) for freebsd-arm64...\033[0m"
|
@echo -e "\033[1;32mBuilding katenary $(VERSION) for freebsd-arm64...\033[0m"
|
||||||
$(MAKE) katenary GOOS=freebsd GOARCH=arm64 OUT=$@
|
$(MAKE) katenary GOOS=freebsd GOARCH=arm64 OUTPUT=$@
|
||||||
|
|
||||||
dist/katenary-windows-setup.exe: nsis/EnVar.dll dist/katenary.exe
|
dist/katenary-windows-setup.exe: nsis/EnVar.dll dist/katenary.exe
|
||||||
makensis -DAPP_VERSION=$(VERSION) nsis/katenary.nsi
|
@$(CTN) run -w /opt/katenary $(PKG_OCI_OPTS) \
|
||||||
|
makensis -DAPP_VERSION=$(VERSION) nsis/katenary.nsi
|
||||||
mv nsis/katenary-windows-setup.exe dist/katenary-windows-setup.exe
|
mv nsis/katenary-windows-setup.exe dist/katenary-windows-setup.exe
|
||||||
|
|
||||||
|
# Download the EnVar plugin for NSIS, put it in the nsis directory, and clean up
|
||||||
nsis/EnVar.dll:
|
nsis/EnVar.dll:
|
||||||
curl https://nsis.sourceforge.io/mediawiki/images/7/7f/EnVar_plugin.zip -o nsis/EnVar_plugin.zip
|
curl https://nsis.sourceforge.io/mediawiki/images/7/7f/EnVar_plugin.zip -o nsis/EnVar_plugin.zip
|
||||||
cd nsis
|
cd nsis
|
||||||
@@ -168,12 +206,105 @@ nsis/EnVar.dll:
|
|||||||
mv Plugins/x86-unicode/EnVar.dll EnVar.dll
|
mv Plugins/x86-unicode/EnVar.dll EnVar.dll
|
||||||
rm -rf EnVar_plugin.zip Plugins
|
rm -rf EnVar_plugin.zip Plugins
|
||||||
|
|
||||||
upx:
|
upx: dist/katenary-linux-amd64 dist/katenary-linux-arm64 dist/katenary-darwin-amd64
|
||||||
$(UPX) dist/katenary-linux-amd64
|
$(UPX) dist/katenary-linux-amd64
|
||||||
$(UPX) dist/katenary-linux-arm64
|
$(UPX) dist/katenary-linux-arm64
|
||||||
#$(UPX) dist/katenary.exe
|
|
||||||
$(UPX) dist/katenary-darwin-amd64 --force-macos
|
$(UPX) dist/katenary-darwin-amd64 --force-macos
|
||||||
|
|
||||||
|
## Linux / FreeBSD packages
|
||||||
|
|
||||||
|
DESCRIPTION := $(shell cat packaging/description | sed ':a;N;$$!ba;s/\n/\\n/g')
|
||||||
|
|
||||||
|
FPM_OPTS=--name katenary \
|
||||||
|
--url https://katenary.org \
|
||||||
|
--vendor "Katenary Project" \
|
||||||
|
--maintainer "Patrice Ferlet <metal3d@gmail.com>" \
|
||||||
|
--license "MIT" \
|
||||||
|
--description="$$(printf "$(DESCRIPTION)" | fold -s)"
|
||||||
|
|
||||||
|
# base files (doc...)
|
||||||
|
FPM_BASES=../LICENSE=/usr/local/share/doc/katenary/LICENSE \
|
||||||
|
../README.md=/usr/local/share/doc/katenary/README.md
|
||||||
|
|
||||||
|
FPM_COMMON_FILES=$(FPM_BASES) ../doc/share/man/man1/katenary.1=/usr/local/share/man/man1/katenary.1
|
||||||
|
|
||||||
|
# ArchLinux has got inconsistent /usr/local/man directory
|
||||||
|
FPM_COMMON_FILES_ARCHLINUX=$(FPM_BASES) ../doc/share/man/man1/katenary.1=/usr/local/man/man1/katenary.1 \
|
||||||
|
|
||||||
|
# Pacman refuses dashes in version, and should start with a number
|
||||||
|
PACMAN_VERSION=$(shell echo $(VERSION) | sed 's/-/./g; s/^v//')
|
||||||
|
|
||||||
|
define RPM_MACROS
|
||||||
|
%_signature gpg
|
||||||
|
%_gpg_path /home/builder/.gnupg
|
||||||
|
%_gpg_name $(SIGNER)
|
||||||
|
%_gpgbin /usr/bin/gpg2
|
||||||
|
%__gpg_sign_cmd %{__gpg} gpg --force-v3-sigs --batch --verbose --no-armor --no-secmem-warning -u "%{_gpg_name}" -sbo %{__signature_filename} --digest-algo sha256 %{__plaintext_filename}'
|
||||||
|
endef
|
||||||
|
|
||||||
|
rpm: dist/katenary-linux-$(GOARCH)
|
||||||
|
@echo "==> Building RPM packages for $(GOARCH)..."
|
||||||
|
$(CTN) run -w /opt/katenary/dist $(PKG_OCI_OPTS) \
|
||||||
|
fpm -s dir -t rpm -a $(GOARCH) -f $(FPM_OPTS) --version=$(VERSION) \
|
||||||
|
$(FPM_COMMON_FILES) \
|
||||||
|
./katenary-linux-$(GOARCH)=/usr/local/bin/katenary
|
||||||
|
rpm-sign:
|
||||||
|
[ -f .rpmmacros ] || echo "$(RPM_MACROS)" > .rpmmacros
|
||||||
|
[ -f .secret.gpg ] || gpg --export-secret-keys -a $(SIGNER) > .secret.gpg
|
||||||
|
$(CTN) run -w /opt/katenary/dist \
|
||||||
|
-v ./.secret.gpg:/home/builder/signer.gpg \
|
||||||
|
-v packager-gpg:/home/builder/.gnupg \
|
||||||
|
$(PKG_OCI_OPTS) \
|
||||||
|
gpg --import /home/builder/signer.gpg
|
||||||
|
$(CTN) run -w /opt/katenary/dist \
|
||||||
|
-v .rpmmacros:/home/builder/.rpmmacros:z \
|
||||||
|
-v packager-gpg:/home/builder/.gnupg \
|
||||||
|
$(PKG_OCI_OPTS) \
|
||||||
|
bash -c 'for rpm in $$(find . -iname "*.rpm"); do echo signing: $$rpm; rpm --addsign $$rpm; done'
|
||||||
|
|
||||||
|
deb:
|
||||||
|
@echo "==> Building DEB packages for $(GOARCH)..."
|
||||||
|
$(CTN) run -w /opt/katenary/dist $(PKG_OCI_OPTS) \
|
||||||
|
fpm -s dir -t deb -a $(GOARCH) -f $(FPM_OPTS) --version=$(VERSION) \
|
||||||
|
$(FPM_COMMON_FILES) \
|
||||||
|
./katenary-linux-$(GOARCH)=/usr/local/bin/katenary
|
||||||
|
|
||||||
|
pacman:
|
||||||
|
@echo "==> Building Pacman packages for $(GOARCH)..."
|
||||||
|
$(CTN) run -w /opt/katenary/dist $(PKG_OCI_OPTS) \
|
||||||
|
fpm -s dir -t pacman -a $(GOARCH) -f $(FPM_OPTS) --version=$(PACMAN_VERSION) \
|
||||||
|
$(FPM_COMMON_FILES_ARCHLINUX) \
|
||||||
|
./katenary-linux-$(GOARCH)=/usr/local/bin/katenary
|
||||||
|
|
||||||
|
freebsd:
|
||||||
|
@echo "==> Building FreeBSD packages for $(GOARCH)..."
|
||||||
|
$(CTN) run -w /opt/katenary/dist $(PKG_OCI_OPTS) \
|
||||||
|
fpm -s dir -t freebsd -a $(GOARCH) -f $(FPM_OPTS) --version=$(VERSION)\
|
||||||
|
$(FPM_COMMON_FILES) \
|
||||||
|
./katenary-freebsd-$(GOARCH)=/usr/local/bin/katenary
|
||||||
|
mv dist/katenary-$(VERSION).txz dist/katenary-freebsd-$(VERSION).$(GOARCH).txz
|
||||||
|
|
||||||
|
tar:
|
||||||
|
@echo "==> Building TAR packages for $(GOOS) $(GOARCH)..."
|
||||||
|
$(CTN) run -w /opt/katenary/dist $(PKG_OCI_OPTS) \
|
||||||
|
fpm -s dir -t tar -a $(GOARCH) -f $(FPM_OPTS) \
|
||||||
|
$(FPM_COMMON_FILES) \
|
||||||
|
./katenary-$(GOOS)-$(GOARCH)=/usr/local/bin/katenary
|
||||||
|
mv dist/katenary.tar dist/katenary-$(GOOS)-$(VERSION).$(GOARCH).tar
|
||||||
|
|
||||||
|
packages: manpage packager-oci-image
|
||||||
|
for arch in amd64 arm64; do \
|
||||||
|
$(MAKE) rpm GOARCH=$$arch; \
|
||||||
|
$(MAKE) deb GOARCH=$$arch; \
|
||||||
|
$(MAKE) pacman GOARCH=$$arch; \
|
||||||
|
$(MAKE) freebsd GOARCH=$$arch; \
|
||||||
|
$(MAKE) tar GOARCH=$$arch GOOS=linux; \
|
||||||
|
$(MAKE) tar GOARCH=$$arch GOOS=freebsd; \
|
||||||
|
done
|
||||||
|
|
||||||
|
packager-oci-image:
|
||||||
|
@$(CTN) build -t packaging:fedora ./packaging/oci 1>/dev/null
|
||||||
|
|
||||||
## GPG signing
|
## GPG signing
|
||||||
|
|
||||||
gpg-sign:
|
gpg-sign:
|
||||||
@@ -195,6 +326,52 @@ dist/%.asc: dist/%
|
|||||||
gpg --armor --detach-sign --default-key $(SIGNER) $< &>/dev/null || exit 1
|
gpg --armor --detach-sign --default-key $(SIGNER) $< &>/dev/null || exit 1
|
||||||
|
|
||||||
|
|
||||||
|
check-dist-rocky:
|
||||||
|
@echo "=> Checking Rocky Linux package..."
|
||||||
|
p=$(wildcard dist/*x86_64.rpm);
|
||||||
|
$(CTN) run --rm -it -v ./dist:/opt:z quay.io/rockylinux/rockylinux:latest bash -c "
|
||||||
|
rpm -ivh /opt/$$(basename $$p);
|
||||||
|
katenary version;
|
||||||
|
"
|
||||||
|
|
||||||
|
check-dist-fedora:
|
||||||
|
@echo "=> Checking Fedora package..."
|
||||||
|
p=$(wildcard dist/*x86_64.rpm);
|
||||||
|
$(CTN) run --rm -it -v ./dist:/opt:z quay.io/fedora/fedora:latest bash -c "
|
||||||
|
rpm -ivh /opt/$$(basename $$p);
|
||||||
|
katenary version;
|
||||||
|
"
|
||||||
|
|
||||||
|
check-dist-archlinux:
|
||||||
|
echo "=> Checking ArchLinux package..."
|
||||||
|
p=$(wildcard dist/*x86_64.pkg.tar.zst);
|
||||||
|
$(CTN) run --rm -it -v ./dist:/opt:z quay.io/archlinux/archlinux bash -c "
|
||||||
|
pacman -U /opt/$$(basename $$p) --noconfirm;
|
||||||
|
katenary version;
|
||||||
|
"
|
||||||
|
|
||||||
|
check-dist-debian:
|
||||||
|
@echo "=> Checking Debian package..."
|
||||||
|
p=$(wildcard dist/*amd64.deb);
|
||||||
|
$(CTN) run --rm -it -v ./dist:/opt:z debian:latest bash -c "
|
||||||
|
dpkg -i /opt/$$(basename $$p);
|
||||||
|
katenary version;
|
||||||
|
"
|
||||||
|
check-dist-ubuntu:
|
||||||
|
@echo "=> Checking Ubuntu package..."
|
||||||
|
p=$(wildcard dist/*amd64.deb);
|
||||||
|
$(CTN) run --rm -it -v ./dist:/opt:z ubuntu:latest bash -c "
|
||||||
|
dpkg -i /opt/$$(basename $$p);
|
||||||
|
katenary version;
|
||||||
|
"
|
||||||
|
|
||||||
|
check-dist-all:
|
||||||
|
$(MAKE) check-dist-fedora
|
||||||
|
$(MAKE) check-dist-rocky
|
||||||
|
$(MAKE) check-dist-debian
|
||||||
|
$(MAKE) check-dist-ubuntu
|
||||||
|
$(MAKE) check-dist-archlinux
|
||||||
|
|
||||||
## installation and uninstallation
|
## installation and uninstallation
|
||||||
|
|
||||||
install: build
|
install: build
|
||||||
@@ -203,8 +380,7 @@ install: build
|
|||||||
uninstall:
|
uninstall:
|
||||||
rm -f $(PREFIX)/bin/katenary
|
rm -f $(PREFIX)/bin/katenary
|
||||||
|
|
||||||
|
serve-doc: doc
|
||||||
serve-doc: __label_doc
|
|
||||||
@cd doc && \
|
@cd doc && \
|
||||||
[ -d venv ] || python -m venv venv; \
|
[ -d venv ] || python -m venv venv; \
|
||||||
source venv/bin/activate && \
|
source venv/bin/activate && \
|
||||||
@@ -220,6 +396,19 @@ doc:
|
|||||||
# generate the labels doc and code doc
|
# generate the labels doc and code doc
|
||||||
$(MAKE) __label_doc
|
$(MAKE) __label_doc
|
||||||
|
|
||||||
|
manpage:
|
||||||
|
@echo "=> Generating manpage from documentation"
|
||||||
|
@cd doc && \
|
||||||
|
[ -d venv ] || python -m venv venv; \
|
||||||
|
source venv/bin/activate && \
|
||||||
|
echo "==> Installing requirements in the virtual env..." && \
|
||||||
|
pip install -qq -r requirements.txt && \
|
||||||
|
pip install -qq -r manpage_requirements.txt && \
|
||||||
|
echo "==> Generating manpage..." && \
|
||||||
|
MANPAGE=true mkdocs build && \
|
||||||
|
rm -rf site &&
|
||||||
|
echo "==> Manpage generated in doc/share/man/man1/katenary.1"
|
||||||
|
|
||||||
install-gomarkdoc:
|
install-gomarkdoc:
|
||||||
go install github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest
|
go install github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest
|
||||||
|
|
||||||
@@ -262,8 +451,6 @@ sast:
|
|||||||
--exclude-rule go.lang.security.audit.crypto.use_of_weak_crypto.use-of-sha1 \
|
--exclude-rule go.lang.security.audit.crypto.use_of_weak_crypto.use-of-sha1 \
|
||||||
--metrics=on \
|
--metrics=on \
|
||||||
.
|
.
|
||||||
|
|
||||||
tests: test
|
|
||||||
test:
|
test:
|
||||||
@echo -e "\033[1;33mTesting katenary $(VERSION)...\033[0m"
|
@echo -e "\033[1;33mTesting katenary $(VERSION)...\033[0m"
|
||||||
go test -coverprofile=cover.out ./...
|
go test -coverprofile=cover.out ./...
|
||||||
|
@@ -149,7 +149,7 @@ TplName returns the name of the kubernetes resource as a template string. It is
|
|||||||
func TplValue(serviceName, variable string, pipes ...string) string
|
func TplValue(serviceName, variable string, pipes ...string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
TplValue returns a container by name and its index in the array.
|
TplValue returns a string that can be used in a template to access a value from the values file.
|
||||||
|
|
||||||
<a name="Warn"></a>
|
<a name="Warn"></a>
|
||||||
## func [Warn](<https://github.com/metal3d/katenary/blob/develop/utils/icons.go#L25>)
|
## func [Warn](<https://github.com/metal3d/katenary/blob/develop/utils/icons.go#L25>)
|
||||||
|
2
doc/manpage_requirements.txt
Normal file
2
doc/manpage_requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
beautifulsoup4==4.*
|
||||||
|
mkdocs-manpage[preprocess]
|
@@ -3,6 +3,16 @@ docs_dir: ./docs
|
|||||||
plugins:
|
plugins:
|
||||||
- search
|
- search
|
||||||
- inline-svg
|
- inline-svg
|
||||||
|
- manpage:
|
||||||
|
enabled: !ENV [MANPAGE, false]
|
||||||
|
preprocess: preprocess.py
|
||||||
|
pages:
|
||||||
|
- title: Katenary
|
||||||
|
header: Katenary helm chart generator
|
||||||
|
output: share/man/man1/katenary.1
|
||||||
|
inputs:
|
||||||
|
- usage.md
|
||||||
|
- labels.md
|
||||||
theme:
|
theme:
|
||||||
name: material
|
name: material
|
||||||
custom_dir: overrides
|
custom_dir: overrides
|
||||||
|
22
doc/preprocess.py
Normal file
22
doc/preprocess.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
"""Called by mkdocs to preprocess files and build manpages"""
|
||||||
|
|
||||||
|
from bs4 import BeautifulSoup, Tag
|
||||||
|
|
||||||
|
|
||||||
|
def to_remove(tag: Tag) -> bool:
|
||||||
|
"""Removes images, SVGs, links containing images or SVGs, and permalinks from the BeautifulSoup object."""
|
||||||
|
if tag.name in {"img", "svg"}:
|
||||||
|
return True
|
||||||
|
# remove links containing images or SVGs
|
||||||
|
if tag.name == "a" and tag.img and to_remove(tag.img):
|
||||||
|
return True
|
||||||
|
# remove permalinks
|
||||||
|
if tag.name == "a" and "headerlink" in tag.get("class", ()):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def preprocess(soup: BeautifulSoup, output: str) -> None:
|
||||||
|
"""Preprocess the BeautifulSoup object to remove unwanted elements."""
|
||||||
|
for element in soup.find_all(to_remove):
|
||||||
|
element.decompose()
|
@@ -136,6 +136,7 @@ func (d *Deployment) AddContainer(service types.ServiceConfig) {
|
|||||||
Resources: corev1.ResourceRequirements{
|
Resources: corev1.ResourceRequirements{
|
||||||
Requests: corev1.ResourceList{},
|
Requests: corev1.ResourceList{},
|
||||||
},
|
},
|
||||||
|
Command: service.Command,
|
||||||
}
|
}
|
||||||
if _, ok := d.chart.Values[service.Name]; !ok {
|
if _, ok := d.chart.Values[service.Name]; !ok {
|
||||||
d.chart.Values[service.Name] = NewValue(service, d.isMainApp)
|
d.chart.Values[service.Name] = NewValue(service, d.isMainApp)
|
||||||
|
@@ -495,3 +495,39 @@ services:
|
|||||||
t.Errorf("Expected valueFrom to be set")
|
t.Errorf("Expected valueFrom to be set")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCheckCommand(t *testing.T) {
|
||||||
|
composeFile := `
|
||||||
|
services:
|
||||||
|
web-app:
|
||||||
|
image: nginx:1.29
|
||||||
|
command:
|
||||||
|
- sh
|
||||||
|
- -c
|
||||||
|
- |-
|
||||||
|
echo "Hello, World!"
|
||||||
|
echo "Done"
|
||||||
|
`
|
||||||
|
|
||||||
|
// composeFile = fmt.Sprintf(composeFile, labels.Prefix())
|
||||||
|
tmpDir := setup(composeFile)
|
||||||
|
defer teardown(tmpDir)
|
||||||
|
|
||||||
|
currentDir, _ := os.Getwd()
|
||||||
|
os.Chdir(tmpDir)
|
||||||
|
defer os.Chdir(currentDir)
|
||||||
|
|
||||||
|
output := internalCompileTest(t, "-s", "templates/web_app/deployment.yaml")
|
||||||
|
dt := v1.Deployment{}
|
||||||
|
if err := yaml.Unmarshal([]byte(output), &dt); err != nil {
|
||||||
|
t.Errorf(unmarshalError, err)
|
||||||
|
}
|
||||||
|
// find the command in the container
|
||||||
|
command := dt.Spec.Template.Spec.Containers[0].Command
|
||||||
|
if len(command) != 3 {
|
||||||
|
t.Errorf("Expected command to have 3 elements, got %d", len(command))
|
||||||
|
}
|
||||||
|
if command[0] != "sh" || command[1] != "-c" {
|
||||||
|
t.Errorf("Expected command to be 'sh -c', got %s", strings.Join(command, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
package generator
|
package generator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version is the version of katenary. It is set at compile time.
|
// Version is the version of katenary. It is set at compile time.
|
||||||
@@ -12,13 +12,17 @@ var Version = "master" // changed at compile time
|
|||||||
// the version is set at compile time for the github release. But, it the user get
|
// the version is set at compile time for the github release. But, it the user get
|
||||||
// katneary using `go install`, the version should be different.
|
// katneary using `go install`, the version should be different.
|
||||||
func GetVersion() string {
|
func GetVersion() string {
|
||||||
if strings.HasPrefix(Version, "release-") {
|
// try to get the semantic version from the Version variable (theorically set at compile time)
|
||||||
|
if reg := regexp.MustCompile(`^v?\d+.\d+.\d+.*|^release-.*`); reg.MatchString(Version) {
|
||||||
return Version
|
return Version
|
||||||
}
|
}
|
||||||
// get the version from the build info
|
|
||||||
v, ok := debug.ReadBuildInfo()
|
// OK... let's try to get the version from the build info
|
||||||
if ok {
|
// get the version from the build info (when installed with go install)
|
||||||
|
if v, ok := debug.ReadBuildInfo(); ok {
|
||||||
return v.Main.Version + "-" + v.GoVersion
|
return v.Main.Version + "-" + v.GoVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OK... none worked, so we return the default version
|
||||||
return Version
|
return Version
|
||||||
}
|
}
|
||||||
|
@@ -8,11 +8,24 @@ import (
|
|||||||
func TestVersion(t *testing.T) {
|
func TestVersion(t *testing.T) {
|
||||||
// we build on "devel" branch
|
// we build on "devel" branch
|
||||||
v := GetVersion()
|
v := GetVersion()
|
||||||
|
// by default, the version comes from build info and it's a development version
|
||||||
if !strings.Contains(v, "(devel)") {
|
if !strings.Contains(v, "(devel)") {
|
||||||
t.Errorf("Expected version to be set, got %s", v)
|
t.Errorf("Expected version to be set, got %s", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// now, imagine we are on a release branch
|
// now, imagine we are on a release branch
|
||||||
|
Version = "1.0.0"
|
||||||
|
v = GetVersion()
|
||||||
|
if !strings.Contains(v, "1.0.0") {
|
||||||
|
t.Errorf("Expected version to be set, got %s", v)
|
||||||
|
}
|
||||||
|
// now, imagine we are on v1.0.0
|
||||||
|
Version = "v1.0.0"
|
||||||
|
v = GetVersion()
|
||||||
|
if !strings.Contains(v, "v1.0.0") {
|
||||||
|
t.Errorf("Expected version to be set, got %s", v)
|
||||||
|
}
|
||||||
|
// we can also compile a release branch
|
||||||
Version = "release-1.0.0"
|
Version = "release-1.0.0"
|
||||||
v = GetVersion()
|
v = GetVersion()
|
||||||
if !strings.Contains(v, "release-1.0.0") {
|
if !strings.Contains(v, "release-1.0.0") {
|
||||||
|
2
go.mod
2
go.mod
@@ -1,4 +1,4 @@
|
|||||||
module katenary // github.com/metal3d/katenary
|
module katenary // github.com/katenay/katenary
|
||||||
|
|
||||||
go 1.24.0
|
go 1.24.0
|
||||||
|
|
||||||
|
@@ -92,8 +92,13 @@ Section "Install"
|
|||||||
File "..\dist\katenary.exe"
|
File "..\dist\katenary.exe"
|
||||||
File "..\LICENSE"
|
File "..\LICENSE"
|
||||||
File "..\README.md"
|
File "..\README.md"
|
||||||
WriteUninstaller "$INSTDIR\uninstall-katenary.exe"
|
|
||||||
|
|
||||||
|
WriteUninstaller "$INSTDIR\uninstall-katenary.exe"
|
||||||
|
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Katenary" "DisplayName" "Katenary"
|
||||||
|
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Katenary" "UninstallString" "$INSTDIR\uninstall-katenary.exe"
|
||||||
|
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Katenary" "InstallLocation" "$INSTDIR"
|
||||||
|
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Katenary" "DisplayIcon" "$INSTDIR\katenary.exe"
|
||||||
|
|
||||||
EnVar::SetHKCU
|
EnVar::SetHKCU
|
||||||
Pop $0
|
Pop $0
|
||||||
|
|
||||||
@@ -114,4 +119,6 @@ Section "Uninstall"
|
|||||||
Delete "$INSTDIR\LICENSE"
|
Delete "$INSTDIR\LICENSE"
|
||||||
Delete "$INSTDIR\README.md"
|
Delete "$INSTDIR\README.md"
|
||||||
RMDir "$INSTDIR"
|
RMDir "$INSTDIR"
|
||||||
|
|
||||||
|
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Katenary"
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
4
packaging/description
Normal file
4
packaging/description
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
Katenary transforms docker/podman compose files to Helm Charts.
|
||||||
|
It harnesses the labels from your "compose" file to craft complete Helm Charts effortlessly, saving you time and energy.
|
||||||
|
- Simple automated CLI: Katenary handles the grunt work, generating everything needed for seamless service binding and Helm Chart creation.
|
||||||
|
- Effortless Efficiency: You only need to add labels when it's necessary to precise things. Then call katenary convert and let the magic happen.
|
20
packaging/oci/Containerfile
Normal file
20
packaging/oci/Containerfile
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
FROM registry.fedoraproject.org/fedora:42
|
||||||
|
RUN set -eux; \
|
||||||
|
microdnf -y install \
|
||||||
|
rubygems rpmbuild rpmsign bsdtar mingw-nsis-base.x86_64 mingw32-nsis.noarch gpg2; \
|
||||||
|
microdnf clean all;
|
||||||
|
|
||||||
|
# create user with 999 UID/GID
|
||||||
|
RUN set -eux; \
|
||||||
|
groupadd -g 1001 builder; \
|
||||||
|
useradd -m -u 1001 -g 1001 -d /home/builder -s /bin/bash builder; \
|
||||||
|
chown builder:builder /home/builder
|
||||||
|
|
||||||
|
USER builder
|
||||||
|
ENV PATH="/home/builder/bin:${PATH}"
|
||||||
|
WORKDIR /home/builder
|
||||||
|
RUN set -eux; \
|
||||||
|
gem install fpm
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user