From 00409472b7d9b2a9a0794dbd0851b5535d128a21 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Thu, 21 Aug 2025 15:17:25 +0200 Subject: [PATCH] chore(packages): Make better packages - we need man page in docs to build on CI/CD platform - new workflows to build packages and push them to the repository --- .gitea/workflows/build-and-package.yaml | 152 ++++ .gitignore | 1 - doc/docs/packages/internal/generator.md | 168 ++-- .../packages/internal/generator/extrafiles.md | 4 +- .../internal/generator/katenaryfile.md | 8 +- .../packages/internal/generator/labels.md | 14 +- .../internal/generator/labels/labelstructs.md | 46 +- doc/docs/packages/internal/parser.md | 2 +- doc/docs/packages/internal/utils.md | 40 +- doc/mkdocs.yml | 2 +- doc/share/man/man1/katenary.1 | 796 ++++++++++++++++++ makefiles/build.mk | 2 +- makefiles/packager.mk | 32 +- oci/katenary/Containerfile | 2 +- 14 files changed, 1123 insertions(+), 146 deletions(-) create mode 100644 .gitea/workflows/build-and-package.yaml create mode 100644 doc/share/man/man1/katenary.1 diff --git a/.gitea/workflows/build-and-package.yaml b/.gitea/workflows/build-and-package.yaml new file mode 100644 index 0000000..e07899a --- /dev/null +++ b/.gitea/workflows/build-and-package.yaml @@ -0,0 +1,152 @@ +on: + push: + tags: + - "*" + +env: + VERSION: ${{ gitea.ref_name }} + PACKAGE_API: https://repo.katenary.io/api/packages/katenary + CGO_ENABLED: 0 + BIN_TARGET: /usr/bin/katenary + FPM_BASE: ../LICENSE=/usr/share/doc/katenary/LICENSE ../README.md=/usr/share/doc/katenary/README.md + FPM_COMMON_FILES: ../doc/share/man/man1/katenary.1=/usr/share/man/man1/katenary.1 + FPM_COMMON_FILES_ARCHLINUX: ../doc/share/man/man1/katenary.1=/usr/man/man1/katenary.1 + VENDOR: "Katenary Project" + MAINTANER: "Patrice Ferlet " + LICENSE: MIT + DESCRIPTION: "Effortless conversion from compose files (docker, podman) to Helm Charts" + URL: "https://katenary.io" + +jobs: + build-packages: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + strategy: + matrix: + goarch: [amd64, arm64] + goos: [linux, freebsd, windows, darwin] + exclude: + - goos: windows + goarch: arm64 + - goos: darwin + goarch: arm64 + + steps: + - name: Install Unix dependencies + if: matrix.goos == 'linux' || matrix.goos == 'freebsd' + run: |- + sudo apt-get update && sudo apt-get install -y rpm zstd libarchive-tools binutils ruby curl + sudo gem install fpm + + - name: Install Windows dependencies + if: matrix.goos == 'windows' + run: |- + sudo apt-get update && sudo apt-get install -y nsis curl + + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.25 + + - name: Compile binary + if: matrix.goos == 'linux' || matrix.goos == 'freebsd' || matrix.goos == 'darwin' + run: |- + mkdir -p dist + GOARCH=${{ matrix.goarch }} GOOS=${{ matrix.goos }}\ + go build -ldflags="-X 'repo.katenary.io/katenary/katenary/internal/generator.Version=$VERSION'" \ + -trimpath -o dist/katenary-${{ matrix.goos }}-${{ matrix.goarch }} ./cmd/katenary + + - name: Package (Linux) + if: matrix.goos == 'linux' + run: |- + mkdir -p dist + cd dist + # rpm and deb + for p in rpm deb; do + fpm -s dir -t $p \ + --name katenary \ + --url "$URL" \ + --vendor "$VENDOR" \ + --maintainer "$MAINTANER" \ + --license "$LICENSE" \ + --description "$DESCRIPTION" \ + -a ${{ matrix.goarch }} -f $FPM_OPTS --version=$VERSION \ + $FPM_BASE $FPM_COMMON_FILES \ + ./katenary-${{ matrix.goos }}-${{ matrix.goarch }}=$BIN_TARGET + done + # arch linux + fpm -s dir -t pacman \ + --name katenary \ + --url "$URL" \ + --vendor "$VENDOR" \ + --maintainer "$MAINTANER" \ + --license "$LICENSE" \ + --description "$DESCRIPTION" \ + -a ${{ matrix.goarch }} -f $FPM_OPTS --version=$VERSION \ + $FPM_BASE $FPM_COMMON_FILES_ARCHLINUX \ + ./katenary-${{ matrix.goos }}-${{ matrix.goarch }}=$BIN_TARGET + + - name: Package (FreeBSD) + if: matrix.goos == 'freebsd' + run: |- + # freebsd + mkdir -p dist + cd dist + fpm -s dir -t freebsd \ + --name katenary \ + --url "$URL" \ + --vendor "$VENDOR" \ + --maintainer "$MAINTANER" \ + --license "$LICENSE" \ + --description "$DESCRIPTION" \ + -a ${{ matrix.goarch }} -f $FPM_OPTS --version=$VERSION \ + $FPM_BASE $FPM_COMMON_FILES \ + ./katenary-${{ matrix.goos }}-${{ matrix.goarch }}=$BIN_TARGET + + - name: Package setup.exe for windows + if: matrix.goos == 'windows' + run: |- + mkdir -p dist + GOARCH=${{ matrix.goarch }} GOOS=${{ matrix.goos }}\ + go build -ldflags="-X 'repo.katenary.io/katenary/katenary/internal/generator.Version=$VERSION'" \ + -trimpath -o dist/katenary.exe ./cmd/katenary + curl https://nsis.sourceforge.io/mediawiki/images/7/7f/EnVar_plugin.zip -o nsis/EnVar_plugin.zip + cd nsis + unzip -o EnVar_plugin.zip Plugins/x86-unicode/EnVar.dll + mv Plugins/x86-unicode/EnVar.dll EnVar.dll + cd .. + makensis -DAPP_VERSION=$VERSION nsis/katenary.nsi + mv nsis/katenary-windows-setup.exe dist/katenary-windows-setup.exe + + - name: Upload to packages repositories + run: |- + for file in katenary-{freebsd,linux}-{amd64,arm64} katenary-darwin-amd64 katenary.exe katenary-windows-setup.exe; do + [[ -f dist/$file ]] || continue + echo "Push $file" + curl -sSLf --user ${{ gitea.actor }}:${{ secrets.ACCESS_TOKEN }} \ + --upload-file dist/$file \ + ${PACKAGE_API}/generic/katenary/${VERSION}/$(basename $file) + done + for file in $(find dist -name "*.rpm"); do + echo "Push $file" + curl -sSLf --user ${{ gitea.actor }}:${{ secrets.ACCESS_TOKEN }} \ + --upload-file $file \ + ${PACKAGE_API}/rpm/upload + done + for file in $(find dist -name "*.deb"); do + echo "Push $file" + curl -sSLf --user ${{ gitea.actor }}:${{ secrets.ACCESS_TOKEN }} \ + --upload-file $file \ + ${PACKAGE_API}/debian/pool/any/main/upload + done + for file in $(find dist -name "*.zst"); do + echo "Push $file" + curl -sSLf --user ${{ gitea.actor }}:${{ secrets.ACCESS_TOKEN }} \ + --upload-file $file \ + ${PACKAGE_API}/arch/core + done diff --git a/.gitignore b/.gitignore index 972ace2..087e188 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,6 @@ cover* nsis/*.dll nsis/*.exe -doc/share __pycache__ .rpmmacros diff --git a/doc/docs/packages/internal/generator.md b/doc/docs/packages/internal/generator.md index f36494a..12a690a 100644 --- a/doc/docs/packages/internal/generator.md +++ b/doc/docs/packages/internal/generator.md @@ -35,7 +35,7 @@ var Version = "master" // changed at compile time ``` -## func [Convert]() +## func [Convert]() ```go func Convert(config ConvertOptions, dockerComposeFile ...string) error @@ -44,7 +44,7 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) error Convert a compose \(docker, podman...\) project to a helm chart. It calls Generate\(\) to generate the chart and then write it to the disk. -## func [GetLabels]() +## func [GetLabels]() ```go func GetLabels(serviceName, appName string) map[string]string @@ -53,7 +53,7 @@ func GetLabels(serviceName, appName string) map[string]string GetLabels returns the labels for a service. It uses the appName to replace the \_\_replace\_\_ in the labels. This is used to generate the labels in the templates. -## func [GetMatchLabels]() +## func [GetMatchLabels]() ```go func GetMatchLabels(serviceName, appName string) map[string]string @@ -62,7 +62,7 @@ func GetMatchLabels(serviceName, appName string) map[string]string GetMatchLabels returns the matchLabels for a service. It uses the appName to replace the \_\_replace\_\_ in the labels. This is used to generate the matchLabels in the templates. -## func [GetVersion]() +## func [GetVersion]() ```go func GetVersion() string @@ -71,7 +71,7 @@ func GetVersion() string GetVersion return the version of katneary. It's important to understand that 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 [Helper]() +## func [Helper]() ```go func Helper(name string) string @@ -80,7 +80,7 @@ func Helper(name string) string Helper returns the \_helpers.tpl file for a chart. -## func [NewCronJob]() +## func [NewCronJob]() ```go func NewCronJob(service types.ServiceConfig, chart *HelmChart, appName string) (*CronJob, *RBAC) @@ -89,7 +89,7 @@ func NewCronJob(service types.ServiceConfig, chart *HelmChart, appName string) ( NewCronJob creates a new CronJob from a compose service. The appName is the name of the application taken from the project name. -## func [ToK8SYaml]() +## func [ToK8SYaml]() ```go func ToK8SYaml(obj any) ([]byte, error) @@ -98,7 +98,7 @@ func ToK8SYaml(obj any) ([]byte, error) -## func [UnWrapTPL]() +## func [UnWrapTPL]() ```go func UnWrapTPL(in []byte) []byte @@ -107,7 +107,7 @@ func UnWrapTPL(in []byte) []byte UnWrapTPL removes the line wrapping from a template. -## type [ChartTemplate]() +## type [ChartTemplate]() ChartTemplate is a template of a chart. It contains the content of the template and the name of the service. This is used internally to generate the templates. @@ -119,7 +119,7 @@ type ChartTemplate struct { ``` -## type [ConfigMap]() +## type [ConfigMap]() ConfigMap is a kubernetes ConfigMap. Implements the DataMap interface. @@ -131,7 +131,7 @@ type ConfigMap struct { ``` -### func [NewConfigMap]() +### func [NewConfigMap]() ```go func NewConfigMap(service types.ServiceConfig, appName string, forFile bool) *ConfigMap @@ -140,7 +140,7 @@ func NewConfigMap(service types.ServiceConfig, appName string, forFile bool) *Co NewConfigMap creates a new ConfigMap from a compose service. The appName is the name of the application taken from the project name. The ConfigMap is filled by environment variables and labels "map\-env". -### func [NewConfigMapFromDirectory]() +### func [NewConfigMapFromDirectory]() ```go func NewConfigMapFromDirectory(service types.ServiceConfig, appName, path string) *ConfigMap @@ -149,7 +149,7 @@ func NewConfigMapFromDirectory(service types.ServiceConfig, appName, path string NewConfigMapFromDirectory creates a new ConfigMap from a compose service. This path is the path to the file or directory. If the path is a directory, all files in the directory are added to the ConfigMap. Each subdirectory are ignored. Note that the Generate\(\) function will create the subdirectories ConfigMaps. -### func \(\*ConfigMap\) [AddBinaryData]() +### func \(\*ConfigMap\) [AddBinaryData]() ```go func (c *ConfigMap) AddBinaryData(key string, value []byte) @@ -158,7 +158,7 @@ func (c *ConfigMap) AddBinaryData(key string, value []byte) AddBinaryData adds binary data to the configmap. Append or overwrite the value if the key already exists. -### func \(\*ConfigMap\) [AddData]() +### func \(\*ConfigMap\) [AddData]() ```go func (c *ConfigMap) AddData(key, value string) @@ -167,7 +167,7 @@ func (c *ConfigMap) AddData(key, value string) AddData adds a key value pair to the configmap. Append or overwrite the value if the key already exists. -### func \(\*ConfigMap\) [AppendDir]() +### func \(\*ConfigMap\) [AppendDir]() ```go func (c *ConfigMap) AppendDir(path string) error @@ -176,7 +176,7 @@ func (c *ConfigMap) AppendDir(path string) error AppendDir adds files from given path to the configmap. It is not recursive, to add all files in a directory, you need to call this function for each subdirectory. -### func \(\*ConfigMap\) [AppendFile]() +### func \(\*ConfigMap\) [AppendFile]() ```go func (c *ConfigMap) AppendFile(path string) error @@ -185,7 +185,7 @@ func (c *ConfigMap) AppendFile(path string) error -### func \(\*ConfigMap\) [Filename]() +### func \(\*ConfigMap\) [Filename]() ```go func (c *ConfigMap) Filename() string @@ -194,7 +194,7 @@ func (c *ConfigMap) Filename() string Filename returns the filename of the configmap. If the configmap is used for files, the filename contains the path. -### func \(\*ConfigMap\) [SetData]() +### func \(\*ConfigMap\) [SetData]() ```go func (c *ConfigMap) SetData(data map[string]string) @@ -203,7 +203,7 @@ func (c *ConfigMap) SetData(data map[string]string) SetData sets the data of the configmap. It replaces the entire data. -### func \(\*ConfigMap\) [Yaml]() +### func \(\*ConfigMap\) [Yaml]() ```go func (c *ConfigMap) Yaml() ([]byte, error) @@ -212,7 +212,7 @@ func (c *ConfigMap) Yaml() ([]byte, error) Yaml returns the yaml representation of the configmap -## type [ConfigMapMount]() +## type [ConfigMapMount]() @@ -223,7 +223,7 @@ type ConfigMapMount struct { ``` -## type [ConvertOptions]() +## type [ConvertOptions]() ConvertOptions are the options to convert a compose project to a helm chart. @@ -241,7 +241,7 @@ type ConvertOptions struct { ``` -## type [CronJob]() +## type [CronJob]() CronJob is a kubernetes CronJob. @@ -253,7 +253,7 @@ type CronJob struct { ``` -### func \(\*CronJob\) [Filename]() +### func \(\*CronJob\) [Filename]() ```go func (c *CronJob) Filename() string @@ -264,7 +264,7 @@ Filename returns the filename of the cronjob. Implements the Yaml interface. -### func \(\*CronJob\) [Yaml]() +### func \(\*CronJob\) [Yaml]() ```go func (c *CronJob) Yaml() ([]byte, error) @@ -275,7 +275,7 @@ Yaml returns the yaml representation of the cronjob. Implements the Yaml interface. -## type [CronJobValue]() +## type [CronJobValue]() CronJobValue is a cronjob configuration that will be saved in values.yaml. @@ -289,7 +289,7 @@ type CronJobValue struct { ``` -## type [DataMap]() +## type [DataMap]() DataMap is a kubernetes ConfigMap or Secret. It can be used to add data to the ConfigMap or Secret. @@ -301,7 +301,7 @@ type DataMap interface { ``` -## type [Deployment]() +## type [Deployment]() Deployment is a kubernetes Deployment. @@ -313,7 +313,7 @@ type Deployment struct { ``` -### func [NewDeployment]() +### func [NewDeployment]() ```go func NewDeployment(service types.ServiceConfig, chart *HelmChart) *Deployment @@ -322,7 +322,7 @@ func NewDeployment(service types.ServiceConfig, chart *HelmChart) *Deployment NewDeployment creates a new Deployment from a compose service. The appName is the name of the application taken from the project name. It also creates the Values map that will be used to create the values.yaml file. -### func \(\*Deployment\) [AddContainer]() +### func \(\*Deployment\) [AddContainer]() ```go func (d *Deployment) AddContainer(service types.ServiceConfig) @@ -331,7 +331,7 @@ func (d *Deployment) AddContainer(service types.ServiceConfig) AddContainer adds a container to the deployment. -### func \(\*Deployment\) [AddHealthCheck]() +### func \(\*Deployment\) [AddHealthCheck]() ```go func (d *Deployment) AddHealthCheck(service types.ServiceConfig, container *corev1.Container) @@ -340,7 +340,7 @@ func (d *Deployment) AddHealthCheck(service types.ServiceConfig, container *core -### func \(\*Deployment\) [AddIngress]() +### func \(\*Deployment\) [AddIngress]() ```go func (d *Deployment) AddIngress(service types.ServiceConfig, appName string) *Ingress @@ -349,7 +349,7 @@ func (d *Deployment) AddIngress(service types.ServiceConfig, appName string) *In AddIngress adds an ingress to the deployment. It creates the ingress object. -### func \(\*Deployment\) [AddLegacyVolume]() +### func \(\*Deployment\) [AddLegacyVolume]() ```go func (d *Deployment) AddLegacyVolume(name, kind string) @@ -358,7 +358,7 @@ func (d *Deployment) AddLegacyVolume(name, kind string) -### func \(\*Deployment\) [AddVolumes]() +### func \(\*Deployment\) [AddVolumes]() ```go func (d *Deployment) AddVolumes(service types.ServiceConfig, appName string) @@ -367,7 +367,7 @@ func (d *Deployment) AddVolumes(service types.ServiceConfig, appName string) AddVolumes adds a volume to the deployment. It does not create the PVC, it only adds the volumes to the deployment. If the volume is a bind volume it will warn the user that it is not supported yet. -### func \(\*Deployment\) [BindFrom]() +### func \(\*Deployment\) [BindFrom]() ```go func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment) @@ -376,7 +376,7 @@ func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment) -### func \(\*Deployment\) [BindMapFilesToContainer]() +### func \(\*Deployment\) [BindMapFilesToContainer]() ```go func (d *Deployment) BindMapFilesToContainer(service types.ServiceConfig, secrets []string, appName string) (*corev1.Container, int) @@ -385,7 +385,7 @@ func (d *Deployment) BindMapFilesToContainer(service types.ServiceConfig, secret -### func \(\*Deployment\) [DependsOn]() +### func \(\*Deployment\) [DependsOn]() ```go func (d *Deployment) DependsOn(to *Deployment, servicename string) error @@ -394,7 +394,7 @@ func (d *Deployment) DependsOn(to *Deployment, servicename string) error DependsOn adds a initContainer to the deployment that will wait for the service to be up. -### func \(\*Deployment\) [Filename]() +### func \(\*Deployment\) [Filename]() ```go func (d *Deployment) Filename() string @@ -403,7 +403,7 @@ func (d *Deployment) Filename() string Filename returns the filename of the deployment. -### func \(\*Deployment\) [MountExchangeVolumes]() +### func \(\*Deployment\) [MountExchangeVolumes]() ```go func (d *Deployment) MountExchangeVolumes() @@ -412,7 +412,7 @@ func (d *Deployment) MountExchangeVolumes() -### func \(\*Deployment\) [SetEnvFrom]() +### func \(\*Deployment\) [SetEnvFrom]() ```go func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string, samePod ...bool) @@ -421,7 +421,7 @@ func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string, sam SetEnvFrom sets the environment variables to a configmap. The configmap is created. -### func \(\*Deployment\) [Yaml]() +### func \(\*Deployment\) [Yaml]() ```go func (d *Deployment) Yaml() ([]byte, error) @@ -430,7 +430,7 @@ func (d *Deployment) Yaml() ([]byte, error) Yaml returns the yaml representation of the deployment. -## type [FileMapUsage]() +## type [FileMapUsage]() FileMapUsage is the usage of the filemap. @@ -448,7 +448,7 @@ const ( ``` -## type [HelmChart]() +## type [HelmChart]() HelmChart is a Helm Chart representation. It contains all the templates, values, versions, helpers... @@ -471,7 +471,7 @@ type HelmChart struct { ``` -### func [Generate]() +### func [Generate]() ```go func Generate(project *types.Project) (*HelmChart, error) @@ -491,7 +491,7 @@ The Generate function will create the HelmChart object this way: - Merge the same\-pod services. -### func [NewChart]() +### func [NewChart]() ```go func NewChart(name string) *HelmChart @@ -500,7 +500,7 @@ func NewChart(name string) *HelmChart NewChart creates a new empty chart with the given name. -### func \(\*HelmChart\) [SaveTemplates]() +### func \(\*HelmChart\) [SaveTemplates]() ```go func (chart *HelmChart) SaveTemplates(templateDir string) @@ -509,7 +509,7 @@ func (chart *HelmChart) SaveTemplates(templateDir string) SaveTemplates the templates of the chart to the given directory. -## type [Ingress]() +## type [Ingress]() @@ -521,7 +521,7 @@ type Ingress struct { ``` -### func [NewIngress]() +### func [NewIngress]() ```go func NewIngress(service types.ServiceConfig, Chart *HelmChart) *Ingress @@ -530,7 +530,7 @@ func NewIngress(service types.ServiceConfig, Chart *HelmChart) *Ingress NewIngress creates a new Ingress from a compose service. -### func \(\*Ingress\) [Filename]() +### func \(\*Ingress\) [Filename]() ```go func (ingress *Ingress) Filename() string @@ -539,7 +539,7 @@ func (ingress *Ingress) Filename() string -### func \(\*Ingress\) [Yaml]() +### func \(\*Ingress\) [Yaml]() ```go func (ingress *Ingress) Yaml() ([]byte, error) @@ -548,7 +548,7 @@ func (ingress *Ingress) Yaml() ([]byte, error) -## type [IngressValue]() +## type [IngressValue]() IngressValue is a ingress configuration that will be saved in values.yaml. @@ -564,7 +564,7 @@ type IngressValue struct { ``` -## type [PersistenceValue]() +## type [PersistenceValue]() PersistenceValue is a persistence configuration that will be saved in values.yaml. @@ -578,7 +578,7 @@ type PersistenceValue struct { ``` -## type [RBAC]() +## type [RBAC]() RBAC is a kubernetes RBAC containing a role, a rolebinding and an associated serviceaccount. @@ -591,7 +591,7 @@ type RBAC struct { ``` -### func [NewRBAC]() +### func [NewRBAC]() ```go func NewRBAC(service types.ServiceConfig, appName string) *RBAC @@ -600,7 +600,7 @@ func NewRBAC(service types.ServiceConfig, appName string) *RBAC NewRBAC creates a new RBAC from a compose service. The appName is the name of the application taken from the project name. -## type [RepositoryValue]() +## type [RepositoryValue]() RepositoryValue is a docker repository image and tag that will be saved in values.yaml. @@ -612,7 +612,7 @@ type RepositoryValue struct { ``` -## type [Role]() +## type [Role]() Role is a kubernetes Role. @@ -624,7 +624,7 @@ type Role struct { ``` -### func \(\*Role\) [Filename]() +### func \(\*Role\) [Filename]() ```go func (r *Role) Filename() string @@ -633,7 +633,7 @@ func (r *Role) Filename() string -### func \(\*Role\) [Yaml]() +### func \(\*Role\) [Yaml]() ```go func (r *Role) Yaml() ([]byte, error) @@ -642,7 +642,7 @@ func (r *Role) Yaml() ([]byte, error) -## type [RoleBinding]() +## type [RoleBinding]() RoleBinding is a kubernetes RoleBinding. @@ -654,7 +654,7 @@ type RoleBinding struct { ``` -### func \(\*RoleBinding\) [Filename]() +### func \(\*RoleBinding\) [Filename]() ```go func (r *RoleBinding) Filename() string @@ -663,7 +663,7 @@ func (r *RoleBinding) Filename() string -### func \(\*RoleBinding\) [Yaml]() +### func \(\*RoleBinding\) [Yaml]() ```go func (r *RoleBinding) Yaml() ([]byte, error) @@ -672,7 +672,7 @@ func (r *RoleBinding) Yaml() ([]byte, error) -## type [Secret]() +## type [Secret]() Secret is a kubernetes Secret. @@ -686,7 +686,7 @@ type Secret struct { ``` -### func [NewSecret]() +### func [NewSecret]() ```go func NewSecret(service types.ServiceConfig, appName string) *Secret @@ -695,7 +695,7 @@ func NewSecret(service types.ServiceConfig, appName string) *Secret NewSecret creates a new Secret from a compose service -### func \(\*Secret\) [AddData]() +### func \(\*Secret\) [AddData]() ```go func (s *Secret) AddData(key, value string) @@ -704,7 +704,7 @@ func (s *Secret) AddData(key, value string) AddData adds a key value pair to the secret. -### func \(\*Secret\) [Filename]() +### func \(\*Secret\) [Filename]() ```go func (s *Secret) Filename() string @@ -713,7 +713,7 @@ func (s *Secret) Filename() string Filename returns the filename of the secret. -### func \(\*Secret\) [SetData]() +### func \(\*Secret\) [SetData]() ```go func (s *Secret) SetData(data map[string]string) @@ -722,7 +722,7 @@ func (s *Secret) SetData(data map[string]string) SetData sets the data of the secret. -### func \(\*Secret\) [Yaml]() +### func \(\*Secret\) [Yaml]() ```go func (s *Secret) Yaml() ([]byte, error) @@ -731,7 +731,7 @@ func (s *Secret) Yaml() ([]byte, error) Yaml returns the yaml representation of the secret. -## type [Service]() +## type [Service]() Service is a kubernetes Service. @@ -743,7 +743,7 @@ type Service struct { ``` -### func [NewService]() +### func [NewService]() ```go func NewService(service types.ServiceConfig, appName string) *Service @@ -752,7 +752,7 @@ func NewService(service types.ServiceConfig, appName string) *Service NewService creates a new Service from a compose service. -### func \(\*Service\) [AddPort]() +### func \(\*Service\) [AddPort]() ```go func (s *Service) AddPort(port types.ServicePortConfig, serviceName ...string) @@ -761,7 +761,7 @@ func (s *Service) AddPort(port types.ServicePortConfig, serviceName ...string) AddPort adds a port to the service. -### func \(\*Service\) [Filename]() +### func \(\*Service\) [Filename]() ```go func (s *Service) Filename() string @@ -770,7 +770,7 @@ func (s *Service) Filename() string Filename returns the filename of the service. -### func \(\*Service\) [Yaml]() +### func \(\*Service\) [Yaml]() ```go func (s *Service) Yaml() ([]byte, error) @@ -779,7 +779,7 @@ func (s *Service) Yaml() ([]byte, error) Yaml returns the yaml representation of the service. -## type [ServiceAccount]() +## type [ServiceAccount]() ServiceAccount is a kubernetes ServiceAccount. @@ -791,7 +791,7 @@ type ServiceAccount struct { ``` -### func \(\*ServiceAccount\) [Filename]() +### func \(\*ServiceAccount\) [Filename]() ```go func (r *ServiceAccount) Filename() string @@ -800,7 +800,7 @@ func (r *ServiceAccount) Filename() string -### func \(\*ServiceAccount\) [Yaml]() +### func \(\*ServiceAccount\) [Yaml]() ```go func (r *ServiceAccount) Yaml() ([]byte, error) @@ -809,7 +809,7 @@ func (r *ServiceAccount) Yaml() ([]byte, error) -## type [TLS]() +## type [TLS]() @@ -821,7 +821,7 @@ type TLS struct { ``` -## type [Value]() +## type [Value]() Value will be saved in values.yaml. It contains configuration for all deployment and services. @@ -841,7 +841,7 @@ type Value struct { ``` -### func [NewValue]() +### func [NewValue]() ```go func NewValue(service types.ServiceConfig, main ...bool) *Value @@ -852,7 +852,7 @@ NewValue creates a new Value from a compose service. The value contains the nece If \`main\` is true, the tag will be empty because it will be set in the helm chart appVersion. -### func \(\*Value\) [AddIngress]() +### func \(\*Value\) [AddIngress]() ```go func (v *Value) AddIngress(host, path string) @@ -861,7 +861,7 @@ func (v *Value) AddIngress(host, path string) -### func \(\*Value\) [AddPersistence]() +### func \(\*Value\) [AddPersistence]() ```go func (v *Value) AddPersistence(volumeName string) @@ -870,7 +870,7 @@ func (v *Value) AddPersistence(volumeName string) AddPersistence adds persistence configuration to the Value. -## type [VolumeClaim]() +## type [VolumeClaim]() VolumeClaim is a kubernetes VolumeClaim. This is a PersistentVolumeClaim. @@ -882,7 +882,7 @@ type VolumeClaim struct { ``` -### func [NewVolumeClaim]() +### func [NewVolumeClaim]() ```go func NewVolumeClaim(service types.ServiceConfig, volumeName, appName string) *VolumeClaim @@ -891,7 +891,7 @@ func NewVolumeClaim(service types.ServiceConfig, volumeName, appName string) *Vo NewVolumeClaim creates a new VolumeClaim from a compose service. -### func \(\*VolumeClaim\) [Filename]() +### func \(\*VolumeClaim\) [Filename]() ```go func (v *VolumeClaim) Filename() string @@ -900,7 +900,7 @@ func (v *VolumeClaim) Filename() string Filename returns the suggested filename for a VolumeClaim. -### func \(\*VolumeClaim\) [Yaml]() +### func \(\*VolumeClaim\) [Yaml]() ```go func (v *VolumeClaim) Yaml() ([]byte, error) @@ -909,7 +909,7 @@ func (v *VolumeClaim) Yaml() ([]byte, error) Yaml marshals a VolumeClaim into yaml. -## type [Yaml]() +## type [Yaml]() Yaml is a kubernetes object that can be converted to yaml. diff --git a/doc/docs/packages/internal/generator/extrafiles.md b/doc/docs/packages/internal/generator/extrafiles.md index 67b12f9..c7483d3 100644 --- a/doc/docs/packages/internal/generator/extrafiles.md +++ b/doc/docs/packages/internal/generator/extrafiles.md @@ -8,7 +8,7 @@ import "katenary.io/internal/generator/extrafiles" Package extrafiles provides function to generate the Chart files that are not objects. Like README.md and notes.txt... -## func [NotesFile]() +## func [NotesFile]() ```go func NotesFile(services []string) string @@ -17,7 +17,7 @@ func NotesFile(services []string) string NotesFile returns the content of the note.txt file. -## func [ReadMeFile]() +## func [ReadMeFile]() ```go func ReadMeFile(charname, description string, values map[string]any) string diff --git a/doc/docs/packages/internal/generator/katenaryfile.md b/doc/docs/packages/internal/generator/katenaryfile.md index 8976c1c..f6fb81c 100644 --- a/doc/docs/packages/internal/generator/katenaryfile.md +++ b/doc/docs/packages/internal/generator/katenaryfile.md @@ -12,7 +12,7 @@ A katenary file, named "katenary.yml" or "katenary.yaml", is a file where you ca Formely, the file describe the same structure as in labels, and so that can be validated and completed by LSP. It also ease the use of katenary. -## func [GenerateSchema]() +## func [GenerateSchema]() ```go func GenerateSchema() string @@ -21,7 +21,7 @@ func GenerateSchema() string GenerateSchema generates the schema for the katenary.yaml file. -## func [OverrideWithConfig]() +## func [OverrideWithConfig]() ```go func OverrideWithConfig(project *types.Project) @@ -30,7 +30,7 @@ func OverrideWithConfig(project *types.Project) OverrideWithConfig overrides the project with the katenary.yaml file. It will set the labels of the services with the values from the katenary.yaml file. It work in memory, so it will not modify the original project. -## type [Service]() +## type [Service]() Service is a struct that contains the service configuration for katenary @@ -56,7 +56,7 @@ type Service struct { ``` -## type [StringOrMap]() +## type [StringOrMap]() StringOrMap is a struct that can be either a string or a map of strings. It's a helper struct to unmarshal the katenary.yaml file and produce the schema diff --git a/doc/docs/packages/internal/generator/labels.md b/doc/docs/packages/internal/generator/labels.md index 687adfb..617c95c 100644 --- a/doc/docs/packages/internal/generator/labels.md +++ b/doc/docs/packages/internal/generator/labels.md @@ -17,7 +17,7 @@ const KatenaryLabelPrefix = "katenary.v3" ``` -## func [GetLabelHelp]() +## func [GetLabelHelp]() ```go func GetLabelHelp(asMarkdown bool) string @@ -26,7 +26,7 @@ func GetLabelHelp(asMarkdown bool) string GetLabelHelp return the help for the labels. -## func [GetLabelHelpFor]() +## func [GetLabelHelpFor]() ```go func GetLabelHelpFor(labelname string, asMarkdown bool) string @@ -35,7 +35,7 @@ func GetLabelHelpFor(labelname string, asMarkdown bool) string GetLabelHelpFor returns the help for a specific label. -## func [GetLabelNames]() +## func [GetLabelNames]() ```go func GetLabelNames() []string @@ -44,7 +44,7 @@ func GetLabelNames() []string GetLabelNames returns a sorted list of all katenary label names. -## func [Prefix]() +## func [Prefix]() ```go func Prefix() string @@ -53,7 +53,7 @@ func Prefix() string -## type [Help]() +## type [Help]() Help is the documentation of a label. @@ -67,7 +67,7 @@ type Help struct { ``` -## type [Label]() +## type [Label]() Label is a katenary label to find in compose files. @@ -99,7 +99,7 @@ const ( ``` -### func [LabelName]() +### func [LabelName]() ```go func LabelName(name string) Label diff --git a/doc/docs/packages/internal/generator/labels/labelstructs.md b/doc/docs/packages/internal/generator/labels/labelstructs.md index 53d3026..2a784f5 100644 --- a/doc/docs/packages/internal/generator/labels/labelstructs.md +++ b/doc/docs/packages/internal/generator/labels/labelstructs.md @@ -8,7 +8,7 @@ import "katenary.io/internal/generator/labels/labelstructs" Package labelstructs is a package that contains the structs used to represent the labels in the yaml files. -## type [ConfigMapFiles]() +## type [ConfigMapFiles]() @@ -17,7 +17,7 @@ type ConfigMapFiles []string ``` -### func [ConfigMapFileFrom]() +### func [ConfigMapFileFrom]() ```go func ConfigMapFileFrom(data string) (ConfigMapFiles, error) @@ -26,7 +26,7 @@ func ConfigMapFileFrom(data string) (ConfigMapFiles, error) -## type [CronJob]() +## type [CronJob]() @@ -40,7 +40,7 @@ type CronJob struct { ``` -### func [CronJobFrom]() +### func [CronJobFrom]() ```go func CronJobFrom(data string) (*CronJob, error) @@ -49,7 +49,7 @@ func CronJobFrom(data string) (*CronJob, error) -## type [Dependency]() +## type [Dependency]() Dependency is a dependency of a chart to other charts. @@ -64,7 +64,7 @@ type Dependency struct { ``` -### func [DependenciesFrom]() +### func [DependenciesFrom]() ```go func DependenciesFrom(data string) ([]Dependency, error) @@ -73,7 +73,7 @@ func DependenciesFrom(data string) ([]Dependency, error) DependenciesFrom returns a slice of dependencies from the given string. -## type [EnvFrom]() +## type [EnvFrom]() @@ -82,7 +82,7 @@ type EnvFrom []string ``` -### func [EnvFromFrom]() +### func [EnvFromFrom]() ```go func EnvFromFrom(data string) (EnvFrom, error) @@ -91,7 +91,7 @@ func EnvFromFrom(data string) (EnvFrom, error) EnvFromFrom returns a EnvFrom from the given string. -## type [ExchangeVolume]() +## type [ExchangeVolume]() @@ -105,7 +105,7 @@ type ExchangeVolume struct { ``` -### func [NewExchangeVolumes]() +### func [NewExchangeVolumes]() ```go func NewExchangeVolumes(data string) ([]*ExchangeVolume, error) @@ -114,7 +114,7 @@ func NewExchangeVolumes(data string) ([]*ExchangeVolume, error) -## type [HealthCheck]() +## type [HealthCheck]() @@ -126,7 +126,7 @@ type HealthCheck struct { ``` -### func [ProbeFrom]() +### func [ProbeFrom]() ```go func ProbeFrom(data string) (*HealthCheck, error) @@ -135,7 +135,7 @@ func ProbeFrom(data string) (*HealthCheck, error) -## type [Ingress]() +## type [Ingress]() @@ -152,7 +152,7 @@ type Ingress struct { ``` -### func [IngressFrom]() +### func [IngressFrom]() ```go func IngressFrom(data string) (*Ingress, error) @@ -161,7 +161,7 @@ func IngressFrom(data string) (*Ingress, error) IngressFrom creates a new Ingress from a compose service. -## type [MapEnv]() +## type [MapEnv]() @@ -170,7 +170,7 @@ type MapEnv map[string]string ``` -### func [MapEnvFrom]() +### func [MapEnvFrom]() ```go func MapEnvFrom(data string) (MapEnv, error) @@ -179,7 +179,7 @@ func MapEnvFrom(data string) (MapEnv, error) MapEnvFrom returns a MapEnv from the given string. -## type [Ports]() +## type [Ports]() @@ -188,7 +188,7 @@ type Ports []uint32 ``` -### func [PortsFrom]() +### func [PortsFrom]() ```go func PortsFrom(data string) (Ports, error) @@ -197,7 +197,7 @@ func PortsFrom(data string) (Ports, error) PortsFrom returns a Ports from the given string. -## type [Secrets]() +## type [Secrets]() @@ -206,7 +206,7 @@ type Secrets []string ``` -### func [SecretsFrom]() +### func [SecretsFrom]() ```go func SecretsFrom(data string) (Secrets, error) @@ -215,7 +215,7 @@ func SecretsFrom(data string) (Secrets, error) -## type [TLS]() +## type [TLS]() @@ -226,7 +226,7 @@ type TLS struct { ``` -## type [ValueFrom]() +## type [ValueFrom]() @@ -235,7 +235,7 @@ type ValueFrom map[string]string ``` -### func [GetValueFrom]() +### func [GetValueFrom]() ```go func GetValueFrom(data string) (*ValueFrom, error) diff --git a/doc/docs/packages/internal/parser.md b/doc/docs/packages/internal/parser.md index d36de50..8ec7614 100644 --- a/doc/docs/packages/internal/parser.md +++ b/doc/docs/packages/internal/parser.md @@ -8,7 +8,7 @@ import "katenary.io/internal/parser" Package parser is a wrapper around compose\-go to parse compose files. -## func [Parse]() +## func [Parse]() ```go func Parse(profiles []string, envFiles []string, dockerComposeFile ...string) (*types.Project, error) diff --git a/doc/docs/packages/internal/utils.md b/doc/docs/packages/internal/utils.md index 13d29cf..c24a866 100644 --- a/doc/docs/packages/internal/utils.md +++ b/doc/docs/packages/internal/utils.md @@ -17,7 +17,7 @@ const DirectoryPermission = 0o755 ``` -## func [AsResourceName]() +## func [AsResourceName]() ```go func AsResourceName(name string) string @@ -26,7 +26,7 @@ func AsResourceName(name string) string AsResourceName returns a resource name with underscores to respect the kubernetes naming convention. It's the opposite of FixedResourceName. -## func [Confirm]() +## func [Confirm]() ```go func Confirm(question string, icon ...Icon) bool @@ -35,7 +35,7 @@ func Confirm(question string, icon ...Icon) bool Confirm asks a question and returns true if the answer is y. -## func [CountStartingSpaces]() +## func [CountStartingSpaces]() ```go func CountStartingSpaces(line string) int @@ -44,7 +44,7 @@ func CountStartingSpaces(line string) int CountStartingSpaces counts the number of spaces at the beginning of a string. -## func [EncodeBasicYaml]() +## func [EncodeBasicYaml]() ```go func EncodeBasicYaml(data any) ([]byte, error) @@ -53,7 +53,7 @@ func EncodeBasicYaml(data any) ([]byte, error) EncodeBasicYaml encodes a basic yaml from an interface. -## func [FixedResourceName]() +## func [FixedResourceName]() ```go func FixedResourceName(name string) string @@ -62,7 +62,7 @@ func FixedResourceName(name string) string FixedResourceName returns a resource name without underscores to respect the kubernetes naming convention. -## func [GetContainerByName]() +## func [GetContainerByName]() ```go func GetContainerByName(name string, containers []corev1.Container) (*corev1.Container, int) @@ -71,7 +71,7 @@ func GetContainerByName(name string, containers []corev1.Container) (*corev1.Con GetContainerByName returns a container by name and its index in the array. It returns nil, \-1 if not found. -## func [GetKind]() +## func [GetKind]() ```go func GetKind(path string) (kind string) @@ -80,7 +80,7 @@ func GetKind(path string) (kind string) GetKind returns the kind of the resource from the file path. -## func [GetServiceNameByPort]() +## func [GetServiceNameByPort]() ```go func GetServiceNameByPort(port int) string @@ -89,7 +89,7 @@ func GetServiceNameByPort(port int) string GetServiceNameByPort returns the service name for a port. It the service name is not found, it returns an empty string. -## func [GetValuesFromLabel]() +## func [GetValuesFromLabel]() ```go func GetValuesFromLabel(service types.ServiceConfig, LabelValues string) map[string]*EnvConfig @@ -98,7 +98,7 @@ func GetValuesFromLabel(service types.ServiceConfig, LabelValues string) map[str GetValuesFromLabel returns a map of values from a label. -## func [HashComposefiles]() +## func [HashComposefiles]() ```go func HashComposefiles(files []string) (string, error) @@ -107,7 +107,7 @@ func HashComposefiles(files []string) (string, error) HashComposefiles returns a hash of the compose files. -## func [Int32Ptr]() +## func [Int32Ptr]() ```go func Int32Ptr(i int32) *int32 @@ -116,7 +116,7 @@ func Int32Ptr(i int32) *int32 Int32Ptr returns a pointer to an int32. -## func [PathToName]() +## func [PathToName]() ```go func PathToName(path string) string @@ -125,7 +125,7 @@ func PathToName(path string) string PathToName converts a path to a kubernetes complient name. -## func [StrPtr]() +## func [StrPtr]() ```go func StrPtr(s string) *string @@ -134,7 +134,7 @@ func StrPtr(s string) *string StrPtr returns a pointer to a string. -## func [TplName]() +## func [TplName]() ```go func TplName(serviceName, appname string, suffix ...string) string @@ -143,7 +143,7 @@ func TplName(serviceName, appname string, suffix ...string) string TplName returns the name of the kubernetes resource as a template string. It is used in the templates and defined in \_helper.tpl file. -## func [TplValue]() +## func [TplValue]() ```go func TplValue(serviceName, variable string, pipes ...string) string @@ -152,7 +152,7 @@ func TplValue(serviceName, variable string, pipes ...string) string TplValue returns a string that can be used in a template to access a value from the values file. -## func [Warn]() +## func [Warn]() ```go func Warn(msg ...any) @@ -161,7 +161,7 @@ func Warn(msg ...any) Warn prints a warning message -## func [WordWrap]() +## func [WordWrap]() ```go func WordWrap(text string, lineWidth int) string @@ -170,7 +170,7 @@ func WordWrap(text string, lineWidth int) string WordWrap wraps a string to a given line width. Warning: it may break the string. You need to check the result. -## func [Wrap]() +## func [Wrap]() ```go func Wrap(src, above, below string) string @@ -179,7 +179,7 @@ func Wrap(src, above, below string) string Wrap wraps a string with a string above and below. It will respect the indentation of the src string. -## type [EnvConfig]() +## type [EnvConfig]() EnvConfig is a struct to hold the description of an environment variable. @@ -191,7 +191,7 @@ type EnvConfig struct { ``` -## type [Icon]() +## type [Icon]() Icon is a unicode icon diff --git a/doc/mkdocs.yml b/doc/mkdocs.yml index 9e8a66c..b785fd5 100644 --- a/doc/mkdocs.yml +++ b/doc/mkdocs.yml @@ -4,7 +4,7 @@ plugins: - search - inline-svg - manpage: - enabled: !ENV [MANPAGE, false] + enabled: true preprocess: preprocess.py pages: - title: Katenary diff --git a/doc/share/man/man1/katenary.1 b/doc/share/man/man1/katenary.1 new file mode 100644 index 0000000..03ffd91 --- /dev/null +++ b/doc/share/man/man1/katenary.1 @@ -0,0 +1,796 @@ +'\" t +.\" Automatically generated by Pandoc 3.1.11.1 +.\" +.TH "Katenary" "1" "2025-08-21" "mkdocs-manpage v2.0.1" "Katenary helm chart generator" +.SH Basic Usage +Basically, you can use \f[CR]katenary\f[R] to transpose a docker\-compose file (or any compose file compatible with \f[CR]podman\-compose\f[R] and \f[CR]docker\-compose\f[R]) to a configurable Helm Chart. +This resulting helm chart can be installed with \f[CR]helm\f[R] command to your Kubernetes cluster. +.PP +For very basic compose files, without any specific configuration, Katenary will create a working helm chart using the simple command line: +.IP +.EX +katenary convert +.EE +.PP +This will create a \f[CR]chart\f[R] directory with the helm chart inside. +.PP +But, in general, you will need to add a few configurations to help Katenary to transpose the compose file to a working helm chart. +.PP +There are two ways to configure Katenary: +.IP \[bu] 2 +Using the compose files, adding labels to the services +.IP \[bu] 2 +Using a specific file named \f[CR]katenary.yaml\f[R] +.PP +The Katenary file \f[CR]katenary.yaml\f[R] has benefits over the labels in the compose file: +.IP \[bu] 2 +you can validate the configuration with a schema, and use completion in your editor +.IP \[bu] 2 +you separate the configuration and leave the compose file \[dq]intact\[dq] +.IP \[bu] 2 +the syntax is a bit simpler, instead of using \f[CR]katenary.v3/xxx: |\-\f[R] you can use \f[CR]xxx: ...\f[R] +.PP +But: \f[B]this implies that you have to maintain two files if the compose file changes.\f[R] +.PP +For example. +With \[dq]labels\[dq], you should do: +.IP +.EX +# in compose file +services: + webapp: + image: php:7\-apache + ports: + \- 8080:80 + environment: + DB_HOST: database + labels: + katenary.v3/ingress: |\- + hostname: myapp.example.com + port: 8080 + katenary.v3/map\-env: |\- + DB_HOST: \[dq]{{ .Release.Name }}\-database\[dq] +.EE +.PP +Using a Katenary file, you can do: +.IP +.EX +# in compose file, no need to add labels +services: + webapp: + image: php:7\-apache + ports: + \- 8080:80 + environment: + DB_HOST: database + +# in katenary.yaml +webapp: + ingress: + hostname: myapp.example.com + port: 8080 + + map\-env: + DB_HOST: \[dq]{{ .Release.Name }}\-database\[dq] +.EE +.PP +YAML in multiline label +.PP +Compose only accept text label. +So, to put a complete YAML content in the target label, you need to use a pipe char (\f[CR]|\f[R] or \f[CR]|\-\f[R]) and to \f[B]indent\f[R] your content. +.PP +For example : +.IP +.EX + labels: + # your labels + foo: bar + # katenary labels with multiline + katenary.v3/ingress: |\- + hostname: my.website.tld + port: 80 + katenary.v3/ports: |\- + \- 1234 +.EE +.PP +Katenary transforms compose services this way: +.IP \[bu] 2 +Takes the service and create a \[dq]Deployment\[dq] file +.IP \[bu] 2 +if a port is declared, Katenary creates a service (\f[CR]ClusterIP\f[R]) +.IP \[bu] 2 +if a port is exposed, Katenary creates a service (\f[CR]NodePort\f[R]) +.IP \[bu] 2 +environment variables will be stored inside a \f[CR]ConfigMap\f[R] +.IP \[bu] 2 +image, tags, and ingresses configuration are also stored in \f[CR]values.yaml\f[R] file +.IP \[bu] 2 +if named volumes are declared, Katenary create \f[CR]PersistentVolumeClaims\f[R] \- not enabled in values file +.IP \[bu] 2 +\f[CR]depends_on\f[R] needs that the pointed service declared a port. +If not, you can use labels to inform Katenary +.PP +For any other specific configuration, like binding local files as \f[CR]ConfigMap\f[R], bind variables, add values with documentation, etc. +You\[aq]ll need to use labels. +.PP +Katenary can also configure containers grouping in pods, declare dependencies, ignore some services, force variables as secrets, mount files as \f[CR]configMap\f[R], and many others things. +To adapt the helm chart generation, you will need to use some specific labels. +.PP +For more complete label usage, see the labels page. +.PP +Overriding file +.PP +It could be sometimes more convinient to separate the configuration related to Katenary inside a secondary file. +.PP +Instead of adding labels inside the \f[CR]compose.yaml\f[R] file, you can create a file named \f[CR]compose.katenary.yaml\f[R] and declare your labels inside. +Katenary will detect it by default. +.PP +\f[B]No need to precise the file in the command line.\f[R] +.SS Make conversion +After having installed \f[CR]katenary\f[R], the standard usage is to call: +.IP +.EX +katenary convert +.EE +.PP +It will search standard compose files in the current directory and try to create a helm chart in \[dq]chart\[dq] directory. +.PP +Info +.PP +Katenary uses the compose\-go library which respects the Docker and Docker\-Compose specification. +Keep in mind that it will find files exactly the same way as \f[CR]docker\-compose\f[R] and \f[CR]podman\-compose\f[R] do it. +.PP +Of course, you can provide others files than the default with (cumulative) \f[CR]\-c\f[R] options: +.IP +.EX +katenary convert \-c file1.yaml \-c file2.yaml +.EE +.SS Some common labels to use +Katenary proposes a lot of labels to configure the helm chart generation, but some are very important. +.PP +Info +.PP +For more complete label usage, see the labels page. +.SS Work with Depends On? +Kubernetes does not provide service or pod starting detection from others pods. +But Katenary will create \f[CR]initContainer\f[R] to make you able to wait for a service to respond. +But you\[aq]ll probably need to adapt a bit the compose file. +.PP +See this compose file: +.IP +.EX +version: \[dq]3\[dq] + +services: + webapp: + image: php:8\-apache + depends_on: + \- database + + database: + image: mariadb + environment: + MYSQL_ROOT_PASSWORD: foobar +.EE +.PP +In this case, \f[CR]webapp\f[R] needs to know the \f[CR]database\f[R] port because the \f[CR]depends_on\f[R] points on it and Kubernetes has not (yet) solution to check the database startup. +Katenary wants to create a \f[CR]initContainer\f[R] to hit on the related service. +So, instead of exposing the port in the compose definition, let\[aq]s declare this to Katenary with labels: +.IP +.EX +version: \[dq]3\[dq] + +services: + webapp: + image: php:8\-apache + depends_on: + \- database + + database: + image: mariadb + environment: + MYSQL_ROOT_PASSWORD: foobar + labels: + katenary.v3/ports: |\- + \- 3306 +.EE +.SS Declare ingresses +It\[aq]s very common to have an Ingress resource on web application to deploy on Kubernetes. +It allows exposing the service to the outside of the cluster (you need to install an ingress controller). +.PP +Katenary can create this resource for you. +You just need to declare the hostname and the port to bind. +.IP +.EX +services: + webapp: + image: ... + ports: 8080:5050 + labels: + katenary.v3/ingress: |\- + # the target port is 5050 wich is the \[dq]service\[dq] port + port: 5050 + hostname: myapp.example.com +.EE +.PP +Note that the port to bind is the one used by the container, not the used locally. +This is because Katenary create a service to bind the container itself. +.SS Map environment to helm values +A lot of framework needs to receive service host or IP in an environment variable to configure the connection. +For example, to connect a PHP application to a database. +.PP +With a compose file, there is no problem as Docker/Podman allows resolving the name by container name: +.IP +.EX +services: + webapp: + image: php:7\-apache + environment: + DB_HOST: database + + database: + image: mariadb +.EE +.PP +Katenary prefixes the services with \f[CR]{{ .Release.Name }}\f[R] (to make it possible to install the application several times in a namespace), so you need to \[dq]remap\[dq] the environment variable to the right one. +.IP +.EX +services: + webapp: + image: php:7\-apache + environment: + DB_HOST: database + labels: + katenary.v3/mapenv: |\- + DB_HOST: \[dq]{{ .Release.Name }}\-database\[dq] + + database: + image: mariadb +.EE +.PP +This label can be used to map others environment for any others reason. +E.g. +to change an informational environment variable. +.IP +.EX +services: + webapp: + #... + environment: + RUNNING: docker + labels: + katenary.v3/mapenv: |\- + RUNNING: kubernetes +.EE +.PP +In the above example, \f[CR]RUNNING\f[R] will be set to \f[CR]kubernetes\f[R] when you\[aq]ll deploy the application with helm, and it\[aq]s \f[CR]docker\f[R] for \[dq]Podman\[dq] and \[dq]Docker\[dq] executions. +.SH Labels documentation +Katenary proposes labels to set in \f[CR]compose.yaml\f[R] files (or override files) to configure the Helm Chart generation. +Because it is sometimes needed to have structured values, it is necessary to use the YAML syntax. +While compose labels are string, we can use \f[I]here\-doc\f[R] syntax using \f[CR]|\f[R] to use YAML multiline as value. +.IP +.EX +label\-name: |\- + # this is actually a multiline string here + key1: value1 + key2: value2 +.EE +.PP +Katenary will try to \f[I]Unmarshal\f[R] these labels. +.SS Label list and types +.PP +.TS +tab(@); +l l l. +T{ +Label name +T}@T{ +Description +T}@T{ +Type +T} +_ +T{ +\f[CR]katenary.v3/configmap\-files\f[R] +T}@T{ +Inject files as Configmap. +T}@T{ +\f[CR][]string\f[R] +T} +T{ +\f[CR]katenary.v3/cronjob\f[R] +T}@T{ +Create a cronjob from the service. +T}@T{ +\f[CR]object\f[R] +T} +T{ +\f[CR]katenary.v3/dependencies\f[R] +T}@T{ +Add Helm dependencies to the service. +T}@T{ +\f[CR][]object\f[R] +T} +T{ +\f[CR]katenary.v3/description\f[R] +T}@T{ +Description of the service +T}@T{ +\f[CR]string\f[R] +T} +T{ +\f[CR]katenary.v3/env\-from\f[R] +T}@T{ +Add environment variables from another service. +T}@T{ +\f[CR][]string\f[R] +T} +T{ +\f[CR]katenary.v3/exchange\-volumes\f[R] +T}@T{ +Add exchange volumes (empty directory on the node) to share data +T}@T{ +\f[CR][]object\f[R] +T} +T{ +\f[CR]katenary.v3/health\-check\f[R] +T}@T{ +Health check to be added to the deployment. +T}@T{ +\f[CR]object\f[R] +T} +T{ +\f[CR]katenary.v3/ignore\f[R] +T}@T{ +Ignore the service +T}@T{ +\f[CR]bool\f[R] +T} +T{ +\f[CR]katenary.v3/ingress\f[R] +T}@T{ +Ingress rules to be added to the service. +T}@T{ +\f[CR]object\f[R] +T} +T{ +\f[CR]katenary.v3/main\-app\f[R] +T}@T{ +Mark the service as the main app. +T}@T{ +\f[CR]bool\f[R] +T} +T{ +\f[CR]katenary.v3/map\-env\f[R] +T}@T{ +Map env vars from the service to the deployment. +T}@T{ +\f[CR]map[string]string\f[R] +T} +T{ +\f[CR]katenary.v3/ports\f[R] +T}@T{ +Ports to be added to the service. +T}@T{ +\f[CR][]uint32\f[R] +T} +T{ +\f[CR]katenary.v3/same\-pod\f[R] +T}@T{ +Move the same\-pod deployment to the target deployment. +T}@T{ +\f[CR]string\f[R] +T} +T{ +\f[CR]katenary.v3/secrets\f[R] +T}@T{ +Env vars to be set as secrets. +T}@T{ +\f[CR][]string\f[R] +T} +T{ +\f[CR]katenary.v3/values\f[R] +T}@T{ +Environment variables to be added to the values.yaml +T}@T{ +\f[CR][]string or map[string]string\f[R] +T} +T{ +\f[CR]katenary.v3/values\-from\f[R] +T}@T{ +Add values from another service. +T}@T{ +\f[CR]map[string]string\f[R] +T} +.TE +.SS Detailed description +.SS katenary.v3/configmap\-files +Inject files as Configmap. +.PP +\f[B]Type\f[R]: \f[CR][]string\f[R] +.PP +It makes a file or directory to be converted to one or more ConfigMaps and mounted in the pod. +The file or directory is relative to the service directory. +.PP +If it is a directory, all files inside it are added to the ConfigMap. +.PP +If the directory as subdirectories, so one configmap per subpath are created. +.PP +Warning +.PP +It is not intended to be used to store an entire project in configmaps. +It is intended to be used to store configuration files that are not managed by the application, like nginx configuration files. +Keep in mind that your project sources should be stored in an application image or in a storage. +.PP +\f[B]Example:\f[R] +.IP +.EX +volumes + \- ./conf.d:/etc/nginx/conf.d +labels: + katenary.v3/configmap\-files: |\- + \- ./conf.d +.EE +.SS katenary.v3/cronjob +Create a cronjob from the service. +.PP +\f[B]Type\f[R]: \f[CR]object\f[R] +.PP +This adds a cronjob to the chart. +.PP +The label value is a YAML object with the following attributes: \- command: the command to be executed \- schedule: the cron schedule (cron format or \[at]every where \[dq]every\[dq] is a duration like 1h30m, daily, hourly...) +\- rbac: false (optionnal), if true, it will create a role, a rolebinding and a serviceaccount to make your cronjob able to connect the Kubernetes API +.PP +\f[B]Example:\f[R] +.IP +.EX +labels: + katenary.v3/cronjob: |\- + command: echo \[dq]hello world\[dq] + schedule: \[dq]* */1 * * *\[dq] # or \[at]hourly for example +.EE +.SS katenary.v3/dependencies +Add Helm dependencies to the service. +.PP +\f[B]Type\f[R]: \f[CR][]object\f[R] +.PP +Set the service to be, actually, a Helm dependency. +This means that the service will not be exported as template. +The dependencies are added to the Chart.yaml file and the values are added to the values.yaml file. +.PP +It\[aq]s a list of objects with the following attributes: +.IP \[bu] 2 +name: the name of the dependency +.IP \[bu] 2 +repository: the repository of the dependency +.IP \[bu] 2 +alias: the name of the dependency in values.yaml (optional) +.IP \[bu] 2 +values: the values to be set in values.yaml (optional) +.PP +Info +.PP +Katenary doesn\[aq]t update the helm depenedencies by default. +.PP +Use \f[CR]\-\-helm\-update\f[R] (or \f[CR]\-u\f[R]) flag to update the dependencies. +.PP +example: \f[CR]katenary convert \-u\f[R] +.PP +By setting an alias, it is possible to change the name of the dependency in values.yaml. +.PP +\f[B]Example:\f[R] +.IP +.EX +labels: + katenary.v3/dependencies: |\- + \- name: mariadb + repository: oci://registry\-1.docker.io/bitnamicharts + + ## optional, it changes the name of the section in values.yaml + # alias: mydatabase + + ## optional, it adds the values to values.yaml + values: + auth: + database: mydatabasename + username: myuser + password: the secret password +.EE +.SS katenary.v3/description +Description of the service +.PP +\f[B]Type\f[R]: \f[CR]string\f[R] +.PP +This replaces the default comment in values.yaml file to the given description. +It is useful to document the service and configuration. +.PP +The value can be set with a documentation in multiline format. +.PP +\f[B]Example:\f[R] +.IP +.EX +labels: + katenary.v3/description: |\- + This is a description of the service. + It can be multiline. +.EE +.SS katenary.v3/env\-from +Add environment variables from another service. +.PP +\f[B]Type\f[R]: \f[CR][]string\f[R] +.PP +It adds environment variables from another service to the current service. +.PP +\f[B]Example:\f[R] +.IP +.EX +service1: + image: nginx:1.19 + environment: + FOO: bar + +service2: + image: php:7.4\-fpm + labels: + # get the congigMap from service1 where FOO is + # defined inside this service too + katenary.v3/env\-from: |\- + \- myservice1 +.EE +.SS katenary.v3/exchange\-volumes +Add exchange volumes (empty directory on the node) to share data +.PP +\f[B]Type\f[R]: \f[CR][]object\f[R] +.PP +This label allows sharing data between containres. +The volume is created in the node and mounted in the pod. +It is useful to share data between containers in a \[dq]same pod\[dq] logic. +For example to let PHP\-FPM and Nginx share the same direcotory. +.PP +This will create: +.IP \[bu] 2 +an \f[CR]emptyDir\f[R] volume in the deployment +.IP \[bu] 2 +a \f[CR]voumeMount\f[R] in the pod for \f[B]each container\f[R] +.IP \[bu] 2 +a \f[CR]initContainer\f[R] for each definition +.PP +Fields: \- name: the name of the volume (manadatory) \- mountPath: the path where the volume is mounted in the pod (optional, default is \f[CR]/opt\f[R]) \- init: a command to run to initialize the volume with data (optional) +.PP +Warning +.PP +This is highly experimental. +This is mainly useful when using the \[dq]same\-pod\[dq] label. +.PP +\f[B]Example:\f[R] +.IP +.EX +nginx: + # ... + labels; + katenary.v3/exchange\-volumes: |\- + \- name: php\-fpm + mountPath: /var/www/html +php: + # ... + labels: + katenary.v3/exchange\-volumes: |\- + \- name: php\-fpm + mountPath: /opt + init: cp \-ra /var/www/html/* /opt +.EE +.SS katenary.v3/health\-check +Health check to be added to the deployment. +.PP +\f[B]Type\f[R]: \f[CR]object\f[R] +.PP +Health check to be added to the deployment. +.PP +\f[B]Example:\f[R] +.IP +.EX +labels: + katenary.v3/health\-check: |\- + livenessProbe: + httpGet: + path: /health + port: 8080 +.EE +.SS katenary.v3/ignore +Ignore the service +.PP +\f[B]Type\f[R]: \f[CR]bool\f[R] +.PP +Ingoring a service to not be exported in helm chart. +.PP +\f[B]Example:\f[R] +.IP +.EX +labels: + katenary.v3/ignore: \[dq]true\[dq] +.EE +.SS katenary.v3/ingress +Ingress rules to be added to the service. +.PP +\f[B]Type\f[R]: \f[CR]object\f[R] +.PP +Declare an ingress rule for the service. +The port should be exposed or declared with \f[CR]katenary.v3/ports\f[R]. +.PP +\f[B]Example:\f[R] +.IP +.EX +labels: + katenary.v3/ingress: |\- + port: 80 + hostname: mywebsite.com (optional) +.EE +.SS katenary.v3/main\-app +Mark the service as the main app. +.PP +\f[B]Type\f[R]: \f[CR]bool\f[R] +.PP +This makes the service to be the main application. +Its image tag is considered to be the Chart appVersion and to be the defaultvalue in Pod container image attribute. +.PP +Warning +.PP +This label cannot be repeated in others services. +If this label is set in more than one service as true, Katenary will return an error. +.PP +\f[B]Example:\f[R] +.IP +.EX +ghost: + image: ghost:1.25.5 + labels: + # The chart is now named ghost, and the appVersion is 1.25.5. + # In Deployment, the image attribute is set to ghost:1.25.5 if + # you don\[aq]t change the \[dq]tag\[dq] attribute in values.yaml + katenary.v3/main\-app: true +.EE +.SS katenary.v3/map\-env +Map env vars from the service to the deployment. +.PP +\f[B]Type\f[R]: \f[CR]map[string]string\f[R] +.PP +Because you may need to change the variable for Kubernetes, this label forces the value to another. +It is also particullary helpful to use a template value instead. +For example, you could bind the value to a service name with Helm attributes: \f[CR]{{ tpl .Release.Name . }}\f[R]. +.PP +If you use \f[CR]__APP__\f[R] in the value, it will be replaced by the Chart name. +.PP +\f[B]Example:\f[R] +.IP +.EX +env: + DB_HOST: database + RUNNING: docker + OTHER: value +labels: + katenary.v3/map\-env: |\- + RUNNING: kubernetes + DB_HOST: \[aq]{{ include \[dq]__APP__.fullname\[dq] . }}\-database\[aq] +.EE +.SS katenary.v3/ports +Ports to be added to the service. +.PP +\f[B]Type\f[R]: \f[CR][]uint32\f[R] +.PP +Only useful for services without exposed port. +It is mandatory if the service is a dependency of another service. +.PP +\f[B]Example:\f[R] +.IP +.EX +labels: + katenary.v3/ports: |\- + \- 8080 + \- 8081 +.EE +.SS katenary.v3/same\-pod +Move the same\-pod deployment to the target deployment. +.PP +\f[B]Type\f[R]: \f[CR]string\f[R] +.PP +This will make the service to be included in another service pod. +Some services must work together in the same pod, like a sidecar or a proxy or nginx + php\-fpm. +.PP +Note that volume and VolumeMount are copied from the source to the target deployment. +.PP +\f[B]Example:\f[R] +.IP +.EX +web: + image: nginx:1.19 + +php: + image: php:7.4\-fpm + labels: + katenary.v3/same\-pod: web +.EE +.SS katenary.v3/secrets +Env vars to be set as secrets. +.PP +\f[B]Type\f[R]: \f[CR][]string\f[R] +.PP +This label allows setting the environment variables as secrets. +The variable is removed from the environment and added to a secret object. +.PP +The variable can be set to the \f[CR]katenary.v3/values\f[R] too, so the secret value can be configured in values.yaml +.PP +\f[B]Example:\f[R] +.IP +.EX +env: + PASSWORD: a very secret password + NOT_A_SECRET: a public value +labels: + katenary.v3/secrets: |\- + \- PASSWORD +.EE +.SS katenary.v3/values +Environment variables to be added to the values.yaml +.PP +\f[B]Type\f[R]: \f[CR][]string or map[string]string\f[R] +.PP +By default, all environment variables in the \[dq]env\[dq] and environment files are added to configmaps with the static values set. +This label allows adding environment variables to the values.yaml file. +.PP +Note that the value inside the configmap is \f[CR]{{ tpl vaname . }}\f[R], so you can set the value to a template that will be rendered with the values.yaml file. +.PP +The value can be set with a documentation. +This may help to understand the purpose of the variable. +.PP +\f[B]Example:\f[R] +.IP +.EX +env: + FOO: bar + DB_NAME: mydb + TO_CONFIGURE: something that can be changed in values.yaml + A_COMPLEX_VALUE: example +labels: + katenary.v3/values: |\- + # simple values, set as is in values.yaml + \- TO_CONFIGURE + # complex values, set as a template in values.yaml with a documentation + \- A_COMPLEX_VALUE: |\- + This is the documentation for the variable to + configure in values.yaml. + It can be, of course, a multiline text. +.EE +.SS katenary.v3/values\-from +Add values from another service. +.PP +\f[B]Type\f[R]: \f[CR]map[string]string\f[R] +.PP +This label allows adding values from another service to the current service. +It avoid duplicating values, environment or secrets that should be the same. +.PP +The key is the value to be added, and the value is the \[dq]key\[dq] to fetch in the form \f[CR]service_name.environment_name\f[R]. +.PP +\f[B]Example:\f[R] +.IP +.EX +database: + image: mariadb:10.5 + environment: + MARIADB_USER: myuser + MARIADB_PASSWORD: mypassword + labels: + # we can declare secrets + katenary.v3/secrets: |\- + \- MARIADB_PASSWORD +php: + image: php:7.4\-fpm + environment: + # it\[aq]s duplicated in docker / podman + DB_USER: myuser + DB_PASSWORD: mypassword + labels: + # removes the duplicated, use the configMap and secrets from \[dq]database\[dq] + katenary.v3/values\-from: |\- + DB_USER: database.MARIADB_USER + DB_PASSWORD: database.MARIADB_PASSWORD +.EE diff --git a/makefiles/build.mk b/makefiles/build.mk index 4aac20f..68da02b 100644 --- a/makefiles/build.mk +++ b/makefiles/build.mk @@ -23,7 +23,7 @@ endif # Also generate the windows installer. binaries: prepare $(BINARIES) dist: binaries upx packages -dist-full: clean-dist dist gpg-sign check-sign rpm-sign check-dist-all +dist-full: clean-dist dist check-dist-all prepare: pull packager-oci-image mkdir -p dist diff --git a/makefiles/packager.mk b/makefiles/packager.mk index 155e6f6..dc35d7f 100644 --- a/makefiles/packager.mk +++ b/makefiles/packager.mk @@ -1,5 +1,6 @@ ## Linux / FreeBSD packages with fpm +PACKAGE_API=https://repo.katenary.io/api/packages/katenary DESCRIPTION := $(shell cat oci/description | sed ':a;N;$$!ba;s/\n/\\n/g') FPM_OPTS=--name katenary \ @@ -16,7 +17,7 @@ FPM_BASES=../LICENSE=/usr/local/share/doc/katenary/LICENSE \ 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 \ +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//') @@ -35,6 +36,8 @@ rpm: dist/katenary-linux-$(GOARCH) fpm -s dir -t rpm -a $(GOARCH) -f $(FPM_OPTS) --version=$(VERSION) \ $(FPM_COMMON_FILES) \ ./katenary-linux-$(GOARCH)=/usr/local/bin/katenary + +# could be now removed, as gitea sign packages for us rpm-sign: [ -f .rpmmacros ] || echo "$(RPM_MACROS)" > .rpmmacros [ -f .secret.gpg ] || gpg --export-secret-keys -a $(SIGNER) > .secret.gpg @@ -136,3 +139,30 @@ check-dist-all: $(MAKE) check-dist-debian $(MAKE) check-dist-ubuntu $(MAKE) check-dist-archlinux + +push-packages: rpm deb pacman + source .gitea.env + for file in $$(find dist -type f -name "*.rpm"); do \ + curl --user $$GITEA_USERNAME:$$GITEA_TOKEN \ + --upload-file $$file \ + $(PACKAGE_API)/rpm/upload + done + for file in $$(find dist -type f -name "*.deb"); do \ + curl --user $$GITEA_USERNAME:$$GITEA_TOKEN \ + --upload-file $$file \ + $(PACKAGE_API)/debian/pool/any/main/upload + done + for file in $$(find dist -type f -name "*.tar.zst"); do \ + curl --user $$GITEA_USERNAME:$$GITEA_TOKEN \ + --upload-file $$file \ + $(PACKAGE_API)/arch/core + done + +push-generic-packages: $(BINARIES) + @source .gitea.env + for bin in $^; do \ + echo "pushing $$bin to Gitea..."; \ + curl --user $$GITEA_USERNAME:$$GITEA_TOKEN \ + --upload-file $$bin \ + $(PACKAGE_API)/generic/katenary/$(VERSION)/$$(basename $$bin); + done diff --git a/oci/katenary/Containerfile b/oci/katenary/Containerfile index 56fc3da..aab0e13 100644 --- a/oci/katenary/Containerfile +++ b/oci/katenary/Containerfile @@ -1,4 +1,4 @@ -ARG GOVERSION=1.24 +ARG GOVERSION=1.25 FROM docker.io/golang:${GOVERSION} AS builder ARG VERSION