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

Rename environment prefix, app name and test database name to fleetdb #8

Merged
merged 2 commits into from
Feb 20, 2024
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ 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 -test.v -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 node drain --insecure --host=localhost:26257

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=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')"

# Use the official Alpine image for a lean production container.
# https://hub.docker.com/_/alpine
Expand Down
22 changes: 11 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ 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
DEV_DB=${DB_STRING} dbname=fleetdb
TEST_DB=${DB_STRING} dbname=fleetdb_test
DOCKER_IMAGE := "ghcr.io/metal-toolbox/fleetdb"
PROJECT_NAME := fleetdb
REPO := "https://github.com/metal-toolbox/fleetdb.git"
Expand All @@ -14,7 +14,7 @@ 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 @@ -24,7 +24,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 @@ -60,16 +60,16 @@ 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:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ 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.
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

var (
appName = "serverservice"
appName = "fleetdb"
cfgFile string
logger *zap.SugaredLogger
)
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
2 changes: 1 addition & 1 deletion internal/dbtools/testtools.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

// 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 quickstart-dev.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: "3.9"

services:
serverservice:
fleetdb:
build:
context: .
dockerfile: Dockerfile.dev

serverservice-migrate:
fleetdb-migrate:
build:
context: .
dockerfile: Dockerfile.dev
10 changes: 5 additions & 5 deletions quickstart-tracing.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
version: '3.7'

services:
serverservice:
fleetdb:
depends_on:
- jaeger
environment:
- SERVERSERVICE_TRACING_ENABLED=true
- SERVERSERVICE_TRACING_ENVIRONMENT=dev-dockercompose
- SERVERSERVICE_TRACING_PROVIDER=jaeger
- SERVERSERVICE_TRACING_JAEGER_ENDPOINT=http://jaeger:14268/api/traces
- FLEETDB_TRACING_ENABLED=true
- FLEETDB_TRACING_ENVIRONMENT=dev-dockercompose
- FLEETDB_TRACING_PROVIDER=jaeger
- FLEETDB_TRACING_JAEGER_ENDPOINT=http://jaeger:14268/api/traces

jaeger:
image: jaegertracing/all-in-one:1.48.0
Expand Down
14 changes: 7 additions & 7 deletions quickstart.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
version: "3.9"

services:
serverservice:
fleetdb:
image: ghcr.io/metal-toolbox/fleetdb:latest
depends_on:
- crdb
- serverservice-migrate
- fleetdb-migrate
environment:
- SERVERSERVICE_OIDC_ENABLED=false
- SERVERSERVICE_CRDB_URI=postgresql://root@crdb:26257/defaultdb?sslmode=disable
- SERVERSERVICE_DB_ENCRYPTION_DRIVER=base64key://smGbjm71Nxd1Ig5FS0wj9SlbzAIrnolCz9bQQ6uAhl4=
- FLEETDB_OIDC_ENABLED=false
- FLEETDB_CRDB_URI=postgresql://root@crdb:26257/defaultdb?sslmode=disable
- FLEETDB_DB_ENCRYPTION_DRIVER=base64key://smGbjm71Nxd1Ig5FS0wj9SlbzAIrnolCz9bQQ6uAhl4=
ports:
- "8000:8000"
restart: unless-stopped
networks:
- hollow

serverservice-migrate:
fleetdb-migrate:
image: ghcr.io/metal-toolbox/fleetdb:latest
command:
migrate up
depends_on:
- crdb
environment:
- SERVERSERVICE_CRDB_URI=postgresql://root@crdb:26257/defaultdb?sslmode=disable
- FLEETDB_CRDB_URI=postgresql://root@crdb:26257/defaultdb?sslmode=disable
restart: on-failure
networks:
- hollow
Expand Down
2 changes: 1 addition & 1 deletion sqlboiler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pkgname = "models"
output = "internal/models"

[crdb]
dbname = "serverservice_test"
dbname = "fleetdb_test"
host = "localhost"
port = 26257
user = "root"
Expand Down
Loading