From 218ed71e00a0e58e2b2a4d34bb125de5e7fdd9a3 Mon Sep 17 00:00:00 2001 From: gab-arrobo Date: Thu, 31 Oct 2024 20:17:49 -0700 Subject: [PATCH] Refactor path for configuration file, opton(s) and Docker image (#129) Signed-off-by: Arrobo, Gabriel --- Dockerfile | 10 +++----- ausf.go | 5 ++-- context/ausf_context_init.go | 13 ----------- factory/config.go | 1 + service/init.go | 44 ++++++++++++++++-------------------- util/path.go | 20 ---------------- util/path_debug.go | 20 ---------------- 7 files changed, 27 insertions(+), 86 deletions(-) delete mode 100644 util/path.go delete mode 100644 util/path_debug.go diff --git a/Dockerfile b/Dockerfile index 28851c6..229aa32 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,6 @@ FROM golang:1.23.2-bookworm AS builder -LABEL maintainer="Aether SD-Core " - RUN apt-get update && \ apt-get -y install --no-install-recommends \ apt-transport-https \ @@ -27,6 +25,7 @@ RUN make all FROM alpine:3.20 AS ausf +LABEL maintainer="Aether SD-Core " LABEL description="ONF open source 5G Core Network" \ version="Stage 3" @@ -37,8 +36,5 @@ RUN if [ "$DEBUG_TOOLS" = "true" ]; then \ apk update && apk add --no-cache -U vim strace net-tools curl netcat-openbsd bind-tools; \ fi -# Set working dir -WORKDIR /free5gc/ausf/ - -# Copy executable and default certs -COPY --from=builder /go/src/ausf/bin/* . +# Copy executable +COPY --from=builder /go/src/ausf/bin/* /usr/local/bin/. diff --git a/ausf.go b/ausf.go index 4532f5c..09e9977 100644 --- a/ausf.go +++ b/ausf.go @@ -30,11 +30,12 @@ func main() { app := cli.NewApp() app.Name = "ausf" logger.AppLog.Infoln(app.Name) - app.Usage = "-free5gccfg common configuration file -ausfcfg ausf configuration file" + app.Usage = "Authentication Server Function" + app.UsageText = "ausf -cfg " app.Action = action app.Flags = AUSF.GetCliCmd() if err := app.Run(os.Args); err != nil { - logger.AppLog.Errorf("AUSF Run error: %v", err) + logger.AppLog.Fatalf("AUSF run error: %v", err) } } diff --git a/context/ausf_context_init.go b/context/ausf_context_init.go index 6b7401e..f57ec45 100644 --- a/context/ausf_context_init.go +++ b/context/ausf_context_init.go @@ -14,20 +14,9 @@ import ( "github.com/google/uuid" "github.com/omec-project/ausf/factory" "github.com/omec-project/ausf/logger" - "github.com/omec-project/ausf/util" "github.com/omec-project/openapi/models" - "github.com/omec-project/util/path_util" ) -func TestInit() { - // load config - DefaultAusfConfigPath := path_util.Free5gcPath("free5gc/config/ausfcfg.yaml") - if err := factory.InitConfigFactory(DefaultAusfConfigPath); err != nil { - panic(err) - } - Init() -} - func InitAusfContext(context *AUSFContext) { config := factory.AusfConfig logger.InitLog.Infof("ausfconfig Info: Version[%s] Description[%s]", config.Info.Version, config.Info.Description) @@ -41,8 +30,6 @@ func InitAusfContext(context *AUSFContext) { context.UriScheme = models.UriScheme(configuration.Sbi.Scheme) // default uri scheme context.RegisterIPv4 = factory.AUSF_DEFAULT_IPV4 // default localhost context.SBIPort = factory.AUSF_DEFAULT_PORT_INT // default port - context.Key = util.AusfKeyPath // default key path - context.PEM = util.AusfPemPath // default PEM path if sbi != nil { if sbi.RegisterIPv4 != "" { context.RegisterIPv4 = sbi.RegisterIPv4 diff --git a/factory/config.go b/factory/config.go index 98059da..d6f8197 100644 --- a/factory/config.go +++ b/factory/config.go @@ -22,6 +22,7 @@ type Config struct { Info *Info `yaml:"info"` Configuration *Configuration `yaml:"configuration"` Logger *logger.Logger `yaml:"logger"` + CfgLocation string } type Info struct { diff --git a/service/init.go b/service/init.go index 1313536..3b75163 100644 --- a/service/init.go +++ b/service/init.go @@ -13,6 +13,7 @@ import ( "os" "os/exec" "os/signal" + "path/filepath" "sync" "syscall" "time" @@ -24,14 +25,12 @@ import ( "github.com/omec-project/ausf/logger" "github.com/omec-project/ausf/metrics" "github.com/omec-project/ausf/ueauthentication" - "github.com/omec-project/ausf/util" grpcClient "github.com/omec-project/config5g/proto/client" protos "github.com/omec-project/config5g/proto/sdcoreConfig" "github.com/omec-project/openapi/models" nrfCache "github.com/omec-project/openapi/nrfcache" "github.com/omec-project/util/http2_util" utilLogger "github.com/omec-project/util/logger" - "github.com/omec-project/util/path_util" "github.com/urfave/cli" "go.uber.org/zap" "go.uber.org/zap/zapcore" @@ -42,7 +41,7 @@ type AUSF struct{} type ( // Config information. Config struct { - ausfcfg string + cfg string } ) @@ -50,12 +49,9 @@ var config Config var ausfCLi = []cli.Flag{ cli.StringFlag{ - Name: "free5gccfg", - Usage: "common config file", - }, - cli.StringFlag{ - Name: "ausfcfg", - Usage: "config file", + Name: "cfg", + Usage: "ausf config file", + Required: true, }, } @@ -76,18 +72,17 @@ func (*AUSF) GetCliCmd() (flags []cli.Flag) { func (ausf *AUSF) Initialize(c *cli.Context) error { config = Config{ - ausfcfg: c.String("ausfcfg"), + cfg: c.String("cfg"), } - if config.ausfcfg != "" { - if err := factory.InitConfigFactory(config.ausfcfg); err != nil { - return err - } - } else { - DefaultAusfConfigPath := path_util.Free5gcPath("free5gc/config/ausfcfg.yaml") - if err := factory.InitConfigFactory(DefaultAusfConfigPath); err != nil { - return err - } + absPath, err := filepath.Abs(config.cfg) + if err != nil { + logger.CfgLog.Errorln(err) + return err + } + + if err := factory.InitConfigFactory(absPath); err != nil { + return err } ausf.setLogLevel() @@ -96,6 +91,8 @@ func (ausf *AUSF) Initialize(c *cli.Context) error { return err } + factory.AusfConfig.CfgLocation = absPath + if os.Getenv("MANAGED_BY_CONFIG_POD") == "true" { logger.InitLog.Infoln("MANAGED_BY_CONFIG_POD is true") go manageGrpcClient(factory.AusfConfig.Configuration.WebuiUri, ausf) @@ -262,8 +259,6 @@ func (ausf *AUSF) Start() { context.Init() self := context.GetSelf() - ausfLogPath := util.AusfLogPath - addr := fmt.Sprintf("%s:%d", self.BindingIPv4, self.SBIPort) if self.EnableNrfCaching { @@ -281,7 +276,8 @@ func (ausf *AUSF) Start() { os.Exit(0) }() - server, err := http2_util.NewServer(addr, ausfLogPath, router) + sslLog := filepath.Dir(factory.AusfConfig.CfgLocation) + "/sslkey.log" + server, err := http2_util.NewServer(addr, sslLog, router) if server == nil { logger.InitLog.Errorf("initialize HTTP server failed: %v", err) return @@ -304,10 +300,10 @@ func (ausf *AUSF) Start() { } func (ausf *AUSF) Exec(c *cli.Context) error { - logger.InitLog.Debugln("args:", c.String("ausfcfg")) + logger.InitLog.Debugln("args:", c.String("cfg")) args := ausf.FilterCli(c) logger.InitLog.Debugln("filter:", args) - command := exec.Command("./ausf", args...) + command := exec.Command("ausf", args...) stdout, err := command.StdoutPipe() if err != nil { diff --git a/util/path.go b/util/path.go deleted file mode 100644 index 51daec9..0000000 --- a/util/path.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2019 free5GC.org -// -// SPDX-License-Identifier: Apache-2.0 -// - -//go:build !debug -// +build !debug - -package util - -import ( - "github.com/omec-project/util/path_util" -) - -var ( - AusfLogPath = path_util.Free5gcPath("free5gc/ausfsslkey.log") - AusfPemPath = path_util.Free5gcPath("free5gc/support/TLS/ausf.pem") - AusfKeyPath = path_util.Free5gcPath("free5gc/support/TLS/ausf.key") - DefaultAusfConfigPath = path_util.Free5gcPath("free5gc/config/ausfcfg.yaml") -) diff --git a/util/path_debug.go b/util/path_debug.go deleted file mode 100644 index a40b599..0000000 --- a/util/path_debug.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2019 free5GC.org -// -// SPDX-License-Identifier: Apache-2.0 -// - -//go:build debug -// +build debug - -package util - -import ( - "github.com/omec-project/util/path_util" -) - -var ( - AusfLogPath = path_util.Free5gcPath("free5gc/ausfsslkey.log") - AusfPemPath = path_util.Free5gcPath("free5gc/support/TLS/ausf.pem") - AusfKeyPath = path_util.Free5gcPath("free5gc/support/TLS/ausf.key") - DefaultAusfConfigPath = path_util.Free5gcPath("free5gc/config/ausfcfg.yaml") -)