Skip to content

Commit

Permalink
Refactor path for configuration file, option(s) and Docker image (#247)
Browse files Browse the repository at this point in the history
* Refactor path for configuration file, option(s) and Docker image

Signed-off-by: Arrobo, Gabriel <[email protected]>

* Update `golangci` file accordingly

Signed-off-by: Arrobo, Gabriel <[email protected]>

---------

Signed-off-by: Arrobo, Gabriel <[email protected]>
  • Loading branch information
gab-arrobo authored Nov 7, 2024
1 parent 17615ca commit 5ca636f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 45 deletions.
37 changes: 16 additions & 21 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# SPDX-FileCopyrightText: 2024 Intel Corporation
# SPDX-FileCopyrightText: 2023 Open Networking Foundation <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -27,15 +28,6 @@ run:
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-files:
- "api_.*\\.go$"
- "model_.*\\.go$"
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
Expand All @@ -51,7 +43,7 @@ run:
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: colored-line-number
formats: colored-line-number
# print lines of code with issue, default is true
print-issued-lines: true
# print linter name in the end of issue text, default is true
Expand Down Expand Up @@ -134,10 +126,14 @@ linters-settings:
# minimal confidence for issues, default is 0.8
min-confidence: 0.8
gomnd:
settings:
mnd:
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
checks: argument,case,condition,operation,return,assign
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
checks:
- argument
- case
- condition
- operation
- return
- assign
gomodguard:
allowed:
modules: # List of allowed modules
Expand All @@ -155,8 +151,6 @@ linters-settings:
# version: "< 1.1.0" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
# reason: "testing if blocked version constraint works." # Reason why the version constraint exists. (Optional)
govet:
# report about shadowed variables
check-shadowing: true
# settings per analyzer
settings:
printf: # analyzer name, run `go tool vet help` to see all analyzers
Expand All @@ -167,6 +161,9 @@ linters-settings:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
# enable all analyzers
enable-all: true
disable:
- fieldalignment
disable-all: false
depguard:
list-type: blacklist
include-go-root: false
Expand Down Expand Up @@ -199,8 +196,6 @@ linters-settings:
whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
gci:
local-prefixes: "bitbucket.org"
misspell:
#locale: US
ignore-words:
Expand Down Expand Up @@ -254,9 +249,9 @@ linters:
- dogsled
# - bodyclose
- asciicheck
#- stylecheck
# - unparam
# - wsl
# - stylecheck
# - unparam
# - wsl

#disable-all: false
fast: true
Expand Down
9 changes: 4 additions & 5 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 <[email protected]>"

RUN apt-get update && \
apt-get -y install --no-install-recommends \
vim \
Expand All @@ -20,7 +18,8 @@ RUN make all

FROM alpine:3.20 AS gnbsim

LABEL description="Aether open source 5G Core Network" \
LABEL maintainer="Aether SD-Core <[email protected]>" \
description="Aether open source 5G Core Network" \
version="Stage 3"

ARG DEBUG_TOOLS
Expand All @@ -32,7 +31,7 @@ RUN if [ "$DEBUG_TOOLS" = "true" ]; then \
apk update && apk add --no-cache -U gcompat vim strace net-tools curl netcat-openbsd bind-tools; \
fi

WORKDIR /gnbsim/bin
WORKDIR /gnbsim

# Copy executable
COPY --from=builder /go/src/gnbsim/bin .
COPY --from=builder /go/src/gnbsim/bin /usr/local/bin/.
33 changes: 18 additions & 15 deletions gnbsim.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
_ "net/http/pprof" // Using package only for invoking initialization.
"os"
"os/signal"
"path/filepath"
"sync"
"syscall"
"time"
Expand All @@ -24,18 +25,18 @@ import (
prof "github.com/omec-project/gnbsim/profile"
profctx "github.com/omec-project/gnbsim/profile/context"
"github.com/omec-project/gnbsim/stats"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
"go.uber.org/zap/zapcore"
)

func main() {
app := cli.NewApp()
app.Name = "GNBSIM"
app.Usage = "./gnbsim --cfg [gnbsim configuration file]"
app.Usage = "gnbsim --cfg <gnbsim_config_file.yaml>"
app.Action = action
app.Flags = getCliFlags()

logger.AppLog.Infoln("App Name:", app.Name)
logger.AppLog.Infoln("app name:", app.Name)

if err := app.Run(os.Args); err != nil {
logger.AppLog.Errorln("failed to run GNBSIM:", err)
Expand All @@ -45,13 +46,14 @@ func main() {

func action(c *cli.Context) error {
cfg := c.String("cfg")
if cfg == "" {
logger.AppLog.Warnln("no configuration file provided. Using default configuration file:", factory.GNBSIM_DEFAULT_CONFIG_PATH)
logger.AppLog.Infoln("application usage:", c.App.Usage)
cfg = factory.GNBSIM_DEFAULT_CONFIG_PATH

absPath, err := filepath.Abs(cfg)
if err != nil {
logger.AppLog.Errorln(err)
return err
}

if err := factory.InitConfigFactory(cfg); err != nil {
if err = factory.InitConfigFactory(absPath); err != nil {
logger.AppLog.Errorln("failed to initialize config factory:", err)
return err
}
Expand All @@ -63,7 +65,7 @@ func action(c *cli.Context) error {
go func() {
endpt := fmt.Sprintf(":%v", config.Configuration.GoProfile.Port)
logger.AppLog.Infoln("endpoint for profile server", endpt)
err := http.ListenAndServe(endpt, nil)
err = http.ListenAndServe(endpt, nil)
if err != nil {
logger.AppLog.Errorln("failed to start profiling server")
}
Expand All @@ -76,7 +78,7 @@ func action(c *cli.Context) error {
logger.AppLog.Infoln("setting log level to:", lvl)
logger.SetLogLevel(lvl)

err := prof.InitializeAllProfiles()
err = prof.InitializeAllProfiles()
if err != nil {
logger.AppLog.Errorln("failed to initialize Profiles:", err)
return err
Expand Down Expand Up @@ -156,9 +158,10 @@ func action(c *cli.Context) error {

func getCliFlags() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: "cfg",
Usage: "GNBSIM config file",
&cli.StringFlag{
Name: "cfg",
Usage: "gNBSim config file",
Required: true,
},
}
}
Expand All @@ -178,8 +181,8 @@ func ListenAndLogSummary() {
logger.AppLog.Fatalln("invalid Message Type")
}

logger.AppSummaryLog.Infoln("Profile Name:", msg.ProfileName, ", Profile Type:", msg.ProfileType)
logger.AppSummaryLog.Infoln("Ue's Passed:", msg.UePassedCount, ", Ue's Failed:", msg.UeFailedCount)
logger.AppSummaryLog.Infof("Profile Name: %v, Profile Type: %v", msg.ProfileName, msg.ProfileType)
logger.AppSummaryLog.Infof("Ue's Passed: %v, Ue's Failed: %v", msg.UePassedCount, msg.UeFailedCount)

if len(msg.ErrorList) != 0 {
result = "FAIL"
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/omec-project/ngap v1.3.0
github.com/omec-project/openapi v1.3.1
github.com/omec-project/util v1.2.3
github.com/urfave/cli v1.22.16
github.com/urfave/cli/v2 v2.27.5
github.com/yerden/go-util v1.1.4
go.uber.org/zap v1.27.0
golang.org/x/net v0.30.0
Expand Down Expand Up @@ -76,6 +76,7 @@ require (
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
go.etcd.io/etcd/api/v3 v3.5.12 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.12 // indirect
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ git.cs.nctu.edu.tw/calee/sctp v1.1.0/go.mod h1:NeOuBXO1iJBtldmNhkfSH8yFbnxlhI8eE
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA=
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/Microsoft/hcsshim v0.9.4 h1:mnUj0ivWy6UzbB1uLFqKR6F+ZyiDc7j4iGgHTpO+5+I=
Expand Down Expand Up @@ -260,14 +259,16 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/urfave/cli v1.22.16 h1:MH0k6uJxdwdeWQTwhSO42Pwr4YLrNLwBtg1MRgTqPdQ=
github.com/urfave/cli v1.22.16/go.mod h1:EeJR6BKodywf4zciqrdw6hpCPk68JO9z5LazXZMn5Po=
github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
github.com/yerden/go-util v1.1.4 h1:jd8JyjLHzpEs1ZZQzDkfRgosDtXp/BtIAV1kpNjVTtw=
github.com/yerden/go-util v1.1.4/go.mod h1:3HeLrvtkEeAv67ARostM9Yn0DcAVqgJ3uAiCuywEEXk=
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM=
Expand Down

0 comments on commit 5ca636f

Please sign in to comment.