testing/tofutf: new aport

This commit is contained in:
Guy Godfroy 2024-07-07 21:37:31 +00:00 committed by Natanael Copa
parent 758812aa72
commit 8a351b00d6
9 changed files with 227 additions and 0 deletions

103
testing/tofutf/APKBUILD Normal file
View file

@ -0,0 +1,103 @@
# Contributor: Guy Godfroy <guy.godfroy@gugod.fr>
# Maintainer: Guy Godfroy <guy.godfroy@gugod.fr>
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
"

View file

@ -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())
})
}
}

View file

@ -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

View file

@ -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
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
}