Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Rename package name to fleetdb #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/container-scan-trivy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

- name: Build go binary
run: |
go build -o serverservice .
go build -o fleetdb .

- name: Build
uses: docker/build-push-action@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
args: --timeout=5m

- name: Run go tests and generate coverage report
run: SERVERSERVICE_CRDB_URI="host=localhost port=26257 user=root sslmode=disable dbname=serverservice_test" go test -race -coverprofile=coverage.txt -covermode=atomic -tags testtools -p 1 ./...
run: FLEETDB_CRDB_URI="host=localhost port=26257 user=root sslmode=disable dbname=fleetdb_test" go test -race -coverprofile=coverage.txt -covermode=atomic -tags testtools -p 1 ./...

- name: Stop test database
run: cockroach quit --insecure --host=localhost:26257
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ run:

linters-settings:
goimports:
local-prefixes: go.hollow.sh/serverservice
local-prefixes: go.hollow.sh/fleetdb
gofumpt:
extra-rules: true

Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project_name: serverservice
project_name: fleetdb
before:
hooks:
- go mod download
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM gcr.io/distroless/static

# Copy the binary that goreleaser built
COPY serverservice /serverservice
COPY fleetdb /fleetdb

# Run the web service on container startup.
ENTRYPOINT ["/serverservice"]
ENTRYPOINT ["/fleetdb"]
CMD ["serve"]
8 changes: 4 additions & 4 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ RUN go mod tidy
# Build the binary.
# -mod=readonly ensures immutable go.mod and go.sum in container builds.
RUN export LDFLAG_LOCATION="go.infratographer.com/x/versionx" && \
CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o serverservice \
CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o fleetdb \
-ldflags \
"-X ${LDFLAG_LOCATION}.appName=serverservice \
"-X ${LDFLAG_LOCATION}.appName=fleetdb \
-X ${LDFLAG_LOCATION}.commit=$(git rev-parse --short HEAD) \
-X ${LDFLAG_LOCATION}.version=$(git describe --tags 2>/dev/null) \
-X ${LDFLAG_LOCATION}.date=$(date -u '+%H:%M:%S-%Y-%m-%d')"
Expand All @@ -30,8 +30,8 @@ FROM alpine:3.18.3
RUN apk add --no-cache ca-certificates

# Copy the binary to the production image from the builder stage.
COPY --from=builder /app/serverservice /serverservice
COPY --from=builder /app/fleetdb /fleetdb

# Run the web service on container startup.
ENTRYPOINT ["/serverservice"]
ENTRYPOINT ["/fleetdb"]
CMD ["serve"]
34 changes: 17 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ all: lint test
PHONY: test coverage lint golint clean vendor local-dev-databases docker-up docker-down integration-test unit-test
GOOS=linux
DB_STRING=host=localhost port=26257 user=root sslmode=disable
DEV_DB=${DB_STRING} dbname=serverservice
TEST_DB=${DB_STRING} dbname=serverservice_test
DOCKER_IMAGE := "ghcr.io/metal-toolbox/hollow-serverservice"
DEV_DB=${DB_STRING} dbname=fleetdb
TEST_DB=${DB_STRING} dbname=fleetdb_test
DOCKER_IMAGE := "ghcr.io/metal-toolbox/fleetdb"

## run all tests
test: | unit-test integration-test

## run integration tests
integration-test: test-database
@echo Running integration tests...
@SERVERSERVICE_CRDB_URI="${TEST_DB}" go test -cover -tags testtools,integration -p 1 ./...
@FLEETDB_CRDB_URI="${TEST_DB}" go test -cover -tags testtools,integration -p 1 ./...

## run lint and unit tests
unit-test: | lint
Expand All @@ -22,7 +22,7 @@ unit-test: | lint
## check test coverage
coverage: | test-database
@echo Generating coverage report...
@SERVERSERVICE_CRDB_URI="${TEST_DB}" go test ./... -race -coverprofile=coverage.out -covermode=atomic -tags testtools -p 1
@FLEETDB_CRDB_URI="${TEST_DB}" go test ./... -race -coverprofile=coverage.out -covermode=atomic -tags testtools -p 1
@go tool cover -func=coverage.out
@go tool cover -html=coverage.out

Expand Down Expand Up @@ -58,23 +58,23 @@ docker-clean:

## setup devel database
dev-database: | vendor
@cockroach sql --insecure -e "drop database if exists serverservice"
@cockroach sql --insecure -e "create database serverservice"
@SERVERSERVICE_CRDB_URI="${DEV_DB}" go run main.go migrate up
@cockroach sql --insecure -e "drop database if exists fleetdb"
@cockroach sql --insecure -e "create database fleetdb"
@FLEETDB_CRDB_URI="${DEV_DB}" go run main.go migrate up

## setup test database
test-database: | vendor
@cockroach sql --insecure -e "drop database if exists serverservice_test"
@cockroach sql --insecure -e "create database serverservice_test"
@SERVERSERVICE_CRDB_URI="${TEST_DB}" go run main.go migrate up
@cockroach sql --insecure -e "use serverservice_test; ALTER TABLE attributes DROP CONSTRAINT check_server_id_server_component_id; ALTER TABLE versioned_attributes DROP CONSTRAINT check_server_id_server_component_id;"
@cockroach sql --insecure -e "drop database if exists fleetdb_test"
@cockroach sql --insecure -e "create database fleetdb_test"
@FLEETDB_CRDB_URI="${TEST_DB}" go run main.go migrate up
@cockroach sql --insecure -e "use fleetdb_test; ALTER TABLE attributes DROP CONSTRAINT check_server_id_server_component_id; ALTER TABLE versioned_attributes DROP CONSTRAINT check_server_id_server_component_id;"


## Build linux bin
build-linux:
GOOS=linux GOARCH=amd64 go build -o serverservice
GOOS=linux GOARCH=amd64 go build -o fleetdb

## build docker image and tag as ghcr.io/metal-toolbox/hollow-serverservice:latest
## build docker image and tag as ghcr.io/metal-toolbox/fleetdb:latest
build-image: build-linux
docker build --rm=true -f Dockerfile -t ${DOCKER_IMAGE}:latest . \
--label org.label-schema.schema-version=1.0 \
Expand All @@ -83,9 +83,9 @@ build-image: build-linux

## build and push devel docker image to KIND image repo used by the sandbox - https://github.com/metal-toolbox/sandbox
push-image-devel: build-image
docker tag ${DOCKER_IMAGE}:latest localhost:5001/serverservice:latest
docker push localhost:5001/serverservice:latest
kind load docker-image localhost:5001/serverservice:latest
docker tag ${DOCKER_IMAGE}:latest localhost:5001/fleetdb:latest
docker push localhost:5001/fleetdb:latest
kind load docker-image localhost:5001/fleetdb:latest


# https://gist.github.com/prwhite/8168133
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Server Service
# FleetDB

> This repository is experimental meaning that it's based on untested ideas or techniques and not yet established or finalized or involves a radically new and innovative style!
> This means that support is best effort (at best!) and we strongly encourage you to NOT use this in production.

The server service is a microservice within the Hollow eco-system. Server service is responsible for providing a store for physical server information. Support to storing the device components that make up the server is available. You are also able to create attributes and versioned-attributes for both servers and the server components.
The fleetdb is a microservice within the Hollow eco-system. FleetDB is responsible for providing a store for physical server information. Support to storing the device components that make up the server is available. You are also able to create attributes and versioned-attributes for both servers and the server components.

## Quickstart to running locally

Expand All @@ -13,24 +13,24 @@ The cockroachdb client is required to create and drop the test database.

Follow the instructions to install the cockroachdb dependency https://www.cockroachlabs.com/docs/stable/install-cockroachdb.html

### Running server service
### Running fleetdb

To run the server service locally you can bring it up with docker-compose. This will run with released images from the hollow container registry.
To run the fleetdb locally you can bring it up with docker-compose. This will run with released images from the hollow container registry.

```bash
docker-compose -f quickstart.yml up
```
### Enable tracing

To run the server service locally with tracing enabled you just need to include the `quickstart-tracing.yml` file.
To run the fleetdb locally with tracing enabled you just need to include the `quickstart-tracing.yml` file.

```bash
docker-compose -f quickstart.yml -f quickstart-tracing.yml up
```

### Running with local changes

The `quickstart.yml` compose file will run server service from released images and not the local code base. If you are doing development and want to run with your local code you can use the following command.
The `quickstart.yml` compose file will run fleetdb from released images and not the local code base. If you are doing development and want to run with your local code you can use the following command.

```bash
docker-compose -f quickstart.yml -f quickstart-dev.yml up --build
Expand All @@ -54,11 +54,11 @@ sqlboiler crdb --add-soft-deletes
Export the DB URI required for integration tests.

```bash
export SERVERSERVICE_CRDB_URI="host=localhost port=26257 user=root sslmode=disable dbname=serverservice_test"
export FLEETDB_CRDB_URI="host=localhost port=26257 user=root sslmode=disable dbname=fleetdb_test"
```

Run test.

```bash
go test -timeout 30s -tags testtools -run ^TestIntegrationServerListComponents$ go.hollow.sh/serverservice/pkg/api/v1 -v
go test -timeout 30s -tags testtools -run ^TestIntegrationServerListComponents$ go.hollow.sh/fleetdb/pkg/api/v1 -v
```
2 changes: 1 addition & 1 deletion cmd/doc.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Package cmd provides our CLI interface for the hollow binary
package cmd // import "go.hollow.sh/serverservice/cmd"
package cmd // import "go.hollow.sh/fleetdb/cmd"
12 changes: 6 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ import (
"go.infratographer.com/x/versionx"
"go.uber.org/zap"

dbm "go.hollow.sh/serverservice/db"
"go.hollow.sh/serverservice/internal/config"
dbm "go.hollow.sh/fleetdb/db"
"go.hollow.sh/fleetdb/internal/config"
)

var (
appName = "serverservice"
appName = "fleetdb"
cfgFile string
logger *zap.SugaredLogger
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "serverservice",
Short: "Server Service for Hollow ecosystem",
Use: "fleetdb",
Short: "FleetDB for Hollow ecosystem",
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down Expand Up @@ -69,7 +69,7 @@ func initConfig() {
}

viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.SetEnvPrefix("serverservice")
viper.SetEnvPrefix("fleetdb")
viper.AutomaticEnv() // read in environment variables that match

// If a config file is found, read it in.
Expand Down
10 changes: 5 additions & 5 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
// import gocdk secret drivers
_ "gocloud.dev/secrets/localsecrets"

"go.hollow.sh/serverservice/internal/config"
"go.hollow.sh/serverservice/internal/dbtools"
"go.hollow.sh/serverservice/internal/httpsrv"
"go.hollow.sh/fleetdb/internal/config"
"go.hollow.sh/fleetdb/internal/dbtools"
"go.hollow.sh/fleetdb/internal/httpsrv"
)

var (
Expand Down Expand Up @@ -77,10 +77,10 @@ func init() {
rootCmd.PersistentFlags().String("nats-stream-name", appName, "prefix for NATS subjects")
viperx.MustBindFlag(viper.GetViper(), "nats.stream.name", rootCmd.PersistentFlags().Lookup("nats-stream-name"))

rootCmd.PersistentFlags().String("nats-stream-prefix", "com.hollow.sh.serverservice.events", "NATS stream prefix")
rootCmd.PersistentFlags().String("nats-stream-prefix", "com.hollow.sh.fleetdb.events", "NATS stream prefix")
viperx.MustBindFlag(viper.GetViper(), "nats.stream.prefix", rootCmd.PersistentFlags().Lookup("nats-stream-prefix"))

rootCmd.PersistentFlags().StringSlice("nats-stream-subjects", []string{"com.hollow.sh.serverservice.events.>"}, "NATS stream subject(s)")
rootCmd.PersistentFlags().StringSlice("nats-stream-subjects", []string{"com.hollow.sh.fleetdb.events.>"}, "NATS stream subject(s)")
viperx.MustBindFlag(viper.GetViper(), "nats.stream.subjects", rootCmd.PersistentFlags().Lookup("nats-stream-subjects"))

rootCmd.PersistentFlags().String("nats-stream-urn-ns", "hollow", "NATS stream URN namespace value")
Expand Down
Binary file added fleetdb
Binary file not shown.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module go.hollow.sh/serverservice
module go.hollow.sh/fleetdb

go 1.19

Expand Down Expand Up @@ -36,6 +36,7 @@ require (

require (
github.com/volatiletech/sqlboiler v3.7.1+incompatible
go.hollow.sh/serverservice v0.16.2
go.hollow.sh/toolbox v0.6.1
go.infratographer.com/x v0.3.7
gocloud.dev v0.33.0
Expand Down Expand Up @@ -122,7 +123,6 @@ require (
golang.org/x/text v0.12.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.137.0 // indirect
google.golang.org/genproto v0.0.0-20230815205213-6bfd019c3878 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230815205213-6bfd019c3878 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230815205213-6bfd019c3878 // indirect
google.golang.org/grpc v1.57.0 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,8 @@ go.etcd.io/etcd/api/v3 v3.5.4/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dY
go.etcd.io/etcd/client/pkg/v3 v3.5.4/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
go.etcd.io/etcd/client/v2 v2.305.4/go.mod h1:Ud+VUwIi9/uQHOMA+4ekToJ12lTxlv0zB/+DHwTGEbU=
go.etcd.io/etcd/client/v3 v3.5.4/go.mod h1:ZaRkVgBZC+L+dLCjTcF1hRXpgZXQPOvnA/Ak/gq3kiY=
go.hollow.sh/serverservice v0.16.2 h1:0wt0XJC/rm4OdovB6g8Fsx7BT2X71pG0keJiiLZaY+w=
go.hollow.sh/serverservice v0.16.2/go.mod h1:Zr99vSFO++ZlDjEf9rtPWi3TiMgMswJCW3D6LIFmMDM=
go.hollow.sh/toolbox v0.6.1 h1:3E6JofImSCe63XayczbGfDxIXUjmBziMBBmbwook8WA=
go.hollow.sh/toolbox v0.6.1/go.mod h1:nl+5RDDyYY/+wukOUzHHX2mOyWKRjlTOXUcGxny+tns=
go.infratographer.com/x v0.3.7 h1:kkykoVtC8XrmvC4oZwHWa/15+dv9RhQHgSm8KoEb/Nc=
Expand Down Expand Up @@ -1211,7 +1213,6 @@ google.golang.org/genproto v0.0.0-20220429170224-98d788798c3e/go.mod h1:8w6bsBMX
google.golang.org/genproto v0.0.0-20220505152158-f39f71e6c8f3/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4=
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4=
google.golang.org/genproto v0.0.0-20230815205213-6bfd019c3878 h1:Iveh6tGCJkHAjJgEqUQYGDGgbwmhjoAOz8kO/ajxefY=
google.golang.org/genproto v0.0.0-20230815205213-6bfd019c3878/go.mod h1:yZTlhN0tQnXo3h00fuXNCxJdLdIdnVFVBaRJ5LWBbw4=
google.golang.org/genproto/googleapis/api v0.0.0-20230815205213-6bfd019c3878 h1:WGq4lvB/mlicysM/dUT3SBvijH4D3sm/Ny1A4wmt2CI=
google.golang.org/genproto/googleapis/api v0.0.0-20230815205213-6bfd019c3878/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230815205213-6bfd019c3878 h1:lv6/DhyiFFGsmzxbsUUTOkN29II+zeWHxvT8Lpdxsv0=
Expand Down
2 changes: 1 addition & 1 deletion internal/dbtools/doc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Package dbtools provides tools to help with interacting with the database,
// including all of our utilities for database integration testing
package dbtools // import "go.hollow.sh/serverservice/internal/dbtools"
package dbtools // import "go.hollow.sh/fleetdb/internal/dbtools"
2 changes: 1 addition & 1 deletion internal/dbtools/encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/stretchr/testify/assert"

"go.hollow.sh/serverservice/internal/dbtools"
"go.hollow.sh/fleetdb/internal/dbtools"
)

func TestEncryptandDecrypt(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/dbtools/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/volatiletech/sqlboiler/v4/boil"
"github.com/volatiletech/sqlboiler/v4/types"

"go.hollow.sh/serverservice/internal/models"
"go.hollow.sh/fleetdb/internal/models"
)

//nolint:revive
Expand Down
2 changes: 1 addition & 1 deletion internal/dbtools/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/gosimple/slug"
"github.com/volatiletech/sqlboiler/v4/boil"

"go.hollow.sh/serverservice/internal/models"
"go.hollow.sh/fleetdb/internal/models"
)

// RegisterHooks adds any hooks that are configured to the models library
Expand Down
4 changes: 2 additions & 2 deletions internal/dbtools/testtools.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
// import gocdk secret drivers
_ "gocloud.dev/secrets/localsecrets"

"go.hollow.sh/serverservice/internal/models"
"go.hollow.sh/fleetdb/internal/models"
)

// TestDBURI is the URI for the test database
var TestDBURI = os.Getenv("SERVERSERVICE_CRDB_URI")
var TestDBURI = os.Getenv("FLEETDB_CRDB_URI")
var testDB *sqlx.DB
var testKeeper *secrets.Keeper

Expand Down
4 changes: 2 additions & 2 deletions internal/dbtools/testtools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/volatiletech/null/v8"
"github.com/volatiletech/sqlboiler/v4/boil"

"go.hollow.sh/serverservice/internal/dbtools"
"go.hollow.sh/serverservice/internal/models"
"go.hollow.sh/fleetdb/internal/dbtools"
"go.hollow.sh/fleetdb/internal/models"
)

// TestDatabaseTest is used to force the test commands in this package to run during
Expand Down
4 changes: 2 additions & 2 deletions internal/httpsrv/doc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Package httpsrv provides the HTTP server to handle all
// requests for the serverservice.
package httpsrv // import go.hollow.sh/serverservice/internal/httpsrv
// requests for the fleetdb.
package httpsrv // import go.hollow.sh/fleetdb/internal/httpsrv
4 changes: 2 additions & 2 deletions internal/httpsrv/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"go.uber.org/zap"
"gocloud.dev/secrets"

v1api "go.hollow.sh/serverservice/pkg/api/v1"
v1api "go.hollow.sh/fleetdb/pkg/api/v1"
)

// Server implements the HTTP Server
Expand Down Expand Up @@ -164,7 +164,7 @@ func (s *Server) readinessCheck(c *gin.Context) {
})
}

// version returns the serverservice build information.
// version returns the fleetdb build information.
func (s *Server) version(c *gin.Context) {
c.JSON(http.StatusOK, versionx.BuildDetails().String())
}
4 changes: 2 additions & 2 deletions internal/httpsrv/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"go.hollow.sh/toolbox/ginjwt"
"go.uber.org/zap"

"go.hollow.sh/serverservice/internal/dbtools"
"go.hollow.sh/serverservice/internal/httpsrv"
"go.hollow.sh/fleetdb/internal/dbtools"
"go.hollow.sh/fleetdb/internal/httpsrv"
)

var serverAuthConfig = ginjwt.AuthConfig{
Expand Down
Loading
Loading