From f6f1ebdd053ed208c2d20384d0ec568b170ebf23 Mon Sep 17 00:00:00 2001 From: Sebastian Parborg Date: Tue, 4 Apr 2023 12:25:47 +0200 Subject: [PATCH] Make runtime paths configurable at build time To allow more build-time configuration: - `Makefile` will now pick up `LDFLAGS` from environment variables, and - locations of configuration files can now be overridden with linker options. These are not used for regular Flamenco builds, but do allow studios to customize where configuration files are stored. Review: https://projects.blender.org/studio/flamenco/pulls/104200 --- Makefile | 2 +- internal/appinfo/xdg_paths.go | 10 +++++++++- internal/manager/config/config.go | 7 +++++-- internal/worker/config.go | 6 +++++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index e215c647..5079bf8e 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ _GIT_DESCRIPTION_OR_TAG := $(subst v${VERSION}-,,$(shell git describe --tag --di # ${GITHASH}. GITHASH := $(subst v${VERSION},$(shell git rev-parse --short HEAD),${_GIT_DESCRIPTION_OR_TAG}) -LDFLAGS := -X ${PKG}/internal/appinfo.ApplicationVersion=${VERSION} \ +LDFLAGS := ${LDFLAGS} -X ${PKG}/internal/appinfo.ApplicationVersion=${VERSION} \ -X ${PKG}/internal/appinfo.ApplicationGitHash=${GITHASH} \ -X ${PKG}/internal/appinfo.ReleaseCycle=${RELEASE_CYCLE} BUILD_FLAGS = -ldflags="${LDFLAGS}" diff --git a/internal/appinfo/xdg_paths.go b/internal/appinfo/xdg_paths.go index 114e505b..ea6095d3 100644 --- a/internal/appinfo/xdg_paths.go +++ b/internal/appinfo/xdg_paths.go @@ -10,10 +10,18 @@ import ( "github.com/adrg/xdg" ) +// customHome can be set at link time to specify the home directory for the worker. +// This can be overruled at runtime by setting the FLAMENCO_HOME enviroment variable. +// Only used in InFlamencoHome() function. +var customHome = "" + // InFlamencoHome returns the filename in the 'flamenco home' dir, and ensures // that the directory exists. func InFlamencoHome(filename string) (string, error) { - flamencoHome := os.Getenv("FLAMENCO_HOME") + flamencoHome := customHome + if envHome, ok := os.LookupEnv("FLAMENCO_HOME"); ok { + flamencoHome = envHome + } if flamencoHome == "" { return xdg.DataFile(path.Join(xdgApplicationName, filename)) } diff --git a/internal/manager/config/config.go b/internal/manager/config/config.go index ba917785..09aef57a 100644 --- a/internal/manager/config/config.go +++ b/internal/manager/config/config.go @@ -25,9 +25,12 @@ import ( shaman_config "git.blender.org/flamenco/pkg/shaman/config" ) -const ( - configFilename = "flamenco-manager.yaml" +// configFilename is used to specify where flamenco will write its config file. +// If the path is not absolute, it will use the flamenco binary location as the +// relative root path. This is not intended to be changed during runtime. +var configFilename = "flamenco-manager.yaml" +const ( latestConfigVersion = 3 // // relative to the Flamenco Server Base URL: diff --git a/internal/worker/config.go b/internal/worker/config.go index 81bc164b..fa16ab3a 100644 --- a/internal/worker/config.go +++ b/internal/worker/config.go @@ -22,7 +22,11 @@ var ( errURLWithoutHostName = errors.New("manager URL should contain a host name") ) -const ( +var ( + // config- and credentialsFilename are used to specify where flamenco will + // write its config/credentials file. If the path is not absolute, it will + // use the flamenco binary location as the relative root path. These are not + // intended to be changed during runtime. credentialsFilename = "flamenco-worker-credentials.yaml" configFilename = "flamenco-worker.yaml" )