diff --git a/.gitignore b/.gitignore index 8c1ff8b..1fda1d7 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,9 @@ cover* # nsis nsis/*.dll nsis/*.exe + +doc/share +__pycache__ + +.rpmmacros +*.gpg diff --git a/LICENSE b/LICENSE index 76b1ebf..d15fdf4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ 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 of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile index 8c785c7..41279a5 100644 --- a/Makefile +++ b/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_BRANCH=$(shell git branch --show-current) -VERSION=$(shell git describe --exact-match --tags $(CUR_SHA) 2>/dev/null || echo $(CUR_BRANCH)-$(CUR_SHA)) - -# 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 +VERSION=$(shell git describe --exact-match --tags $(CUR_SHA) 2>/dev/null || echo $(CUR_BRANCH)-$(CUR_SHA))# use by golang flags +# Go build command and environment variables for target OS and architecture GOVERSION=1.24 -GO=container -OUT=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 +GO=container# container, local +OUTPUT=katenary GOOS=linux GOARCH=amd64 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 ?= upx $(UPX_OPTS) BUILD_IMAGE=docker.io/golang:$(GOVERSION) -# SHELL=/bin/bash # 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 -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 += dist/katenary-windows-setup.exe -# installer +BINARIES=\ + dist/katenary-linux-amd64\ + 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 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) -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 @@ -95,6 +126,7 @@ help: ## BUILD +# Simply build the binary for the current OS and architecture build: pull katenary pull: @@ -103,64 +135,70 @@ ifneq ($(GO),local) @$(CTN) pull $(BUILD_IMAGE) endif -katenary: $(SOURCES) Makefile go.mod go.sum +katenary: $(SOURCES) go.mod go.sum ifeq ($(GO),local) @echo "=> Build on host using go" - $(BLD_CMD) -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) + $(GO_BUILD) else @echo "=> Build in container using" $(CTN) - @docker run -e CGO_ENABLED=$(CGO_ENABLED) -e GOOS=$(GOOS) -e GOARCH=$(GOARCH) \ - --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) + @$(CTN) run \ + -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 # Make dist, build executables for all platforms, sign them, and compress them with upx if possible. # 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 -dist/katenary-linux-amd64: +dist/katenary-linux-amd64: $(SOURCES) go.mod go.sum @echo @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 $@ -dist/katenary-linux-arm64: +dist/katenary-linux-arm64: $(SOURCES) go.mod go.sum @echo @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 -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 -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 -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 $@ -dist/katenary-freebsd-arm64: +dist/katenary-freebsd-arm64: $(SOURCES) go.mod go.sum @echo @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 - 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 +# Download the EnVar plugin for NSIS, put it in the nsis directory, and clean up nsis/EnVar.dll: curl https://nsis.sourceforge.io/mediawiki/images/7/7f/EnVar_plugin.zip -o nsis/EnVar_plugin.zip cd nsis @@ -168,12 +206,105 @@ nsis/EnVar.dll: mv Plugins/x86-unicode/EnVar.dll EnVar.dll 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-arm64 - #$(UPX) dist/katenary.exe $(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 " \ + --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-sign: @@ -195,6 +326,52 @@ dist/%.asc: dist/% 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 install: build @@ -203,8 +380,7 @@ install: build uninstall: rm -f $(PREFIX)/bin/katenary - -serve-doc: __label_doc +serve-doc: doc @cd doc && \ [ -d venv ] || python -m venv venv; \ source venv/bin/activate && \ @@ -220,6 +396,19 @@ doc: # generate the labels doc and code 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: 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 \ --metrics=on \ . - -tests: test test: @echo -e "\033[1;33mTesting katenary $(VERSION)...\033[0m" go test -coverprofile=cover.out ./... diff --git a/doc/docs/packages/utils.md b/doc/docs/packages/utils.md index 78a6551..3afadd0 100644 --- a/doc/docs/packages/utils.md +++ b/doc/docs/packages/utils.md @@ -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 ``` -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. ## func [Warn]() diff --git a/doc/manpage_requirements.txt b/doc/manpage_requirements.txt new file mode 100644 index 0000000..9072507 --- /dev/null +++ b/doc/manpage_requirements.txt @@ -0,0 +1,2 @@ +beautifulsoup4==4.* +mkdocs-manpage[preprocess] diff --git a/doc/mkdocs.yml b/doc/mkdocs.yml index 80925d3..64196d5 100644 --- a/doc/mkdocs.yml +++ b/doc/mkdocs.yml @@ -3,6 +3,16 @@ docs_dir: ./docs plugins: - search - 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: name: material custom_dir: overrides diff --git a/doc/preprocess.py b/doc/preprocess.py new file mode 100644 index 0000000..d691cc1 --- /dev/null +++ b/doc/preprocess.py @@ -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() diff --git a/generator/deployment.go b/generator/deployment.go index 2345882..0e8fafb 100644 --- a/generator/deployment.go +++ b/generator/deployment.go @@ -136,6 +136,7 @@ func (d *Deployment) AddContainer(service types.ServiceConfig) { Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{}, }, + Command: service.Command, } if _, ok := d.chart.Values[service.Name]; !ok { d.chart.Values[service.Name] = NewValue(service, d.isMainApp) diff --git a/generator/deployment_test.go b/generator/deployment_test.go index d9e3f97..6139629 100644 --- a/generator/deployment_test.go +++ b/generator/deployment_test.go @@ -495,3 +495,39 @@ services: 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, " ")) + } +} diff --git a/generator/version.go b/generator/version.go index b528773..309c955 100644 --- a/generator/version.go +++ b/generator/version.go @@ -1,8 +1,8 @@ package generator import ( + "regexp" "runtime/debug" - "strings" ) // 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 // katneary using `go install`, the version should be different. 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 } - // get the version from the build info - v, ok := debug.ReadBuildInfo() - if ok { + + // OK... let's try to get the version from the build info + // get the version from the build info (when installed with go install) + if v, ok := debug.ReadBuildInfo(); ok { return v.Main.Version + "-" + v.GoVersion } + + // OK... none worked, so we return the default version return Version } diff --git a/generator/version_test.go b/generator/version_test.go index c65c2f3..9b153c7 100644 --- a/generator/version_test.go +++ b/generator/version_test.go @@ -8,11 +8,24 @@ import ( func TestVersion(t *testing.T) { // we build on "devel" branch v := GetVersion() + // by default, the version comes from build info and it's a development version if !strings.Contains(v, "(devel)") { t.Errorf("Expected version to be set, got %s", v) } // 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" v = GetVersion() if !strings.Contains(v, "release-1.0.0") { diff --git a/go.mod b/go.mod index 0af6081..54a12c0 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module katenary // github.com/metal3d/katenary +module katenary // github.com/katenay/katenary go 1.24.0 diff --git a/nsis/katenary.nsi b/nsis/katenary.nsi index f098c18..3a7c4cd 100644 --- a/nsis/katenary.nsi +++ b/nsis/katenary.nsi @@ -92,8 +92,13 @@ Section "Install" File "..\dist\katenary.exe" File "..\LICENSE" 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 Pop $0 @@ -114,4 +119,6 @@ Section "Uninstall" Delete "$INSTDIR\LICENSE" Delete "$INSTDIR\README.md" RMDir "$INSTDIR" + + DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Katenary" SectionEnd diff --git a/packaging/description b/packaging/description new file mode 100644 index 0000000..f3cbb89 --- /dev/null +++ b/packaging/description @@ -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. diff --git a/packaging/oci/Containerfile b/packaging/oci/Containerfile new file mode 100644 index 0000000..3cc865d --- /dev/null +++ b/packaging/oci/Containerfile @@ -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 + + +