Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Support changeable configuration file location (#36)
Browse files Browse the repository at this point in the history
* Change docker workdir location of the ops-tool
* Add command line option for configuration file.

Signed-off-by: Mustafa Kara <[email protected]>
  • Loading branch information
Mustafa Kara authored Aug 12, 2022
1 parent 1371ace commit 12df07f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"flag"
"net/http"
"os"
"os/signal"
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 12df07f

Please sign in to comment.