Skip to content

Commit

Permalink
FS-1203; Change mod name from serverservice to fleetdb. (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeschuurmans committed Feb 14, 2024
1 parent 9f6d3e7 commit f2a287d
Show file tree
Hide file tree
Showing 74 changed files with 435 additions and 434 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ cosign.key
cockroach-data/
coverage.txt
*.swp
*.swo
*.swo
fleetdb
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: github.com/metal-toolbox/fleetdb
gofumpt:
extra-rules: true

Expand Down
10 changes: 5 additions & 5 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ 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 fleetdb \
CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o fleetdb \
-ldflags \
"-X ${LDFLAG_LOCATION}.appName=serverservice \
-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')"
"-X ${LDFLAG_LOCATION}.appName=serverservice \
-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')"

# Use the official Alpine image for a lean production container.
# https://hub.docker.com/_/alpine
Expand Down
28 changes: 14 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ 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/fleetdb"
DOCKER_IMAGE := "ghcr.io/metal-toolbox/fleetdb"
PROJECT_NAME := fleetdb
REPO := "https://github.com/metal-toolbox/fleetdb.git"

## run all tests
test: | unit-test integration-test
Expand Down Expand Up @@ -69,24 +71,22 @@ test-database: | vendor
@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;"


## Build linux bin
build-linux:
GOOS=linux GOARCH=amd64 go build -o fleetdb
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${PROJECT_NAME}

## 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 \
--label org.label-schema.vcs-ref=$(GIT_COMMIT_FULL) \
--label org.label-schema.vcs-url=$(REPO)
docker build --rm=true -f Dockerfile -t ${DOCKER_IMAGE}:latest . \
--label org.label-schema.schema-version=1.0 \
--label org.label-schema.vcs-ref=${GIT_COMMIT_FULL} \
--label org.label-schema.vcs-url=${REPO}

## 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/fleetdb:latest
docker push localhost:5001/fleetdb:latest
kind load docker-image localhost:5001/fleetdb:latest

docker tag ${DOCKER_IMAGE}:latest localhost:5001/${PROJECT_NAME}:latest
docker push localhost:5001/${PROJECT_NAME}:latest
kind load docker-image localhost:5001/${PROJECT_NAME}:latest

# https://gist.github.com/prwhite/8168133
# COLORS
Expand All @@ -95,8 +95,8 @@ YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)


TARGET_MAX_CHAR_NUM=20

## Show help
help:
@echo ''
Expand All @@ -109,7 +109,7 @@ help:
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
printf " ${YELLOW}%-${TARGET_MAX_CHAR_NUM}s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
{ lastLine = $$0 }' ${MAKEFILE_LIST}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ export SERVERSERVICE_CRDB_URI="host=localhost port=26257 user=root sslmode=disab
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$ github.com/metal-toolbox/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
6 changes: 3 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"go.infratographer.com/x/versionx"
"go.uber.org/zap"

dbm "go.hollow.sh/serverservice/db"
"go.hollow.sh/serverservice/internal/config"
"github.com/metal-toolbox/fleetdb/db"
"github.com/metal-toolbox/fleetdb/internal/config"
)

var (
Expand Down Expand Up @@ -47,7 +47,7 @@ func init() {

// Setup migrate command
goosex.RegisterCobraCommand(rootCmd, func() {
goosex.SetBaseFS(dbm.Migrations)
goosex.SetBaseFS(db.Migrations)
goosex.SetDBURI(config.AppConfig.CRDB.URI)
goosex.SetLogger(logger)
})
Expand Down
6 changes: 3 additions & 3 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,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"
"github.com/metal-toolbox/fleetdb/internal/config"
"github.com/metal-toolbox/fleetdb/internal/dbtools"
"github.com/metal-toolbox/fleetdb/internal/httpsrv"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module go.hollow.sh/serverservice
module github.com/metal-toolbox/fleetdb

go 1.19

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
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"
"github.com/metal-toolbox/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"
"github.com/metal-toolbox/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"
"github.com/metal-toolbox/fleetdb/internal/models"
)

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

"go.hollow.sh/serverservice/internal/models"
"github.com/metal-toolbox/fleetdb/internal/models"
)

// TestDBURI is the URI for the test database
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"
"github.com/metal-toolbox/fleetdb/internal/dbtools"
"github.com/metal-toolbox/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
6 changes: 3 additions & 3 deletions internal/httpsrv/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"go.uber.org/zap"
"gocloud.dev/secrets"

v1api "go.hollow.sh/serverservice/pkg/api/v1"
fleetdbapi "github.com/metal-toolbox/fleetdb/pkg/api/v1"
)

// Server implements the HTTP Server
Expand Down Expand Up @@ -63,7 +63,7 @@ func (s *Server) setup() *gin.Engine {

p := ginprometheus.NewPrometheus("gin")

v1Rtr := v1api.Router{
v1Rtr := fleetdbapi.Router{
DB: s.DB,
AuthMW: authMW,
SecretsKeeper: s.SecretsKeeper,
Expand Down Expand Up @@ -165,7 +165,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"
"github.com/metal-toolbox/fleetdb/internal/dbtools"
"github.com/metal-toolbox/fleetdb/internal/httpsrv"
)

var serverAuthConfig = []ginjwt.AuthConfig{
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main

//go:generate sqlboiler crdb --add-soft-deletes

import "go.hollow.sh/serverservice/cmd"
import "github.com/metal-toolbox/fleetdb/cmd"

func main() {
cmd.Execute()
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1/attribute_list_params.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package serverservice
package fleetdbapi

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1/attribute_list_params_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package serverservice
package fleetdbapi

import (
"net/http"
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1/attributes.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package serverservice
package fleetdbapi

import (
"encoding/json"
"time"

"github.com/volatiletech/sqlboiler/v4/types"

"go.hollow.sh/serverservice/internal/models"
"github.com/metal-toolbox/fleetdb/internal/models"
)

// Attributes provide the ability to apply namespaced settings to an entity.
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1/bom.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package serverservice
package fleetdbapi

import (
"strings"

"github.com/pkg/errors"
"github.com/volatiletech/null/v8"

"go.hollow.sh/serverservice/internal/models"
"github.com/metal-toolbox/fleetdb/internal/models"
)

// Bom provides a struct to map the bom_info table.
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/v1/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package serverservice
package fleetdbapi

import (
"context"
Expand All @@ -9,7 +9,7 @@ import (

var apiVersion = "v1"

// Client has the ability to talk to a hollow server service api server running at the given URI
// Client has the ability to talk to a fleetdb api server running at the given URI
type Client struct {
url string
authToken string
Expand Down Expand Up @@ -37,7 +37,7 @@ func NewClientWithToken(authToken, url string, doerClient Doer) (*Client, error)
return c, nil
}

// NewClient will return a server service client configured to talk to the given URL.
// NewClient will return a fleetdb client configured to talk to the given URL.
// This client will not set the authorization header for you automatically and is left to be handled by the Doer that is provided.
//
// Example:
Expand All @@ -53,7 +53,7 @@ func NewClientWithToken(authToken, url string, doerClient Doer) (*Client, error)
// EndpointParams: url.Values{"audience": []string{"HOLLOW_AUDIENCE_VALUE"}},
// }
//
// c, _ := serverservice.NewClient("HOLLOW_URI", oauthConfig.Client(ctx))
// c, _ := fleetdbapi.NewClient("HOLLOW_URI", oauthConfig.Client(ctx))
func NewClient(url string, doerClient Doer) (*Client, error) {
if url == "" {
return nil, newClientError("failed to initialize: no hollow api url provided")
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/v1/client_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package serverservice_test
package fleetdbapi_test

import (
"context"
Expand All @@ -9,7 +9,7 @@ import (

"github.com/stretchr/testify/assert"

serverservice "go.hollow.sh/serverservice/pkg/api/v1"
fleetdbapi "github.com/metal-toolbox/fleetdb/pkg/api/v1"
)

var (
Expand Down Expand Up @@ -48,7 +48,7 @@ func TestNewClientWithToken(t *testing.T) {
}

for _, tt := range testCases {
c, err := serverservice.NewClientWithToken(tt.authToken, tt.url, nil)
c, err := fleetdbapi.NewClientWithToken(tt.authToken, tt.url, nil)

if tt.expectError {
assert.Error(t, err, tt.testName)
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1/doc.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Package serverservice provides the v1 api for the server service
package serverservice
// Package fleetdbapi provides the v1 api for the fleetdb service
package fleetdbapi
2 changes: 1 addition & 1 deletion pkg/api/v1/errors.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package serverservice
package fleetdbapi

import (
"encoding/json"
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1/firmware.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package serverservice
package fleetdbapi

import (
"time"

"github.com/google/uuid"

"go.hollow.sh/serverservice/internal/models"
"github.com/metal-toolbox/fleetdb/internal/models"
)

// ComponentFirmwareVersion represents a firmware file
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1/firmware_list_params.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package serverservice
package fleetdbapi

import (
"net/url"

"github.com/volatiletech/sqlboiler/types"
"github.com/volatiletech/sqlboiler/v4/queries/qm"

"go.hollow.sh/serverservice/internal/models"
"github.com/metal-toolbox/fleetdb/internal/models"
)

// ComponentFirmwareVersionListParams allows you to filter the results
Expand Down
Loading

0 comments on commit f2a287d

Please sign in to comment.