Skip to content
This repository was archived by the owner on Aug 11, 2025. It is now read-only.

Commit f1ca5e5

Browse files
authored
initiate the structure of the bomservice with parser and handler (#2)
1 parent dbdd3f3 commit f1ca5e5

32 files changed

+3142
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
*.dll
55
*.so
66
*.dylib
7+
*.DS_Store
8+
9+
hollow-bomservice
710

811
# Test binary, built with `go test -c`
912
*.test

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM alpine:3.18.0
2+
3+
ENTRYPOINT ["/usr/sbin/hollow-bomservice"]
4+
5+
COPY hollow-bomservice /usr/sbin/hollow-bomservice
6+
RUN chmod +x /usr/sbin/hollow-bomservice

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright [2023] [Metal Toolbox Authors]
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

Makefile

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
export DOCKER_BUILDKIT=1
2+
LDFLAG_LOCATION := github.com/metal-toolbox/hollow-bomservice/internal/version
3+
GIT_COMMIT := $(shell git rev-parse --short HEAD)
4+
GIT_BRANCH := $(shell git symbolic-ref -q --short HEAD)
5+
GIT_SUMMARY := $(shell git describe --tags --dirty --always)
6+
VERSION := $(shell git describe --tags 2> /dev/null)
7+
BUILD_DATE := $(shell date +%s)
8+
GIT_COMMIT_FULL := $(shell git rev-parse HEAD)
9+
GO_VERSION := $(shell expr `go version |cut -d ' ' -f3 |cut -d. -f2` \>= 16)
10+
DOCKER_IMAGE := "ghcr.io/metal-toolbox/hollow-bomservice"
11+
REPO := "https://github.com/metal-toolbox/hollow-bomservice.git"
12+
13+
.DEFAULT_GOAL := help
14+
15+
## lint
16+
lint:
17+
golangci-lint run
18+
19+
## Go test
20+
test: lint
21+
CGO_ENABLED=0 go test -timeout 1m -v -covermode=atomic ./...
22+
23+
24+
## generate mock store - invoke when changes are made to the store interface
25+
gen-store-mock:
26+
go install github.com/golang/mock/mockgen@v1.6.0
27+
mockgen -package=mock -source=internal/store/interface.go > internal/store/mock/mock.go
28+
29+
## build osx bin
30+
build-osx:
31+
ifeq ($(GO_VERSION), 0)
32+
$(error build requies go version 1.17.n or higher)
33+
endif
34+
GOOS=darwin GOARCH=amd64 go build -o hollow-bomservice \
35+
-ldflags \
36+
"-X $(LDFLAG_LOCATION).GitCommit=$(GIT_COMMIT) \
37+
-X $(LDFLAG_LOCATION).GitBranch=$(GIT_BRANCH) \
38+
-X $(LDFLAG_LOCATION).GitSummary=$(GIT_SUMMARY) \
39+
-X $(LDFLAG_LOCATION).AppVersion=$(VERSION) \
40+
-X $(LDFLAG_LOCATION).BuildDate=$(BUILD_DATE)"
41+
42+
43+
44+
## Build linux bin
45+
build-linux:
46+
ifeq ($(GO_VERSION), 0)
47+
$(error build requies go version 1.20.x+ or higher)
48+
endif
49+
GOOS=linux GOARCH=amd64 go build -o hollow-bomservice \
50+
-ldflags \
51+
"-X $(LDFLAG_LOCATION).GitCommit=$(GIT_COMMIT) \
52+
-X $(LDFLAG_LOCATION).GitBranch=$(GIT_BRANCH) \
53+
-X $(LDFLAG_LOCATION).GitSummary=$(GIT_SUMMARY) \
54+
-X $(LDFLAG_LOCATION).AppVersion=$(VERSION) \
55+
-X $(LDFLAG_LOCATION).BuildDate=$(BUILD_DATE)"
56+
57+
58+
## build docker image and tag as ghcr.io/metal-toolbox/hollow-bomservice:latest
59+
build-image: build-linux
60+
@echo ">>>> NOTE: You may want to execute 'make build-image-nocache' depending on the Docker stages changed"
61+
docker build --rm=true -f Dockerfile -t ${DOCKER_IMAGE}:latest . \
62+
--label org.label-schema.schema-version=1.0 \
63+
--label org.label-schema.vcs-ref=$(GIT_COMMIT_FULL) \
64+
--label org.label-schema.vcs-url=$(REPO)
65+
66+
## build and push devel docker image to KIND image repo
67+
push-image-devel: build-image
68+
docker tag ${DOCKER_IMAGE}:latest localhost:5001/hollow-bomservice:latest
69+
docker push localhost:5001/hollow-bomservice:latest
70+
kind load docker-image localhost:5001/hollow-bomservice:latest
71+
72+
## push docker image
73+
push-image:
74+
docker push ${DOCKER_IMAGE}:latest
75+
76+
77+
# https://gist.github.com/prwhite/8168133
78+
# COLORS
79+
GREEN := $(shell tput -Txterm setaf 2)
80+
YELLOW := $(shell tput -Txterm setaf 3)
81+
WHITE := $(shell tput -Txterm setaf 7)
82+
RESET := $(shell tput -Txterm sgr0)
83+
84+
85+
TARGET_MAX_CHAR_NUM=20
86+
## Show help
87+
help:
88+
@echo ''
89+
@echo 'Usage:'
90+
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
91+
@echo ''
92+
@echo 'Targets:'
93+
@awk '/^[a-zA-Z\-\\_0-9]+:/ { \
94+
helpMessage = match(lastLine, /^## (.*)/); \
95+
if (helpMessage) { \
96+
helpCommand = substr($$1, 0, index($$1, ":")-1); \
97+
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
98+
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
99+
} \
100+
} \
101+
{ lastLine = $$0 }' $(MAKEFILE_LIST)

cmd/root.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Copyright © 2022 Metal toolbox authors <>
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package cmd
17+
18+
import (
19+
"fmt"
20+
"os"
21+
22+
"github.com/spf13/cobra"
23+
)
24+
25+
var (
26+
logLevel string
27+
cfgFile string
28+
)
29+
30+
// rootCmd represents the base command when called without any subcommands
31+
var rootCmd = &cobra.Command{
32+
Use: "hollow-bomservice",
33+
Short: "server hollow bomservice",
34+
}
35+
36+
// Execute adds all child commands to the root command and sets flags appropriately.
37+
// This is called by main.main(). It only needs to happen once to the rootCmd.
38+
func Execute() {
39+
if err := rootCmd.Execute(); err != nil {
40+
fmt.Println(err)
41+
os.Exit(1)
42+
}
43+
}
44+
45+
func init() {
46+
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "bomservice.yaml", "default is ./bomservice.yaml")
47+
rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "set logging level - debug, trace")
48+
}

cmd/server.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package cmd
2+
3+
import (
4+
"context"
5+
"errors"
6+
"log"
7+
"net/http"
8+
"time"
9+
10+
"github.com/metal-toolbox/hollow-bomservice/internal/app"
11+
"github.com/metal-toolbox/hollow-bomservice/internal/model"
12+
"github.com/metal-toolbox/hollow-bomservice/internal/server"
13+
"github.com/metal-toolbox/hollow-bomservice/internal/store"
14+
"github.com/spf13/cobra"
15+
)
16+
17+
var (
18+
shutdownTimeout = 10 * time.Second
19+
)
20+
21+
// install server command
22+
var cmdServer = &cobra.Command{
23+
Use: "server",
24+
Short: "Run hollow bomservice server",
25+
Run: func(cmd *cobra.Command, args []string) {
26+
app, termCh, err := app.New(model.AppKindServer, cfgFile, model.LogLevel(logLevel))
27+
if err != nil {
28+
log.Fatal(err)
29+
}
30+
31+
ctx, cancel := context.WithCancel(cmd.Context())
32+
defer cancel()
33+
repository, err := store.NewStore(ctx, app.Config, app.Logger)
34+
if err != nil {
35+
app.Logger.Fatal(err)
36+
}
37+
38+
options := []server.Option{
39+
server.WithLogger(app.Logger),
40+
server.WithListenAddress(app.Config.ListenAddress),
41+
server.WithStore(repository),
42+
server.WithAuthMiddlewareConfig(app.Config.APIServerJWTAuth),
43+
}
44+
45+
srv := server.New(options...)
46+
go func() {
47+
if err := srv.ListenAndServe(); err != nil && errors.Is(err, http.ErrServerClosed) {
48+
app.Logger.Fatal(err)
49+
}
50+
}()
51+
52+
// sit around for term signal
53+
<-termCh
54+
app.Logger.Info("got TERM signal, shutting down server...")
55+
56+
sCtx, sCancel := context.WithTimeout(ctx, shutdownTimeout)
57+
defer sCancel()
58+
if err := srv.Shutdown(sCtx); err != nil {
59+
app.Logger.Fatal("server shutdown error:", err)
60+
}
61+
},
62+
}
63+
64+
// install command flags
65+
func init() {
66+
rootCmd.AddCommand(cmdServer)
67+
}

go.mod

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
module github.com/metal-toolbox/hollow-bomservice
2+
3+
go 1.21.0
4+
5+
require (
6+
github.com/banzaicloud/logrus-runtime-formatter v0.0.0-20190729070250-5ae5475bae5e
7+
github.com/coreos/go-oidc v2.2.1+incompatible
8+
github.com/gin-gonic/gin v1.9.1
9+
github.com/golang/mock v1.6.0
10+
github.com/hashicorp/go-retryablehttp v0.7.4
11+
github.com/pkg/errors v0.9.1
12+
github.com/sirupsen/logrus v1.9.3
13+
github.com/spf13/cobra v1.7.0
14+
github.com/spf13/viper v1.16.0
15+
github.com/tealeg/xlsx v1.0.5
16+
go.hollow.sh/serverservice v0.16.1
17+
go.hollow.sh/toolbox v0.6.1
18+
golang.org/x/oauth2 v0.11.0
19+
)
20+
21+
require (
22+
github.com/bytedance/sonic v1.10.0 // indirect
23+
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
24+
github.com/chenzhuoyu/iasm v0.9.0 // indirect
25+
github.com/cockroachdb/cockroach-go/v2 v2.3.5 // indirect
26+
github.com/davecgh/go-spew v1.1.1 // indirect
27+
github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 // indirect
28+
github.com/friendsofgo/errors v0.9.2 // indirect
29+
github.com/fsnotify/fsnotify v1.6.0 // indirect
30+
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
31+
github.com/gin-contrib/sse v0.1.0 // indirect
32+
github.com/go-logr/logr v1.2.4 // indirect
33+
github.com/go-logr/stdr v1.2.2 // indirect
34+
github.com/go-playground/locales v0.14.1 // indirect
35+
github.com/go-playground/universal-translator v0.18.1 // indirect
36+
github.com/go-playground/validator/v10 v10.15.0 // indirect
37+
github.com/goccy/go-json v0.10.2 // indirect
38+
github.com/gofrs/uuid v4.4.0+incompatible // indirect
39+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
40+
github.com/golang/protobuf v1.5.3 // indirect
41+
github.com/google/uuid v1.3.1 // indirect
42+
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
43+
github.com/gosimple/slug v1.13.1 // indirect
44+
github.com/gosimple/unidecode v1.0.1 // indirect
45+
github.com/hashicorp/errwrap v1.1.0 // indirect
46+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
47+
github.com/hashicorp/go-multierror v1.1.1 // indirect
48+
github.com/hashicorp/hcl v1.0.0 // indirect
49+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
50+
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
51+
github.com/jackc/pgconn v1.14.1 // indirect
52+
github.com/jackc/pgio v1.0.0 // indirect
53+
github.com/jackc/pgpassfile v1.0.0 // indirect
54+
github.com/jackc/pgproto3/v2 v2.3.2 // indirect
55+
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
56+
github.com/jackc/pgtype v1.14.0 // indirect
57+
github.com/jackc/pgx/v4 v4.18.1 // indirect
58+
github.com/jmoiron/sqlx v1.3.5 // indirect
59+
github.com/json-iterator/go v1.1.12 // indirect
60+
github.com/klauspost/compress v1.16.7 // indirect
61+
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
62+
github.com/leodido/go-urn v1.2.4 // indirect
63+
github.com/lib/pq v1.10.9 // indirect
64+
github.com/magiconair/properties v1.8.7 // indirect
65+
github.com/mattn/go-colorable v0.1.13 // indirect
66+
github.com/mattn/go-isatty v0.0.19 // indirect
67+
github.com/mitchellh/mapstructure v1.5.0 // indirect
68+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
69+
github.com/modern-go/reflect2 v1.0.2 // indirect
70+
github.com/nats-io/jwt/v2 v2.4.0 // indirect
71+
github.com/nats-io/nats.go v1.28.0 // indirect
72+
github.com/nats-io/nkeys v0.4.4 // indirect
73+
github.com/nats-io/nuid v1.0.1 // indirect
74+
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
75+
github.com/pmezard/go-difflib v1.0.0 // indirect
76+
github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021 // indirect
77+
github.com/rogpeppe/go-internal v1.10.0 // indirect
78+
github.com/spf13/afero v1.9.5 // indirect
79+
github.com/spf13/cast v1.5.1 // indirect
80+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
81+
github.com/spf13/pflag v1.0.5 // indirect
82+
github.com/stretchr/testify v1.8.4 // indirect
83+
github.com/subosito/gotenv v1.6.0 // indirect
84+
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
85+
github.com/ugorji/go/codec v1.2.11 // indirect
86+
github.com/volatiletech/inflect v0.0.1 // indirect
87+
github.com/volatiletech/null v8.0.0+incompatible // indirect
88+
github.com/volatiletech/null/v8 v8.1.2 // indirect
89+
github.com/volatiletech/randomize v0.0.1 // indirect
90+
github.com/volatiletech/sqlboiler v3.7.1+incompatible // indirect
91+
github.com/volatiletech/sqlboiler/v4 v4.15.0 // indirect
92+
github.com/volatiletech/strmangle v0.0.5 // indirect
93+
go.opencensus.io v0.24.0 // indirect
94+
go.opentelemetry.io/otel v1.17.0 // indirect
95+
go.opentelemetry.io/otel/metric v1.17.0 // indirect
96+
go.opentelemetry.io/otel/trace v1.17.0 // indirect
97+
go.uber.org/multierr v1.11.0 // indirect
98+
go.uber.org/zap v1.25.0 // indirect
99+
gocloud.dev v0.33.0 // indirect
100+
golang.org/x/arch v0.4.0 // indirect
101+
golang.org/x/crypto v0.12.0 // indirect
102+
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
103+
golang.org/x/net v0.14.0 // indirect
104+
golang.org/x/sys v0.11.0 // indirect
105+
golang.org/x/text v0.12.0 // indirect
106+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
107+
google.golang.org/api v0.137.0 // indirect
108+
google.golang.org/appengine v1.6.7 // indirect
109+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230815205213-6bfd019c3878 // indirect
110+
google.golang.org/grpc v1.57.0 // indirect
111+
google.golang.org/protobuf v1.31.0 // indirect
112+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
113+
gopkg.in/ini.v1 v1.67.0 // indirect
114+
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
115+
gopkg.in/yaml.v3 v3.0.1 // indirect
116+
)

0 commit comments

Comments
 (0)