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 1 commit
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 .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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
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
18 changes: 9 additions & 9 deletions quickstart.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
version: "3.9"

services:
serverservice:
image: ghcr.io/metal-toolbox/hollow-serverservice:v0.16.0
fleetdb:
image: ghcr.io/metal-toolbox/fleetdb:v0.16.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for later: we'll want to update the version of FleetDB to 1.0 when we bring that live to production.

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:
image: ghcr.io/metal-toolbox/hollow-serverservice:v0.16.0
fleetdb-migrate:
image: ghcr.io/metal-toolboxfleetdb:v0.16.0
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