Skip to content

Commit

Permalink
Build: simplify make targets to just run every time (#5411)
Browse files Browse the repository at this point in the history
* run the make targets regardless of file timestamps and changes, just run them every time.

Signed-off-by: Edward Welch <edward.welch@grafana.com>

* attempt #2

Signed-off-by: Edward Welch <edward.welch@grafana.com>

* don't need GO_FILES anymore

Signed-off-by: Edward Welch <edward.welch@grafana.com>

* remove all the mod=vendor flags required as we transitioned through go versions 13/14/15

Signed-off-by: Edward Welch <edward.welch@grafana.com>

* changing drone deps because check-generated-files removes protos and I guess this all happens in the same place at the same time in drone.

Signed-off-by: Edward Welch <edward.welch@grafana.com>

* fix rebase

Signed-off-by: Edward Welch <edward.welch@grafana.com>
  • Loading branch information
slim-bean authored Feb 22, 2022
1 parent c80244a commit 4db3e59
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .drone/drone.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ local manifest(apps) = pipeline('manifest') {
image: 'koalaman/shellcheck-alpine:stable',
commands: ['apk add make bash && make lint-scripts'],
},
make('loki', container=false) { depends_on: ['clone'] },
make('loki', container=false) { depends_on: ['clone', 'check-generated-files'] },
make('validate-example-configs', container=false) { depends_on: ['loki'] },
make('check-example-config-doc', container=false) { depends_on: ['clone'] },
],
Expand Down
3 changes: 2 additions & 1 deletion .drone/drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ steps:
- make BUILD_IN_CONTAINER=false loki
depends_on:
- clone
- check-generated-files
image: grafana/loki-build-image:0.20.0
name: loki
- commands:
Expand Down Expand Up @@ -1064,6 +1065,6 @@ kind: secret
name: deploy_config
---
kind: signature
hmac: ca18b0336abbfa2af076bcf301c13450ce1a8cdad68b0d7c4a5a3e6fbb6a3140
hmac: 6d010031b5c18947ac4710106d06f119e77d715ddc687983227700254b27e6d8

...
81 changes: 31 additions & 50 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,6 @@

SHELL = /usr/bin/env bash

# Empty value = no -mod parameter is used.
# If not empty, GOMOD is passed to -mod= parameter.
# In Go 1.13, "readonly" and "vendor" are accepted.
# In Go 1.14, "readonly", "vendor" and "mod" values are accepted.
# If no value is specified, defaults to "vendor".
#
# Can be used from command line by using "GOMOD= make" (empty = no -mod parameter), or "GOMOD=vendor make" (default).

GOMOD ?= vendor
ifeq ($(strip $(GOMOD)),) # Is empty?
MOD_FLAG=
GOLANGCI_ARG=
else
MOD_FLAG=-mod=$(GOMOD)
GOLANGCI_ARG=--modules-download-mode=$(GOMOD)
endif

GOTEST ?= go test

#############
Expand Down Expand Up @@ -59,20 +42,16 @@ GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
# 'make: Entering directory '/src/loki' phase.
DONT_FIND := -name tools -prune -o -name vendor -prune -o -name .git -prune -o -name .cache -prune -o -name .pkg -prune -o

# These are all the application files, they are included in the various binary rules as dependencies
# to make sure binaries are rebuilt if any source files change.
APP_GO_FILES := $(shell find . $(DONT_FIND) -name .y.go -prune -o -name .pb.go -prune -o -name cmd -prune -o -type f -name '*.go' -print)

# Build flags
VPREFIX := github.com/grafana/loki/pkg/util/build
GO_LDFLAGS := -X $(VPREFIX).Branch=$(GIT_BRANCH) -X $(VPREFIX).Version=$(IMAGE_TAG) -X $(VPREFIX).Revision=$(GIT_REVISION) -X $(VPREFIX).BuildUser=$(shell whoami)@$(shell hostname) -X $(VPREFIX).BuildDate=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
GO_FLAGS := -ldflags "-extldflags \"-static\" -s -w $(GO_LDFLAGS)" -tags netgo $(MOD_FLAG)
DYN_GO_FLAGS := -ldflags "-s -w $(GO_LDFLAGS)" -tags netgo $(MOD_FLAG)
GO_FLAGS := -ldflags "-extldflags \"-static\" -s -w $(GO_LDFLAGS)" -tags netgo
DYN_GO_FLAGS := -ldflags "-s -w $(GO_LDFLAGS)" -tags netgo
# Per some websites I've seen to add `-gcflags "all=-N -l"`, the gcflags seem poorly if at all documented
# the best I could dig up is -N disables optimizations and -l disables inlining which should make debugging match source better.
# Also remove the -s and -w flags present in the normal build which strip the symbol table and the DWARF symbol table.
DEBUG_GO_FLAGS := -gcflags "all=-N -l" -ldflags "-extldflags \"-static\" $(GO_LDFLAGS)" -tags netgo $(MOD_FLAG)
DYN_DEBUG_GO_FLAGS := -gcflags "all=-N -l" -ldflags "$(GO_LDFLAGS)" -tags netgo $(MOD_FLAG)
DEBUG_GO_FLAGS := -gcflags "all=-N -l" -ldflags "-extldflags \"-static\" $(GO_LDFLAGS)" -tags netgo
DYN_DEBUG_GO_FLAGS := -gcflags "all=-N -l" -ldflags "$(GO_LDFLAGS)" -tags netgo
# Docker mount flag, ignored on native docker host. see (https://docs.docker.com/docker-for-mac/osxfs-caching/#delegated)
MOUNT_FLAGS := :delegated

Expand Down Expand Up @@ -148,47 +127,49 @@ check-generated-files: yacc ragel protos clients/pkg/promtail/server/ui/assets_v
##########
# Logcli #
##########

logcli: yacc ragel cmd/logcli/logcli
.PHONY: cmd/logcli/logcli
logcli: cmd/logcli/logcli

logcli-image:
$(SUDO) docker build -t $(IMAGE_PREFIX)/logcli:$(IMAGE_TAG) -f cmd/logcli/Dockerfile .

cmd/logcli/logcli: $(APP_GO_FILES) cmd/logcli/main.go
CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D)
cmd/logcli/logcli:
CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./cmd/logcli
$(NETGO_CHECK)

########
# Loki #
########

.PHONY: cmd/loki/loki cmd/loki/loki-debug
loki: cmd/loki/loki
loki-debug: cmd/loki/loki-debug

cmd/loki/loki: $(APP_GO_FILES) cmd/loki/main.go
cmd/loki/loki:
CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D)
$(NETGO_CHECK)

cmd/loki/loki-debug: $(APP_GO_FILES) cmd/loki/main.go
cmd/loki/loki-debug:
CGO_ENABLED=0 go build $(DEBUG_GO_FLAGS) -o $@ ./$(@D)
$(NETGO_CHECK)

###############
# Loki-Canary #
###############

.PHONY: cmd/loki-canary/loki-canary
loki-canary: cmd/loki-canary/loki-canary

cmd/loki-canary/loki-canary: $(APP_GO_FILES) cmd/loki-canary/main.go
cmd/loki-canary/loki-canary:
CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D)
$(NETGO_CHECK)

#################
# Loki-QueryTee #
#################
.PHONY: cmd/querytee/querytee
loki-querytee: cmd/querytee/querytee

loki-querytee: $(APP_GO_FILES) cmd/querytee/main.go
CGO_ENABLED=0 go build $(GO_FLAGS) -o ./cmd/querytee/$@ ./cmd/querytee/
cmd/querytee/querytee:
CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D)
$(NETGO_CHECK)

############
Expand All @@ -209,33 +190,33 @@ PROMTAIL_GO_FLAGS = $(DYN_GO_FLAGS)
PROMTAIL_DEBUG_GO_FLAGS = $(DYN_DEBUG_GO_FLAGS)
endif
endif

promtail: yacc ragel clients/cmd/promtail/promtail
promtail-debug: yacc ragel clients/cmd/promtail/promtail-debug
.PHONY: clients/cmd/promtail/promtail clients/cmd/promtail/promtail-debug
promtail: clients/cmd/promtail/promtail
promtail-debug: clients/cmd/promtail/promtail-debug

promtail-clean-assets:
rm -rf clients/pkg/promtail/server/ui/assets_vfsdata.go

# Rule to generate promtail static assets file
$(PROMTAIL_GENERATED_FILE): $(PROMTAIL_UI_FILES)
@echo ">> writing assets"
GOFLAGS="$(MOD_FLAG)" GOOS=$(shell go env GOHOSTOS) go generate -x -v ./clients/pkg/promtail/server/ui
GOOS=$(shell go env GOHOSTOS) go generate -x -v ./clients/pkg/promtail/server/ui

clients/cmd/promtail/promtail: $(APP_GO_FILES) $(PROMTAIL_GENERATED_FILE) clients/cmd/promtail/main.go
clients/cmd/promtail/promtail:
CGO_ENABLED=$(PROMTAIL_CGO) go build $(PROMTAIL_GO_FLAGS) -o $@ ./$(@D)
$(NETGO_CHECK)

clients/cmd/promtail/promtail-debug: $(APP_GO_FILES) clients/pkg/promtail/server/ui/assets_vfsdata.go clients/cmd/promtail/main.go
clients/cmd/promtail/promtail-debug:
CGO_ENABLED=$(PROMTAIL_CGO) go build $(PROMTAIL_DEBUG_GO_FLAGS) -o $@ ./$(@D)
$(NETGO_CHECK)

###############
# Migrate #
###############

.PHONY: cmd/migrate/migrate
migrate: cmd/migrate/migrate

cmd/migrate/migrate: $(APP_GO_FILES) cmd/migrate/main.go
cmd/migrate/migrate:
CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D)
$(NETGO_CHECK)

Expand Down Expand Up @@ -268,15 +249,15 @@ publish: packages
# To run this efficiently on your workstation, run this from the root dir:
# docker run --rm --tty -i -v $(pwd)/.cache:/go/cache -v $(pwd)/.pkg:/go/pkg -v $(pwd):/src/loki grafana/loki-build-image:0.17.0 lint
lint:
GO111MODULE=on GOGC=10 golangci-lint run -v $(GOLANGCI_ARG)
GO111MODULE=on GOGC=10 golangci-lint run -v
faillint -paths "sync/atomic=go.uber.org/atomic" ./...

########
# Test #
########

test: all
GOGC=10 $(GOTEST) -covermode=atomic -coverprofile=coverage.txt $(MOD_FLAG) -p=4 ./...
GOGC=10 $(GOTEST) -covermode=atomic -coverprofile=coverage.txt -p=4 ./...

#########
# Clean #
Expand All @@ -297,7 +278,7 @@ clean:
rm -rf clients/cmd/fluent-bit/out_grafana_loki.h
rm -rf clients/cmd/fluent-bit/out_grafana_loki.so
rm -rf cmd/migrate/migrate
go clean $(MOD_FLAG) ./...
go clean ./...

#########
# YACCs #
Expand Down Expand Up @@ -399,7 +380,7 @@ docker-driver: docker-driver-clean
$(build-rootfs)
docker plugin create $(LOKI_DOCKER_DRIVER):main$(PLUGIN_ARCH) clients/cmd/docker-driver

clients/cmd/docker-driver/docker-driver: $(APP_GO_FILES)
clients/cmd/docker-driver/docker-driver:
CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D)
$(NETGO_CHECK)

Expand Down Expand Up @@ -571,8 +552,8 @@ endif
########

benchmark-store:
go run $(MOD_FLAG) ./pkg/storage/hack/main.go
$(GOTEST) $(MOD_FLAG) ./pkg/storage/ -bench=. -benchmem -memprofile memprofile.out -cpuprofile cpuprofile.out -trace trace.out
go run ./pkg/storage/hack/main.go
$(GOTEST) ./pkg/storage/ -bench=. -benchmem -memprofile memprofile.out -cpuprofile cpuprofile.out -trace trace.out

# regenerate drone yaml
drone:
Expand Down

0 comments on commit 4db3e59

Please sign in to comment.