2021-10-22 18:26:54 +00:00
.PHONY : build clean clean -assets e 2e -reset -db e 2e -serve e 2e -setup changelog db -reset db -backup db -restore
2016-09-05 21:58:49 +00:00
2019-08-13 17:32:23 +00:00
export GO111MODULE = on
2021-05-31 18:35:15 +00:00
PATH := $( shell npm bin) :$( PATH)
2017-01-30 19:37:27 +00:00
VERSION = $( shell git describe --tags --always --dirty)
2016-12-15 16:39:01 +00:00
BRANCH = $( shell git rev-parse --abbrev-ref HEAD)
REVISION = $( shell git rev-parse HEAD)
REVSHORT = $( shell git rev-parse --short HEAD)
USER = $( shell whoami)
2020-11-05 06:16:51 +00:00
DOCKER_IMAGE_NAME = fleetdm/fleet
2016-10-12 16:25:59 +00:00
2022-07-11 11:12:33 +00:00
i f d e f G O _ T E S T _ E X T R A _ F L A G S
GO_TEST_EXTRA_FLAGS_VAR := $( GO_TEST_EXTRA_FLAGS)
2022-02-14 19:38:53 +00:00
e l s e
2022-07-11 11:12:33 +00:00
GO_TEST_EXTRA_FLAGS_VAR :=
2022-02-14 19:38:53 +00:00
e n d i f
2022-07-11 11:12:33 +00:00
i f d e f G O _ B U I L D _ R A C E _ E N A B L E D
GO_BUILD_RACE_ENABLED_VAR := true
2022-02-14 19:38:53 +00:00
e l s e
2022-07-11 11:12:33 +00:00
GO_BUILD_RACE_ENABLED_VAR := false
2022-02-14 19:38:53 +00:00
e n d i f
2016-09-20 18:03:42 +00:00
i f n e q ( $( OS ) , W i n d o w s _ N T )
2016-12-15 16:39:01 +00:00
# If on macOS, set the shell to bash explicitly
2016-09-20 18:03:42 +00:00
ifeq ( $( shell uname) , Darwin)
SHELL := /bin/bash
endif
2016-08-10 05:15:44 +00:00
2016-12-15 16:39:01 +00:00
# The output binary name is different on Windows, so we're explicit here
2017-10-16 23:35:14 +00:00
OUTPUT = fleet
2016-08-10 05:15:44 +00:00
2016-12-15 16:39:01 +00:00
# To populate version metadata, we use unix tools to get certain data
GOVERSION = $( shell go version | awk '{print $$3}' )
2021-04-16 23:14:56 +00:00
NOW = $( shell date +"%Y-%m-%d" )
2016-12-15 16:39:01 +00:00
e l s e
# The output binary name is different on Windows, so we're explicit here
2017-10-16 23:35:14 +00:00
OUTPUT = fleet.exe
2016-09-20 02:37:47 +00:00
2016-12-15 16:39:01 +00:00
# To populate version metadata, we use windows tools to get the certain data
2016-09-20 02:37:47 +00:00
GOVERSION_CMD = "(go version).Split()[2]"
GOVERSION = $( shell powershell $( GOVERSION_CMD) )
2021-04-16 23:14:56 +00:00
NOW = $( shell powershell Get-Date -format "yyy-MM-dd" )
2016-09-04 05:13:42 +00:00
e n d i f
2016-09-19 22:54:57 +00:00
i f n d e f C I R C L E _ P R _ N U M B E R
2016-12-08 17:54:21 +00:00
DOCKER_IMAGE_TAG = ${ REVSHORT }
2016-09-19 22:54:57 +00:00
e l s e
2016-12-08 17:54:21 +00:00
DOCKER_IMAGE_TAG = dev-${ CIRCLE_PR_NUMBER } -${ REVSHORT }
2016-09-20 02:37:47 +00:00
e n d i f
2017-02-02 16:30:23 +00:00
i f d e f C I R C L E _ T A G
DOCKER_IMAGE_TAG = ${ CIRCLE_TAG }
e n d i f
2017-10-12 16:42:13 +00:00
KIT_VERSION = " \
2019-08-14 18:49:18 +00:00
-X github.com/kolide/kit/version.appName= ${ APP_NAME } \
-X github.com/kolide/kit/version.version= ${ VERSION } \
-X github.com/kolide/kit/version.branch= ${ BRANCH } \
-X github.com/kolide/kit/version.revision= ${ REVISION } \
-X github.com/kolide/kit/version.buildDate= ${ NOW } \
-X github.com/kolide/kit/version.buildUser= ${ USER } \
-X github.com/kolide/kit/version.goVersion= ${ GOVERSION } "
2017-10-12 16:42:13 +00:00
2016-09-20 02:37:47 +00:00
all : build
d e f i n e H E L P _ T E X T
Makefile commands
2017-12-20 23:41:19 +00:00
make deps - Install dependent programs and libraries
2019-07-29 16:31:42 +00:00
make generate - Generate and bundle required all code
make generate-go - Generate and bundle required go code
make generate-js - Generate and bundle required js code
2016-09-20 02:37:47 +00:00
make generate-dev - Generate and bundle required code in a watch loop
2021-03-05 02:16:20 +00:00
make clean - Clean all build artifacts
make clean-assets - Clean assets only
2016-09-20 02:37:47 +00:00
make build - Build the code
2017-01-30 16:34:29 +00:00
make package - Build rpm and deb packages for linux
2016-09-20 02:37:47 +00:00
make test - Run the full test suite
make test-go - Run the Go tests
make test-js - Run the JavaScript tests
2016-10-31 13:56:13 +00:00
make lint - Run all linters
2016-09-20 02:37:47 +00:00
make lint-go - Run the Go linters
make lint-js - Run the JavaScript linters
2016-10-31 13:56:13 +00:00
make lint-scss - Run the SCSS linters
2016-12-15 16:39:01 +00:00
make lint-ts - Run the TypeScript linters
2016-09-20 23:26:44 +00:00
2016-09-20 02:37:47 +00:00
e n d e f
help :
$( info $( HELP_TEXT) )
.prefix :
2017-10-16 23:35:14 +00:00
mkdir -p build/linux
mkdir -p build/darwin
2016-09-14 17:19:11 +00:00
2017-10-16 23:35:14 +00:00
.pre-build :
$( eval GOGC = off)
$( eval CGO_ENABLED = 0)
.pre-fleet :
2017-10-12 16:42:13 +00:00
$( eval APP_NAME = fleet)
2017-10-16 23:35:14 +00:00
2017-11-12 18:58:19 +00:00
.pre-fleetctl :
$( eval APP_NAME = fleetctl)
2018-05-08 23:56:44 +00:00
build : fleet fleetctl
2017-11-12 18:58:19 +00:00
fleet : .prefix .pre -build .pre -fleet
2022-07-11 11:12:33 +00:00
CGO_ENABLED = 1 go build -race= ${ GO_BUILD_RACE_ENABLED_VAR } -tags full,fts5,netgo -o build/${ OUTPUT } -ldflags ${ KIT_VERSION } ./cmd/fleet
2022-06-29 17:38:23 +00:00
2022-07-11 11:12:33 +00:00
fleet-dev : GO_BUILD_RACE_ENABLED_VAR =true
2022-06-29 17:38:23 +00:00
fleet-dev : fleet
2016-09-14 17:19:11 +00:00
2017-11-12 18:58:19 +00:00
fleetctl : .prefix .pre -build .pre -fleetctl
2022-07-11 11:12:33 +00:00
# Race requires cgo
$( eval CGO_ENABLED := $( shell [ [ " ${ GO_BUILD_RACE_ENABLED_VAR } " = "true" ] ] && echo 1 || echo 0) )
CGO_ENABLED = ${ CGO_ENABLED } go build -race= ${ GO_BUILD_RACE_ENABLED_VAR } -o build/fleetctl -ldflags ${ KIT_VERSION } ./cmd/fleetctl
fleetctl-dev : GO_BUILD_RACE_ENABLED_VAR =true
fleetctl-dev : fleetctl
2017-11-12 18:58:19 +00:00
2016-09-06 21:00:34 +00:00
lint-js :
2021-03-05 01:13:28 +00:00
yarn lint
2016-09-06 21:00:34 +00:00
lint-go :
2022-06-10 21:52:24 +00:00
golangci-lint run --skip-dirs ./node_modules --timeout 10m
2016-09-06 21:00:34 +00:00
2021-03-05 01:13:28 +00:00
lint : lint -go lint -js
2016-09-06 21:00:34 +00:00
2021-08-20 15:27:41 +00:00
dump-test-schema :
2021-08-24 20:24:52 +00:00
go run ./tools/dbutils ./server/datastore/mysql/schema.sql
2021-08-20 15:27:41 +00:00
2021-12-03 13:54:17 +00:00
test-go : dump -test -schema generate -mock
2022-07-11 11:12:33 +00:00
go test -tags full,fts5,netgo ${ GO_TEST_EXTRA_FLAGS_VAR } -parallel 8 -coverprofile= coverage.txt -covermode= atomic ./cmd/... ./ee/... ./orbit/pkg/... ./orbit/cmd/orbit ./pkg/... ./server/... ./tools/...
2017-01-04 21:59:17 +00:00
analyze-go :
2021-08-16 18:48:45 +00:00
go test -tags full,fts5,netgo -race -cover ./...
2017-01-04 21:59:17 +00:00
2016-09-06 21:00:34 +00:00
test-js :
2020-12-01 18:15:12 +00:00
npm test
2016-09-06 21:00:34 +00:00
2016-10-31 13:56:13 +00:00
test : lint test -go test -js
2016-09-04 05:13:42 +00:00
2021-03-05 02:16:20 +00:00
generate : clean -assets generate -js generate -go
2019-07-29 16:31:42 +00:00
2021-04-16 23:14:56 +00:00
generate-ci :
NODE_ENV = development webpack
make generate-go
2021-03-05 02:16:20 +00:00
generate-js : clean -assets .prefix
2017-01-19 15:24:10 +00:00
NODE_ENV = production webpack --progress --colors
2019-07-29 16:31:42 +00:00
generate-go : .prefix
2021-03-22 18:03:03 +00:00
go run github.com/kevinburke/go-bindata/go-bindata -pkg= bindata -tags full \
2020-03-30 02:22:04 +00:00
-o= server/bindata/generated.go \
frontend/templates/ assets/... server/mail/templates
2016-09-06 15:08:11 +00:00
2021-10-27 23:17:41 +00:00
# we first generate the webpack bundle so that bindata knows to atch the
2016-09-22 00:40:26 +00:00
# output bundle file. then, generate debug bindata source file. finally, we
# run webpack in watch mode to continuously re-generate the bundle
2016-09-06 15:08:11 +00:00
generate-dev : .prefix
2019-07-29 16:40:16 +00:00
NODE_ENV = development webpack --progress --colors
2021-03-22 18:03:03 +00:00
go run github.com/kevinburke/go-bindata/go-bindata -debug -pkg= bindata -tags full \
2020-03-30 02:22:04 +00:00
-o= server/bindata/generated.go \
frontend/templates/ assets/... server/mail/templates
2019-07-29 16:40:16 +00:00
NODE_ENV = development webpack --progress --colors --watch
2016-08-10 05:15:44 +00:00
2021-08-10 13:43:27 +00:00
generate-mock : .prefix
2021-12-03 13:54:17 +00:00
go install github.com/groob/mockimpl@latest
2022-07-01 11:08:03 +00:00
go generate github.com/fleetdm/fleet/v4/server/mock github.com/fleetdm/fleet/v4/server/mock/mockresult
2021-08-10 13:43:27 +00:00
2022-12-23 16:05:16 +00:00
generate-doc : .prefix
go generate github.com/fleetdm/fleet/v4/server/fleet
2019-07-29 16:31:42 +00:00
deps : deps -js deps -go
deps-js :
2017-02-10 18:22:26 +00:00
yarn
2019-07-29 16:31:42 +00:00
deps-go :
2019-08-13 17:32:23 +00:00
go mod download
2022-07-12 21:21:15 +00:00
go get github.com/quasilyte/go-ruleguard/dsl
2016-08-10 05:15:44 +00:00
2021-02-05 17:48:06 +00:00
migration :
go run github.com/fleetdm/goose/cmd/goose -dir server/datastore/mysql/migrations/tables create $( name)
2022-04-05 16:56:15 +00:00
gofmt -w server/datastore/mysql/migrations/tables/*_$( name) *.go
2021-02-05 17:48:06 +00:00
2021-03-05 02:16:20 +00:00
clean : clean -assets
2016-09-20 02:37:47 +00:00
rm -rf build vendor
rm -f assets/bundle.js
2016-08-10 05:15:44 +00:00
2021-03-05 02:16:20 +00:00
clean-assets :
git clean -fx assets
2018-08-08 23:21:49 +00:00
docker-build-release : xp -fleet xp -fleetctl
2017-02-13 22:57:16 +00:00
docker build -t " ${ DOCKER_IMAGE_NAME } : ${ DOCKER_IMAGE_TAG } " .
2020-11-05 05:36:25 +00:00
docker tag " ${ DOCKER_IMAGE_NAME } : ${ DOCKER_IMAGE_TAG } " fleetdm/fleet:${ VERSION }
docker tag " ${ DOCKER_IMAGE_NAME } : ${ DOCKER_IMAGE_TAG } " fleetdm/fleet:latest
2018-01-23 21:31:42 +00:00
docker-push-release : docker -build -release
2017-02-13 22:57:16 +00:00
docker push " ${ DOCKER_IMAGE_NAME } : ${ DOCKER_IMAGE_TAG } "
2020-11-05 05:36:25 +00:00
docker push fleetdm/fleet:${ VERSION }
docker push fleetdm/fleet:latest
2016-09-20 23:26:44 +00:00
2022-07-11 12:49:13 +00:00
fleetctl-docker : xp -fleetctl
docker build -t fleetdm/fleetctl --platform= linux/amd64 -f tools/fleetctl-docker/Dockerfile .
2018-05-23 19:19:01 +00:00
.pre-binary-bundle :
2017-10-18 16:45:01 +00:00
rm -rf build/binary-bundle
mkdir -p build/binary-bundle/linux
mkdir -p build/binary-bundle/darwin
2018-05-23 19:19:01 +00:00
xp-fleet : .pre -binary -bundle .pre -fleet generate
2021-08-16 18:48:45 +00:00
CGO_ENABLED = 1 GOOS = linux go build -tags full,fts5,netgo -trimpath -o build/binary-bundle/linux/fleet -ldflags ${ KIT_VERSION } ./cmd/fleet
CGO_ENABLED = 1 GOOS = darwin go build -tags full,fts5,netgo -trimpath -o build/binary-bundle/darwin/fleet -ldflags ${ KIT_VERSION } ./cmd/fleet
CGO_ENABLED = 1 GOOS = windows go build -tags full,fts5,netgo -trimpath -o build/binary-bundle/windows/fleet.exe -ldflags ${ KIT_VERSION } ./cmd/fleet
2018-05-23 19:19:01 +00:00
2020-09-27 16:45:22 +00:00
xp-fleetctl : .pre -binary -bundle .pre -fleetctl generate -go
2021-10-27 23:17:41 +00:00
CGO_ENABLED = 0 GOOS = linux go build -trimpath -o build/binary-bundle/linux/fleetctl -ldflags ${ KIT_VERSION } ./cmd/fleetctl
CGO_ENABLED = 0 GOOS = darwin go build -trimpath -o build/binary-bundle/darwin/fleetctl -ldflags ${ KIT_VERSION } ./cmd/fleetctl
CGO_ENABLED = 0 GOOS = windows go build -trimpath -o build/binary-bundle/windows/fleetctl.exe -ldflags ${ KIT_VERSION } ./cmd/fleetctl
2018-05-23 19:19:01 +00:00
binary-bundle : xp -fleet xp -fleetctl
2020-11-13 02:03:01 +00:00
cd build/binary-bundle && zip -r fleet.zip darwin/ linux/ windows/
2021-03-31 12:33:00 +00:00
cd build/binary-bundle && mkdir fleetctl-macos && cp darwin/fleetctl fleetctl-macos && tar -czf fleetctl-macos.tar.gz fleetctl-macos
cd build/binary-bundle && mkdir fleetctl-linux && cp linux/fleetctl fleetctl-linux && tar -czf fleetctl-linux.tar.gz fleetctl-linux
2020-12-02 16:24:34 +00:00
cd build/binary-bundle && mkdir fleetctl-windows && cp windows/fleetctl.exe fleetctl-windows && tar -czf fleetctl-windows.tar.gz fleetctl-windows
2021-03-31 12:33:00 +00:00
cd build/binary-bundle && cp windows/fleetctl.exe . && zip fleetctl.exe.zip fleetctl.exe
2020-12-02 16:24:34 +00:00
cd build/binary-bundle && shasum -a 256 fleet.zip fleetctl.exe.zip fleetctl-macos.tar.gz fleetctl-windows.tar.gz fleetctl-linux.tar.gz
2020-11-13 02:03:01 +00:00
2021-06-25 21:56:01 +00:00
.pre-binary-arch :
i f n d e f G O O S
@echo "GOOS is Empty. Try use to see valid GOOS/GOARCH platform: go tool dist list. Ex.: make binary-arch GOOS=linux GOARCH=arm64"
@exit 1;
e n d i f
i f n d e f G O A R C H
@echo "GOARCH is Empty. Try use to see valid GOOS/GOARCH platform: go tool dist list. Ex.: make binary-arch GOOS=linux GOARCH=arm64"
@exit 1;
e n d i f
binary-arch : .pre -binary -arch .pre -binary -bundle .pre -fleet
mkdir -p build/binary-bundle/${ GOARCH } -${ GOOS }
2021-08-16 18:48:45 +00:00
CGO_ENABLED = 1 GOARCH = ${ GOARCH } GOOS = ${ GOOS } go build -tags full,fts5,netgo -o build/binary-bundle/${ GOARCH } -${ GOOS } /fleet -ldflags ${ KIT_VERSION } ./cmd/fleet
CGO_ENABLED = 0 GOARCH = ${ GOARCH } GOOS = ${ GOOS } go build -tags full,fts5,netgo -o build/binary-bundle/${ GOARCH } -${ GOOS } /fleetctl -ldflags ${ KIT_VERSION } ./cmd/fleetctl
2021-06-25 21:56:01 +00:00
cd build/binary-bundle/${ GOARCH } -${ GOOS } && tar -czf fleetctl-${ GOARCH } -${ GOOS } .tar.gz fleetctl fleet
2021-03-11 23:55:58 +00:00
# Drop, create, and migrate the e2e test database
e2e-reset-db :
Add read replica testing helpers and fix non-sso login bug (#4908)
not set on the INSERT.
- OUT: Only sets the ID on the passed session and returns it. (`CreatedAt`, `AccessedAt`, are not set.)
New version:
```go
func (ds *Datastore) NewSession(ctx context.Context, userID uint, sessionKey string) (*fleet.Session, error) {
sqlStatement := `
INSERT INTO sessions (
user_id,
` + "`key`" + `
)
VALUES(?,?)
`
result, err := ds.writer.ExecContext(ctx, sqlStatement, userID, sessionKey)
if err != nil {
return nil, ctxerr.Wrap(ctx, err, "inserting session")
}
id, _ := result.LastInsertId() // cannot fail with the mysql driver
return ds.sessionByID(ctx, ds.writer, uint(id))
}
```
- IN: Define arguments that are truly used when creating a session.
- OUT: Load and return the fleet.Session struct with all values set (using the `ds.writer` to support read replicas correctly).
PS: The new `NewSession` version mimics what we already do with other entities, like policies (`Datastore.NewGlobalPolicy`).
2022-04-04 23:52:05 +00:00
docker-compose exec -T mysql_test bash -c 'echo "drop database if exists e2e; create database e2e;" | MYSQL_PWD=toor mysql -uroot'
2021-06-07 01:10:58 +00:00
./build/fleet prepare db --mysql_address= localhost:3307 --mysql_username= root --mysql_password= toor --mysql_database= e2e
2021-03-11 23:55:58 +00:00
e2e-setup :
2021-06-09 18:56:59 +00:00
./build/fleetctl config set --context e2e --address https://localhost:8642 --tls-skip-verify true
2022-05-18 17:03:00 +00:00
./build/fleetctl setup --context e2e --email= admin@example.com --password= password123# --org-name= 'Fleet Test' --name Admin
./build/fleetctl user create --context e2e --email= maintainer@example.com --name maintainer --password= password123# --global-role= maintainer
./build/fleetctl user create --context e2e --email= observer@example.com --name observer --password= password123# --global-role= observer
2021-06-24 20:42:29 +00:00
./build/fleetctl user create --context e2e --email= sso_user@example.com --name "SSO user" --sso= true
2021-03-11 23:55:58 +00:00
2022-06-23 15:01:37 +00:00
# Setup e2e test environment and pre-populate database with software and vulnerabilities fixtures.
#
# Use in lieu of `e2e-setup` for tests that depend on these fixtures
e2e-setup-with-software :
curl 'https://localhost:8642/api/v1/setup' \
--data-raw '{"server_url":"https://localhost:8642","org_info":{"org_name":"Fleet Test"},"admin":{"admin":true,"email":"admin@example.com","name":"Admin","password":"password123#","password_confirmation":"password123#"}}' \
--compressed \
--insecure
./tools/backup_db/restore_e2e_software_test.sh
2021-12-24 20:18:00 +00:00
e2e-serve-free : e 2e -reset -db
2021-12-03 17:44:57 +00:00
./build/fleet serve --mysql_address= localhost:3307 --mysql_username= root --mysql_password= toor --mysql_database= e2e --server_address= 0.0.0.0:8642
2021-06-01 00:07:51 +00:00
2021-12-24 20:18:00 +00:00
e2e-serve-premium : e 2e -reset -db
2021-12-03 17:44:57 +00:00
./build/fleet serve --dev_license --mysql_address= localhost:3307 --mysql_username= root --mysql_password= toor --mysql_database= e2e --server_address= 0.0.0.0:8642
2021-06-01 00:07:51 +00:00
2022-06-23 15:01:37 +00:00
# Associate a host with a Fleet Desktop token.
#
# Usage:
# make e2e-set-desktop-token host_id=1 token=foo
e2e-set-desktop-token :
docker-compose exec -T mysql_test bash -c 'echo "INSERT INTO e2e.host_device_auth (host_id, token) VALUES ($(host_id), \"$(token)\") ON DUPLICATE KEY UPDATE token=VALUES(token)" | MYSQL_PWD=toor mysql -uroot'
2021-08-25 22:14:24 +00:00
changelog :
2022-04-25 21:54:25 +00:00
sh -c "find changes -type f | grep -v .keep | xargs -I {} sh -c 'grep \"\S\" {}; echo' > new-CHANGELOG.md"
2021-08-25 22:14:24 +00:00
sh -c "cat new-CHANGELOG.md CHANGELOG.md > tmp-CHANGELOG.md && rm new-CHANGELOG.md && mv tmp-CHANGELOG.md CHANGELOG.md"
sh -c "git rm changes/*"
2021-10-22 18:26:54 +00:00
2021-12-20 01:38:10 +00:00
changelog-orbit :
sh -c "find orbit/changes -type file | grep -v .keep | xargs -I {} sh -c 'grep \"\S\" {}; echo' > new-CHANGELOG.md"
sh -c "cat new-CHANGELOG.md orbit/CHANGELOG.md > tmp-CHANGELOG.md && rm new-CHANGELOG.md && mv tmp-CHANGELOG.md orbit/CHANGELOG.md"
sh -c "git rm orbit/changes/*"
2021-10-22 18:26:54 +00:00
###
# Development DB commands
###
# Reset the development DB
db-reset :
Add read replica testing helpers and fix non-sso login bug (#4908)
not set on the INSERT.
- OUT: Only sets the ID on the passed session and returns it. (`CreatedAt`, `AccessedAt`, are not set.)
New version:
```go
func (ds *Datastore) NewSession(ctx context.Context, userID uint, sessionKey string) (*fleet.Session, error) {
sqlStatement := `
INSERT INTO sessions (
user_id,
` + "`key`" + `
)
VALUES(?,?)
`
result, err := ds.writer.ExecContext(ctx, sqlStatement, userID, sessionKey)
if err != nil {
return nil, ctxerr.Wrap(ctx, err, "inserting session")
}
id, _ := result.LastInsertId() // cannot fail with the mysql driver
return ds.sessionByID(ctx, ds.writer, uint(id))
}
```
- IN: Define arguments that are truly used when creating a session.
- OUT: Load and return the fleet.Session struct with all values set (using the `ds.writer` to support read replicas correctly).
PS: The new `NewSession` version mimics what we already do with other entities, like policies (`Datastore.NewGlobalPolicy`).
2022-04-04 23:52:05 +00:00
docker-compose exec -T mysql bash -c 'echo "drop database if exists fleet; create database fleet;" | MYSQL_PWD=toor mysql -uroot'
2021-10-22 18:26:54 +00:00
./build/fleet prepare db --dev
# Back up the development DB to file
db-backup :
./tools/backup_db/backup.sh
# Restore the development DB from file
db-restore :
2021-10-27 23:17:41 +00:00
./tools/backup_db/restore.sh
2022-03-15 19:04:12 +00:00
2022-05-13 10:15:29 +00:00
# Generate osqueryd.app.tar.gz bundle from osquery.io.
2022-03-15 19:04:12 +00:00
#
# Usage:
# make osqueryd-app-tar-gz version=5.1.0 out-path=.
osqueryd-app-tar-gz :
i f n e q ( $( shell uname ) , D a r w i n )
@echo "Makefile target osqueryd-app-tar-gz is only supported on macOS"
@exit 1
e n d i f
$( eval TMP_DIR := $( shell mktemp -d) )
2022-06-13 15:04:21 +00:00
curl -L https://github.com/osquery/osquery/releases/download/$( version) /osquery-$( version) .pkg --output $( TMP_DIR) /osquery-$( version) .pkg
2022-03-15 19:04:12 +00:00
pkgutil --expand $( TMP_DIR) /osquery-$( version) .pkg $( TMP_DIR) /osquery_pkg_expanded
rm -rf $( TMP_DIR) /osquery_pkg_payload_expanded
mkdir -p $( TMP_DIR) /osquery_pkg_payload_expanded
tar xf $( TMP_DIR) /osquery_pkg_expanded/Payload --directory $( TMP_DIR) /osquery_pkg_payload_expanded
2022-05-13 10:15:29 +00:00
$( TMP_DIR) /osquery_pkg_payload_expanded/opt/osquery/lib/osquery.app/Contents/MacOS/osqueryd --version
2022-03-15 19:04:12 +00:00
tar czf $( out-path) /osqueryd.app.tar.gz -C $( TMP_DIR) /osquery_pkg_payload_expanded/opt/osquery/lib osquery.app
rm -r $( TMP_DIR)
2022-03-21 17:53:53 +00:00
# Build and generate desktop.app.tar.gz bundle.
#
# Usage:
# FLEET_DESKTOP_APPLE_AUTHORITY=foo FLEET_DESKTOP_VERSION=0.0.1 make desktop-app-tar-gz
2022-05-04 14:14:12 +00:00
#
# Output: desktop.app.tar.gz
2022-03-21 17:53:53 +00:00
desktop-app-tar-gz :
i f n e q ( $( shell uname ) , D a r w i n )
@echo "Makefile target desktop-app-tar-gz is only supported on macOS"
@exit 1
e n d i f
go run ./tools/desktop macos
2022-04-01 20:28:51 +00:00
2022-05-04 14:14:12 +00:00
FLEET_DESKTOP_VERSION ?= unknown
2022-04-01 20:28:51 +00:00
# Build desktop executable for Windows.
#
# Usage:
# FLEET_DESKTOP_VERSION=0.0.1 make desktop-windows
2022-05-04 14:14:12 +00:00
#
# Output: fleet-desktop.exe
2022-04-01 20:28:51 +00:00
desktop-windows :
2022-05-04 14:14:12 +00:00
GOOS = windows GOARCH = amd64 go build -ldflags " -H=windowsgui -X=main.version= $( FLEET_DESKTOP_VERSION) " -o fleet-desktop.exe ./orbit/cmd/desktop
# Build desktop executable for Linux.
#
# Usage:
# FLEET_DESKTOP_VERSION=0.0.1 make desktop-linux
#
# Output: desktop.tar.gz
desktop-linux :
docker build -f Dockerfile-desktop-linux -t desktop-linux-builder .
docker run --rm -v $( shell pwd ) :/output desktop-linux-builder /bin/bash -c " \
mkdir /output/fleet-desktop && \
go build -o /output/fleet-desktop/fleet-desktop -ldflags " -X=main.version= $( FLEET_DESKTOP_VERSION) " /usr/src/fleet/orbit/cmd/desktop && \
cp /usr/lib/x86_64-linux-gnu/libayatana-appindicator3.so.1 \
/usr/lib/x86_64-linux-gnu/libayatana-ido3-0.4.so.0 \
/usr/lib/x86_64-linux-gnu/libayatana-indicator3.so.7 \
/lib/x86_64-linux-gnu/libm.so.6 \
/usr/lib/x86_64-linux-gnu/libdbusmenu-gtk3.so.4 \
/usr/lib/x86_64-linux-gnu/libdbusmenu-glib.so.4 \
/output/fleet-desktop && cd /output && \
tar czf desktop.tar.gz fleet-desktop && \
rm -r fleet-desktop"
Add read replica testing helpers and fix non-sso login bug (#4908)
not set on the INSERT.
- OUT: Only sets the ID on the passed session and returns it. (`CreatedAt`, `AccessedAt`, are not set.)
New version:
```go
func (ds *Datastore) NewSession(ctx context.Context, userID uint, sessionKey string) (*fleet.Session, error) {
sqlStatement := `
INSERT INTO sessions (
user_id,
` + "`key`" + `
)
VALUES(?,?)
`
result, err := ds.writer.ExecContext(ctx, sqlStatement, userID, sessionKey)
if err != nil {
return nil, ctxerr.Wrap(ctx, err, "inserting session")
}
id, _ := result.LastInsertId() // cannot fail with the mysql driver
return ds.sessionByID(ctx, ds.writer, uint(id))
}
```
- IN: Define arguments that are truly used when creating a session.
- OUT: Load and return the fleet.Session struct with all values set (using the `ds.writer` to support read replicas correctly).
PS: The new `NewSession` version mimics what we already do with other entities, like policies (`Datastore.NewGlobalPolicy`).
2022-04-04 23:52:05 +00:00
# db-replica-setup setups one main and one read replica MySQL instance for dev/testing.
# - Assumes the docker containers are already running (tools/mysql-replica-testing/docker-compose.yml)
# - MySQL instance listening on 3308 is the main instance.
# - MySQL instance listening on 3309 is the read instance.
# - Sets a delay of 1s for replication.
db-replica-setup :
$( eval MYSQL_REPLICATION_USER := replicator)
$( eval MYSQL_REPLICATION_PASSWORD := rotacilper)
MYSQL_PWD = toor mysql --host 127.0.0.1 --port 3309 -uroot -AN -e "stop slave; reset slave all;"
MYSQL_PWD = toor mysql --host 127.0.0.1 --port 3308 -uroot -AN -e " drop user if exists ' $( MYSQL_REPLICATION_USER) '; create user ' $( MYSQL_REPLICATION_USER) '@'%'; grant replication slave on *.* to ' $( MYSQL_REPLICATION_USER) '@'%' identified by ' $( MYSQL_REPLICATION_PASSWORD) '; flush privileges; "
$( eval MAIN_POSITION := $( shell MYSQL_PWD = toor mysql --host 127.0.0.1 --port 3308 -uroot -e 'show master status \G' | grep Position | grep -o '[0-9]*' ) )
$( eval MAIN_FILE := $( shell MYSQL_PWD = toor mysql --host 127.0.0.1 --port 3308 -uroot -e 'show master status \G' | grep File | sed -n -e 's/^.*: //p' ) )
MYSQL_PWD = toor mysql --host 127.0.0.1 --port 3309 -uroot -AN -e " change master to master_host='mysql_main',master_user=' $( MYSQL_REPLICATION_USER) ',master_password=' $( MYSQL_REPLICATION_PASSWORD) ',master_log_file=' $( MAIN_FILE) ',master_log_pos= $( MAIN_POSITION) ; "
MYSQL_PWD = toor mysql --host 127.0.0.1 --port 3309 -uroot -AN -e "change master to master_delay=1;"
MYSQL_PWD = toor mysql --host 127.0.0.1 --port 3309 -uroot -AN -e "start slave;"
# db-replica-reset resets the main MySQL instance.
db-replica-reset : fleet
MYSQL_PWD = toor mysql --host 127.0.0.1 --port 3308 -uroot -e "drop database if exists fleet; create database fleet;"
FLEET_MYSQL_ADDRESS = 127.0.0.1:3308 ./build/fleet prepare db --dev
# db-replica-run runs fleet serve with one main and one read MySQL instance.
db-replica-run : fleet
2022-12-23 16:05:16 +00:00
FLEET_MYSQL_ADDRESS = 127.0.0.1:3308 FLEET_MYSQL_READ_REPLICA_ADDRESS = 127.0.0.1:3309 FLEET_MYSQL_READ_REPLICA_USERNAME = fleet FLEET_MYSQL_READ_REPLICA_DATABASE = fleet FLEET_MYSQL_READ_REPLICA_PASSWORD = insecure ./build/fleet serve --dev --dev_license