.ONESHELL : # Applies to every targets in the file! .ONESHELL instructs make to invoke a single instance of the shell and provide it with the entire recipe, regardless of how many lines it contains.
.SHELLFLAGS = -ec
########################################################################################################################
# Global Env Settings
########################################################################################################################
GO_WORKSPACE ?= /go/src/github.com/analogj/scrutiny
COLLECTOR_BINARY_NAME = scrutiny-collector-metrics
WEB_BINARY_NAME = scrutiny-web
LD_FLAGS =
STATIC_TAGS =
# enable multiarch docker image builds
DOCKER_TARGETARCH_BUILD_ARG =
i f d e f T A R G E T A R C H
DOCKER_TARGETARCH_BUILD_ARG := $( DOCKER_TARGETARCH_BUILD_ARG) --build-arg TARGETARCH = $( TARGETARCH)
e n d i f
# enable to build static binaries.
i f d e f S T A T I C
export CGO_ENABLED = 0
LD_FLAGS := $( LD_FLAGS) -extldflags= -static
STATIC_TAGS := $( STATIC_TAGS) -tags "static netgo"
e n d i f
i f d e f G O O S
COLLECTOR_BINARY_NAME := $( COLLECTOR_BINARY_NAME) -$( GOOS)
WEB_BINARY_NAME := $( WEB_BINARY_NAME) -$( GOOS)
LD_FLAGS := $( LD_FLAGS) -X main.goos= $( GOOS)
e n d i f
i f d e f G O A R C H
COLLECTOR_BINARY_NAME := $( COLLECTOR_BINARY_NAME) -$( GOARCH)
WEB_BINARY_NAME := $( WEB_BINARY_NAME) -$( GOARCH)
LD_FLAGS := $( LD_FLAGS) -X main.goarch= $( GOARCH)
e n d i f
i f d e f G O A R M
COLLECTOR_BINARY_NAME := $( COLLECTOR_BINARY_NAME) -$( GOARM)
WEB_BINARY_NAME := $( WEB_BINARY_NAME) -$( GOARM)
e n d i f
i f e q ( $( OS ) , W i n d o w s _ N T )
COLLECTOR_BINARY_NAME := $( COLLECTOR_BINARY_NAME) .exe
WEB_BINARY_NAME := $( WEB_BINARY_NAME) .exe
e n d i f
########################################################################################################################
# Binary
########################################################################################################################
.PHONY : all
all : binary -all
.PHONY : binary -all
binary-all : binary -collector binary -web
@echo "built binary-collector and binary-web targets"
.PHONY : binary -clean
binary-clean :
go clean
.PHONY : binary -dep
binary-dep :
go mod vendor
.PHONY : binary -test
binary-test : binary -dep
go test -v $( STATIC_TAGS) ./...
.PHONY : binary -test -coverage
binary-test-coverage : binary -dep
go test -coverprofile= coverage.txt -covermode= atomic -v $( STATIC_TAGS) ./...
.PHONY : binary -collector
binary-collector : binary -dep
go build -ldflags " $( LD_FLAGS) " -o $( COLLECTOR_BINARY_NAME) $( STATIC_TAGS) ./collector/cmd/collector-metrics/
i f n e q ( $( OS ) , W i n d o w s _ N T )
chmod +x $( COLLECTOR_BINARY_NAME)
file $( COLLECTOR_BINARY_NAME) || true
ldd $( COLLECTOR_BINARY_NAME) || true
./$( COLLECTOR_BINARY_NAME) || true
e n d i f
.PHONY : binary -web
binary-web : binary -dep
go build -ldflags " $( LD_FLAGS) " -o $( WEB_BINARY_NAME) $( STATIC_TAGS) ./webapp/backend/cmd/scrutiny/
i f n e q ( $( OS ) , W i n d o w s _ N T )
chmod +x $( WEB_BINARY_NAME)
file $( WEB_BINARY_NAME) || true
ldd $( WEB_BINARY_NAME) || true
./$( WEB_BINARY_NAME) || true
e n d i f
########################################################################################################################
# Binary
########################################################################################################################
.PHONY : binary -frontend
# reduce logging, disable angular-cli analytics for ci environment
binary-frontend : export NPM_CONFIG_LOGLEVEL = warn
binary-frontend : export NG_CLI_ANALYTICS = false
binary-frontend :
cd webapp/frontend
npm install -g @angular/cli@9.1.4
mkdir -p $( CURDIR) /dist
npm ci
npm run build:prod -- --output-path= $( CURDIR) /dist
.PHONY : binary -frontend -test -coverage
# reduce logging, disable angular-cli analytics for ci environment
binary-frontend-test-coverage :
cd webapp/frontend
npm ci
npx ng test --watch= false --browsers= ChromeHeadless --code-coverage
########################################################################################################################
# Docker
# NOTE: these docker make targets are only used for local development (not used by Github Actions/CI)
# NOTE: docker-web and docker-omnibus require `make binary-frontend` or frontend.tar.gz content in /dist before executing.
########################################################################################################################
.PHONY : docker -collector
docker-collector :
@echo "building collector docker image"
docker build $( DOCKER_TARGETARCH_BUILD_ARG) -f docker/Dockerfile.collector -t analogj/scrutiny-dev:collector .
.PHONY : docker -web
docker-web :
@echo "building web docker image"
docker build $( DOCKER_TARGETARCH_BUILD_ARG) -f docker/Dockerfile.web -t analogj/scrutiny-dev:web .
.PHONY : docker -omnibus
docker-omnibus :
@echo "building omnibus docker image"
docker build $( DOCKER_TARGETARCH_BUILD_ARG) -f docker/Dockerfile -t analogj/scrutiny-dev:omnibus .