From 12df07fd5dc9a869bf661219c9e12cc6805b3e0d Mon Sep 17 00:00:00 2001 From: Mustafa Kara Date: Fri, 12 Aug 2022 13:53:22 +0300 Subject: [PATCH] Support changeable configuration file location (#36) * Change docker workdir location of the ops-tool * Add command line option for configuration file. Signed-off-by: Mustafa Kara --- Makefile | 5 ++++- build/Dockerfile | 4 ++-- main.go | 6 +++++- server/server.go | 4 ++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 05841f0..8038812 100644 --- a/Makefile +++ b/Makefile @@ -82,6 +82,9 @@ GITHUB_ORG := mattermost # Most probably the name of the repo GITHUB_REPO := ${APP_NAME} +# Command line arguments of ops tool when executed +OPS_TOOL_ARGS ?= -c config/config.sample.yaml + # ==================================================================================== # Colors @@ -281,7 +284,7 @@ go-build-docker: # to build binaries under a controlled docker dedicated go cont .PHONY: go-run go-run: ## to run locally for development @$(INFO) running locally... - $(AT)$(GO) run ${GO_BUILD_OPTS} ${CONFIG_APP_CODE} || ${FAIL} + $(AT)$(GO) run ${GO_BUILD_OPTS} ${CONFIG_APP_CODE} -- ${OPS_TOOL_ARGS} || ${FAIL} @$(OK) running locally .PHONY: go-test diff --git a/build/Dockerfile b/build/Dockerfile index 1070732..93b4fe0 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -22,5 +22,5 @@ COPY --from=builder /src/dist/ops_tool-linux-amd64 /opt/ops-tool/bin/ops-tool # Run as UID for nobody USER 65534 -WORKDIR /opt/ops-tool/bin -ENTRYPOINT ["./ops-tool"] +WORKDIR /opt/ops-tool +ENTRYPOINT ["./bin/ops-tool"] diff --git a/main.go b/main.go index c7a2406..9579689 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "flag" "net/http" "os" "os/signal" @@ -13,6 +14,9 @@ import ( ) func main() { + configFilePath := flag.String("config", "config/config.yaml", "Ops-Tool Configuration File Location") + flag.Parse() + log.AttachVersion(version.Full()) signalChanel := make(chan os.Signal, 1) @@ -36,7 +40,7 @@ func main() { srv.Stop() }() - err := srv.Start(ctx) + err := srv.Start(ctx, *configFilePath) if err != nil && err != http.ErrServerClosed { panic(err) } diff --git a/server/server.go b/server/server.go index a8f5f9c..72b5d14 100644 --- a/server/server.go +++ b/server/server.go @@ -55,13 +55,13 @@ func New() *Server { return &Server{} } -func (s *Server) Start(ctx context.Context) error { +func (s *Server) Start(ctx context.Context, configPath string) error { log := log.FromContext(ctx) log.Info("Starting ops tool server...") log.Info("Loading config...") - cfg, err := config.Load("config/config.yaml") + cfg, err := config.Load(configPath) if err != nil { log.WithError(err).Error("Failed to load config") return errors.Wrap(err, "failed to load config")