Skip to content

Commit

Permalink
Refactor path for configuration file, opton(s) and Docker image (#129)
Browse files Browse the repository at this point in the history
Signed-off-by: Arrobo, Gabriel <gabriel.arrobo@intel.com>
  • Loading branch information
gab-arrobo authored Nov 1, 2024
1 parent d7b315d commit 218ed71
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 86 deletions.
10 changes: 3 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

FROM golang:1.23.2-bookworm AS builder

LABEL maintainer="Aether SD-Core <dev@lists.aetherproject.org>"

RUN apt-get update && \
apt-get -y install --no-install-recommends \
apt-transport-https \
Expand All @@ -27,6 +25,7 @@ RUN make all

FROM alpine:3.20 AS ausf

LABEL maintainer="Aether SD-Core <dev@lists.aetherproject.org>"
LABEL description="ONF open source 5G Core Network" \
version="Stage 3"

Expand All @@ -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/.
5 changes: 3 additions & 2 deletions ausf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ausf_config_file.conf>"
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)
}
}

Expand Down
13 changes: 0 additions & 13 deletions context/ausf_context_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
44 changes: 20 additions & 24 deletions service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"os/exec"
"os/signal"
"path/filepath"
"sync"
"syscall"
"time"
Expand All @@ -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"
Expand All @@ -42,20 +41,17 @@ type AUSF struct{}
type (
// Config information.
Config struct {
ausfcfg string
cfg string
}
)

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

Expand All @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand Down
20 changes: 0 additions & 20 deletions util/path.go

This file was deleted.

20 changes: 0 additions & 20 deletions util/path_debug.go

This file was deleted.

0 comments on commit 218ed71

Please sign in to comment.