From 8a351b00d62317576ff074425ca529204455ff7c Mon Sep 17 00:00:00 2001 From: Guy Godfroy Date: Sun, 7 Jul 2024 21:37:31 +0000 Subject: [PATCH] testing/tofutf: new aport --- testing/tofutf/APKBUILD | 103 ++++++++++++++++++++++ testing/tofutf/check_otf.patch | 35 ++++++++ testing/tofutf/tofutf-agent.confd | 12 +++ testing/tofutf/tofutf-agent.initd | 21 +++++ testing/tofutf/tofutf-agent.pre-install | 8 ++ testing/tofutf/tofutf-server.post-install | 7 ++ testing/tofutf/tofutf-server.pre-install | 8 ++ testing/tofutf/tofutfd.confd | 12 +++ testing/tofutf/tofutfd.initd | 21 +++++ 9 files changed, 227 insertions(+) create mode 100644 testing/tofutf/APKBUILD create mode 100644 testing/tofutf/check_otf.patch create mode 100644 testing/tofutf/tofutf-agent.confd create mode 100644 testing/tofutf/tofutf-agent.initd create mode 100644 testing/tofutf/tofutf-agent.pre-install create mode 100644 testing/tofutf/tofutf-server.post-install create mode 100644 testing/tofutf/tofutf-server.pre-install create mode 100644 testing/tofutf/tofutfd.confd create mode 100644 testing/tofutf/tofutfd.initd diff --git a/testing/tofutf/APKBUILD b/testing/tofutf/APKBUILD new file mode 100644 index 00000000000..6de38465b46 --- /dev/null +++ b/testing/tofutf/APKBUILD @@ -0,0 +1,103 @@ +# Contributor: Guy Godfroy +# Maintainer: Guy Godfroy +pkgname=tofutf +pkgver=0.9.1 +pkgrel=0 +pkgdesc="Open source alternative to Terraform Enterprise" +url="https://docs.tofutf.io" +arch="all" +license="MPL-2.0" +depends="tofutf-server tofutf-cli" +makedepends="go" +subpackages=" + $pkgname-cli + $pkgname-server + $pkgname-server-openrc:server_openrc + $pkgname-agent + $pkgname-agent-openrc:agent_openrc + " +source="$pkgname-$pkgver.tar.gz::https://github.com/tofutf/tofutf/archive/refs/tags/v$pkgver.tar.gz + check_otf.patch + tofutfd.initd + tofutfd.confd + tofutf-agent.initd + tofutf-agent.confd + " +options="net" + +build() { + mkdir build + export LD_FLAGS="-s -w -X github.com/tofutf/tofutf/internal.Version=$pkgver" + go build -ldflags="$LD_FLAGS" -o build ./... +} + +check() { + # TestExecutor_execute: takes ages and then timeout + # internal/integration: this module tests need docker + # TestDownloader: lacks testdata for some architectures https://github.com/tofutf/tofutf/pull/241 + toskip="TestExecutor_execute" + if [ "$CARCH" != "x86_64" ] && [ "$CARCH" != "aarch64" ] + then + toskip="${toskip}|TestDownloader" + fi + go test -skip "$toskip" $(go list ./... | grep -v internal/integration) +} + +package() { + # Main package is only a metapackage depending of server and cli component. + # This is because main component should be server, but the binary named "tofutf" is the cli tool. + # So to avoid confusion, all components are subpackaged. + mkdir -p "$pkgdir" +} + +cli() { + unset depends + pkgdesc="Command line tool for tofutf" + install -m755 -D "$builddir"/build/tofutf \ + "$subpkgdir"/usr/bin/tofutf +} + +server() { + depends="xxd" + pkgdesc="Server component for tofufs" + install="tofutf-server.pre-install tofutf-server.post-install" + install -m755 -D "$builddir"/build/tofutfd \ + "$subpkgdir"/usr/bin/tofutfd +} + +server_openrc() { + unset depends + pkgdesc="Server component for tofufs (OpenRC init scripts)" + install_if="$pkgname-server=$pkgver-r$pkgrel openrc" + install -m755 -D "$srcdir"/tofutfd.initd \ + "$subpkgdir"/etc/init.d/tofutfd + install -m644 -D "$srcdir"/tofutfd.confd \ + "$subpkgdir"/etc/conf.d/tofutfd +} + +agent() { + unset depends + pkgdesc="Agent for tofutf" + install="tofutf-agent.pre-install" + install -m755 -D "$builddir"/build/tofutf-agent \ + "$subpkgdir"/usr/bin/tofutf-agent +} + +agent_openrc() { + unset depends + install_if="$pkgname-agent=$pkgver-r$pkgrel openrc" + pkgdesc="Agent for tofutf (OpenRC init scripts)" + install -m755 -D "$srcdir"/tofutf-agent.initd \ + "$subpkgdir"/etc/init.d/tofutf-agent + install -m644 -D "$srcdir"/tofutf-agent.confd \ + "$subpkgdir"/etc/conf.d/tofutf-agent +} + +sha512sums=" +d03d72a8ba63c30b0e14c404761722fc4bec86ba1dda2342f5721f392d3da68e676ad19c6d991a0375fe586c151fa3bdd5b421b408b5bb41ccbaee41e99f0f25 tofutf-0.9.1.tar.gz +9d075813376e129ccd3af97659c21a167c93feaa5418be0bfef05771294faf46a006bf80b2324f31a3353d7b0b2993ebeea423f56f28954021665adb5987994c check_otf.patch +267f21cb6aa0879132b994ff0a965b97cd426bf624b44b7e960cbfa2438405f3cd46f29cc6d76781ffe85705e828cc408dd67655125b696588041f822f30d71d tofutfd.initd +f917e6078a21adec9a16923490c9b90e4ab03da59d488c11e29319ded8dccb5904be50c0c04563aa8268bc82c9d4bf50d579436f936b07f9010a17e8e9a4de99 tofutfd.confd +ae25de3409bc5e4ef8abb18eb2b2c56fc15ed57b272a2585e43e415e4a731c207c1c8349854a314ea0f5c2a9957d114ae6051d58de010cceb0b75ba67832912d tofutf-agent.initd +7cb1869a722be8de24089d4fd368620efe4dc1768a141f842303077437f6cb96eec8d466a4feaa6a5bb220e6158fb55e7bc7ae260857dd42d6a1bbdd81e93f86 tofutf-agent.confd +" diff --git a/testing/tofutf/check_otf.patch b/testing/tofutf/check_otf.patch new file mode 100644 index 00000000000..1188dda3fe2 --- /dev/null +++ b/testing/tofutf/check_otf.patch @@ -0,0 +1,35 @@ +diff --git a/cmd/environment_variables_test.go b/cmd/environment_variables_test.go +index db0fddd..70750c9 100644 +--- a/cmd/environment_variables_test.go ++++ b/cmd/environment_variables_test.go +@@ -20,7 +20,7 @@ func TestSetFlagsFromEnvVariables(t *testing.T) { + t.Run("override flag with env var file", func(t *testing.T) { + fs := pflag.NewFlagSet("testing", pflag.ContinueOnError) + got := fs.String("foo", "default", "") +- t.Setenv("OTF_FOO_FILE", "./testdata/otf_foo_file") ++ t.Setenv("OTF_FOO_FILE", "./testdata/tofutf_foo_file") + require.NoError(t, SetFlagsFromEnvVariables(fs)) + require.NoError(t, fs.Parse(nil)) + assert.Equal(t, "big\nmultiline\nsecret\n", *got) +@@ -28,7 +28,7 @@ func TestSetFlagsFromEnvVariables(t *testing.T) { + t.Run("ignore env var for flag ending with _file", func(t *testing.T) { + fs := pflag.NewFlagSet("testing", pflag.ContinueOnError) + got := fs.String("foo_file", "default", "") +- t.Setenv("OTF_FOO_FILE_FILE", "./testdata/otf_foo_file") ++ t.Setenv("OTF_FOO_FILE_FILE", "./testdata/tofutf_foo_file") + require.NoError(t, SetFlagsFromEnvVariables(fs)) + require.NoError(t, fs.Parse(nil)) + assert.Equal(t, "default", *got) +diff --git a/cmd/tofutfd/main_test.go b/cmd/tofutfd/main_test.go +index 3f52155..b2e952d 100644 +--- a/cmd/tofutfd/main_test.go ++++ b/cmd/tofutfd/main_test.go +@@ -48,7 +48,7 @@ func TestHelp(t *testing.T) { + err := parseFlags(ctx, tt.args, got) + require.NoError(t, err) + +- assert.Regexp(t, `^otfd is the daemon component of the open terraforming framework.`, got.String()) ++ assert.Regexp(t, `^tofutfd is the daemon component of the opentofu tuft framework.`, got.String()) + }) + } + } diff --git a/testing/tofutf/tofutf-agent.confd b/testing/tofutf/tofutf-agent.confd new file mode 100644 index 00000000000..0972a6227b5 --- /dev/null +++ b/testing/tofutf/tofutf-agent.confd @@ -0,0 +1,12 @@ +# Configuration for /etc/init.d/tofutf-agent + +# User (and group) to run tofutf-agent as. +#command_user="tofutf:tofutf" + +# Additional arguments for tofutfd daemon. +#command_args="" + +token_file="/var/lib/tofutf/token" + +# Comment out to disable process supervisor. +supervisor=supervise-daemon diff --git a/testing/tofutf/tofutf-agent.initd b/testing/tofutf/tofutf-agent.initd new file mode 100644 index 00000000000..37f0e4e85f2 --- /dev/null +++ b/testing/tofutf/tofutf-agent.initd @@ -0,0 +1,21 @@ +#!/sbin/openrc-run + +name="tofutf agent" + +: ${command_user:="tofutf:tofutf"} + +command="/usr/bin/tofutf-agent" +command_args="--token $(cat $token_file) $command_args" +command_background="yes" +error_log="/var/log/tofutf-agent.log" +pidfile="/run/$RC_SVCNAME.pid" + +depend() { + need net + after firewall +} + +start_pre() { + checkpath -f --owner "$command_user" --mode 0644 \ + $error_log +} diff --git a/testing/tofutf/tofutf-agent.pre-install b/testing/tofutf/tofutf-agent.pre-install new file mode 100644 index 00000000000..b3359f291be --- /dev/null +++ b/testing/tofutf/tofutf-agent.pre-install @@ -0,0 +1,8 @@ +#!/bin/sh + +addgroup -S tofutf 2>/dev/null +adduser -S -D -H -h /var/lib/tofutf -s /sbin/nologin \ + -G tofutf -g tofutf tofutf 2>/dev/null + +exit 0 + diff --git a/testing/tofutf/tofutf-server.post-install b/testing/tofutf/tofutf-server.post-install new file mode 100644 index 00000000000..a33ddf39515 --- /dev/null +++ b/testing/tofutf/tofutf-server.post-install @@ -0,0 +1,7 @@ +#!/bin/sh + +secretfile=/var/lib/tofutf/secret + +! [ -f $secretfile ] && xxd -u -l 16 -p /dev/urandom > $secretfile +chown tofutf:tofutf $secretfile +chmod 600 $secretfile diff --git a/testing/tofutf/tofutf-server.pre-install b/testing/tofutf/tofutf-server.pre-install new file mode 100644 index 00000000000..0da434b7487 --- /dev/null +++ b/testing/tofutf/tofutf-server.pre-install @@ -0,0 +1,8 @@ +#!/bin/sh + +addgroup -S tofutf 2>/dev/null +adduser -S -D -h /var/lib/tofutf -s /sbin/nologin \ + -G tofutf -g tofutf tofutf 2>/dev/null + +exit 0 + diff --git a/testing/tofutf/tofutfd.confd b/testing/tofutf/tofutfd.confd new file mode 100644 index 00000000000..9363a30977b --- /dev/null +++ b/testing/tofutf/tofutfd.confd @@ -0,0 +1,12 @@ +# Configuration for /etc/init.d/tofutfd + +# User (and group) to run tofutfd as. +#command_user="tofutf:tofutf" + +# Additional arguments for tofutfd daemon. +#command_args="" + +secret_file="/var/lib/tofutf/secret" + +# Comment out to disable process supervisor. +supervisor=supervise-daemon diff --git a/testing/tofutf/tofutfd.initd b/testing/tofutf/tofutfd.initd new file mode 100644 index 00000000000..7aea55f4053 --- /dev/null +++ b/testing/tofutf/tofutfd.initd @@ -0,0 +1,21 @@ +#!/sbin/openrc-run + +name="tofutf server" + +: ${command_user:="tofutf:tofutf"} + +command="/usr/bin/tofutfd" +command_args="--secret $(cat $secret_file) $command_args" +command_background="yes" +error_log="/var/log/tofutfd.log" +pidfile="/run/$RC_SVCNAME.pid" + +depend() { + need net + after firewall +} + +start_pre() { + checkpath -f --owner "$command_user" --mode 0644 \ + $error_log +}