2020-12-02 10:09:37 -05:00
|
|
|
PREFIX=/usr/local
|
2022-04-27 08:08:19 -04:00
|
|
|
|
|
|
|
FIPS_MODE ?= 0
|
2021-07-21 11:08:52 -04:00
|
|
|
PKG := gitlab.com/gitlab-org/gitlab/workhorse
|
2020-12-02 10:09:37 -05:00
|
|
|
BUILD_DIR ?= $(CURDIR)
|
|
|
|
TARGET_DIR ?= $(BUILD_DIR)/_build
|
|
|
|
VERSION_STRING := $(shell git describe)
|
|
|
|
ifeq ($(strip $(VERSION_STRING)),)
|
|
|
|
VERSION_STRING := v$(shell cat VERSION)
|
|
|
|
endif
|
2021-08-20 05:09:16 -04:00
|
|
|
DATE_FMT = +%Y%m%d.%H%M%S
|
|
|
|
ifdef SOURCE_DATE_EPOCH
|
|
|
|
BUILD_TIME := $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
|
|
|
|
else
|
|
|
|
BUILD_TIME := $(shell date -u "$(DATE_FMT)")
|
|
|
|
endif
|
2022-02-01 10:18:50 -05:00
|
|
|
GO_BUILD_GENERIC_LDFLAGS := -X main.Version=$(VERSION_STRING) -X main.BuildTime=$(BUILD_TIME)
|
2021-10-28 08:10:22 -04:00
|
|
|
GITALY := tmp/tests/gitaly/_build/bin/gitaly
|
|
|
|
GITALY_PID_FILE := gitaly.pid
|
2020-12-02 10:09:37 -05:00
|
|
|
EXE_ALL := gitlab-resize-image gitlab-zip-cat gitlab-zip-metadata gitlab-workhorse
|
|
|
|
INSTALL := install
|
|
|
|
BUILD_TAGS := tracer_static tracer_static_jaeger continuous_profiler_stackdriver
|
|
|
|
|
2022-04-27 08:08:19 -04:00
|
|
|
ifeq (${FIPS_MODE}, 1)
|
|
|
|
# boringcrypto tag is added automatically by golang-fips compiler
|
|
|
|
BUILD_TAGS += fips
|
|
|
|
# If the golang-fips compiler is built with CGO_ENABLED=0, this needs to be
|
|
|
|
# explicitly switched on.
|
|
|
|
export CGO_ENABLED=1
|
|
|
|
endif
|
|
|
|
|
2020-12-02 10:09:37 -05:00
|
|
|
MINIMUM_SUPPORTED_GO_VERSION := 1.11
|
|
|
|
|
|
|
|
export GOBIN := $(TARGET_DIR)/bin
|
|
|
|
export PATH := $(GOBIN):$(PATH)
|
|
|
|
export GOPROXY ?= https://proxy.golang.org
|
|
|
|
export GO111MODULE=on
|
|
|
|
|
|
|
|
define message
|
|
|
|
@echo "### $(1)"
|
|
|
|
endef
|
|
|
|
|
2022-02-01 10:18:50 -05:00
|
|
|
# To compute a unique and deterministic value for GNU build-id, we build the Go binary a second time.
|
|
|
|
# From the first build, we extract its unique and deterministic Go build-id, and use that to derive
|
|
|
|
# a comparably unique and deterministic GNU build-id to inject into the final binary.
|
|
|
|
# If we cannot extract a Go build-id, we punt and fallback to using a random 32-byte hex string.
|
|
|
|
# This fallback is unique but non-deterministic. Uniqueness is critical, because the GNU build-id
|
|
|
|
# can be used as a cache key in a build cache. Without the fallback, we risk cache key collisions.
|
|
|
|
## Skip generation of the GNU build ID if set to speed up builds.
|
|
|
|
WITHOUT_BUILD_ID ?=
|
2020-12-02 10:09:37 -05:00
|
|
|
|
|
|
|
.NOTPARALLEL:
|
|
|
|
|
|
|
|
.PHONY: all
|
|
|
|
all: clean-build $(EXE_ALL)
|
|
|
|
|
2022-02-01 10:18:50 -05:00
|
|
|
.PHONY: gitlab-resize-image gitlab-zip-cat gitlab-zip-metadata
|
|
|
|
gitlab-resize-image gitlab-zip-cat gitlab-zip-metadata:
|
2020-12-02 10:09:37 -05:00
|
|
|
$(call message,Building $@)
|
2022-02-01 10:18:50 -05:00
|
|
|
go build -ldflags "$(GO_BUILD_GENERIC_LDFLAGS)" -tags "$(BUILD_TAGS)" -o $(BUILD_DIR)/$@ $(PKG)/cmd/$@
|
|
|
|
ifndef WITHOUT_BUILD_ID
|
|
|
|
go build -ldflags "$(GO_BUILD_GENERIC_LDFLAGS) -B 0x$$(_support/make-gnu-build-id.sh $(BUILD_DIR)/$@)" -tags "$(BUILD_TAGS)" -o $(BUILD_DIR)/$@ $(PKG)/cmd/$@
|
|
|
|
endif
|
2020-12-02 10:09:37 -05:00
|
|
|
|
2021-01-11 10:10:32 -05:00
|
|
|
.PHONY: gitlab-workhorse
|
2021-08-18 11:11:07 -04:00
|
|
|
gitlab-workhorse:
|
2020-12-02 10:09:37 -05:00
|
|
|
$(call message,Building $@)
|
2022-02-01 10:18:50 -05:00
|
|
|
go build -ldflags "$(GO_BUILD_GENERIC_LDFLAGS)" -tags "$(BUILD_TAGS)" -o $(BUILD_DIR)/$@ $(PKG)
|
|
|
|
ifndef WITHOUT_BUILD_ID
|
|
|
|
go build -ldflags "$(GO_BUILD_GENERIC_LDFLAGS) -B 0x$$(_support/make-gnu-build-id.sh $(BUILD_DIR)/$@)" -tags "$(BUILD_TAGS)" -o $(BUILD_DIR)/$@ $(PKG)
|
|
|
|
endif
|
2020-12-02 10:09:37 -05:00
|
|
|
|
|
|
|
.PHONY: install
|
2021-08-18 11:11:07 -04:00
|
|
|
install: $(EXE_ALL)
|
2020-12-02 10:09:37 -05:00
|
|
|
$(call message,$@)
|
|
|
|
mkdir -p $(DESTDIR)$(PREFIX)/bin/
|
|
|
|
cd $(BUILD_DIR) && $(INSTALL) $(EXE_ALL) $(DESTDIR)$(PREFIX)/bin/
|
|
|
|
|
|
|
|
.PHONY: test
|
2021-08-18 11:11:07 -04:00
|
|
|
test: prepare-tests
|
2020-12-02 10:09:37 -05:00
|
|
|
$(call message,$@)
|
2021-12-23 13:14:10 -05:00
|
|
|
@if [ -z "$${GITALY_ADDRESS+x}" ] ; then \
|
|
|
|
echo "To run gitaly integration tests set GITALY_ADDRESS=tcp://127.0.0.1:8075" ; \
|
|
|
|
else \
|
|
|
|
$(MAKE) run-gitaly ; \
|
|
|
|
fi
|
|
|
|
@go test -tags "$(BUILD_TAGS)" ./... ;\
|
2021-10-28 08:10:22 -04:00
|
|
|
status="$$?" ;\
|
|
|
|
if [ -f "$(GITALY_PID_FILE)" ] ; then \
|
|
|
|
echo "Clean up Gitaly server for workhorse integration test" ;\
|
|
|
|
kill -9 $$(cat $(GITALY_PID_FILE)) ;\
|
|
|
|
rm $(GITALY_PID_FILE) ;\
|
|
|
|
else \
|
|
|
|
echo "Gitaly integration test not running" ;\
|
|
|
|
fi ;\
|
|
|
|
exit "$$status"
|
2020-12-02 10:09:37 -05:00
|
|
|
@echo SUCCESS
|
|
|
|
|
|
|
|
.PHONY: clean
|
2021-08-18 11:11:07 -04:00
|
|
|
clean: clean-workhorse clean-build
|
2020-12-02 10:09:37 -05:00
|
|
|
$(call message,$@)
|
|
|
|
rm -rf testdata/data testdata/scratch
|
|
|
|
|
|
|
|
.PHONY: clean-workhorse
|
|
|
|
clean-workhorse:
|
|
|
|
$(call message,$@)
|
|
|
|
rm -f $(EXE_ALL)
|
|
|
|
|
|
|
|
.PHONY: clean-build
|
|
|
|
clean-build:
|
|
|
|
$(call message,$@)
|
|
|
|
rm -rf $(TARGET_DIR)
|
|
|
|
|
|
|
|
.PHONY: prepare-tests
|
|
|
|
prepare-tests: testdata/data/group/test.git $(EXE_ALL)
|
|
|
|
prepare-tests: testdata/scratch
|
|
|
|
|
2021-10-28 08:10:22 -04:00
|
|
|
.PHONY: run-gitaly
|
2021-12-23 13:14:10 -05:00
|
|
|
run-gitaly: $(GITALY_PID_FILE)
|
2021-10-28 08:10:22 -04:00
|
|
|
|
|
|
|
$(GITALY_PID_FILE): gitaly.toml
|
2021-12-23 13:14:10 -05:00
|
|
|
$(call message, "Starting gitaly")
|
2022-01-18 13:11:20 -05:00
|
|
|
cd ..; GITALY_TESTING_NO_GIT_HOOKS=1 GITALY_PID_FILE=workhorse/$(GITALY_PID_FILE) scripts/gitaly-test-spawn workhorse/gitaly.toml
|
2021-10-28 08:10:22 -04:00
|
|
|
|
|
|
|
gitaly.toml: ../tmp/tests/gitaly/config.toml
|
|
|
|
sed -e 's/^socket_path.*$$/listen_addr = "0.0.0.0:8075"/;s/^\[auth\]$$//;s/^token.*$$//;s/^internal_socket_dir.*$$//' \
|
|
|
|
$< > $@
|
|
|
|
|
2021-12-23 13:14:10 -05:00
|
|
|
../tmp/tests/gitaly/config.toml:
|
|
|
|
$(call message, "Building a complete test environment")
|
|
|
|
cd .. ; ./scripts/setup-test-env
|
|
|
|
|
2020-12-02 10:09:37 -05:00
|
|
|
testdata/data/group/test.git:
|
|
|
|
$(call message,$@)
|
|
|
|
git clone --quiet --bare https://gitlab.com/gitlab-org/gitlab-test.git $@
|
|
|
|
|
|
|
|
testdata/scratch:
|
|
|
|
mkdir -p testdata/scratch
|
|
|
|
|
|
|
|
.PHONY: verify
|
|
|
|
verify: lint vet detect-context detect-assert check-formatting staticcheck deps-check
|
|
|
|
|
|
|
|
.PHONY: lint
|
2021-08-18 11:11:07 -04:00
|
|
|
lint:
|
2020-12-02 10:09:37 -05:00
|
|
|
$(call message,Verify: $@)
|
|
|
|
go install golang.org/x/lint/golint
|
|
|
|
@_support/lint.sh ./...
|
|
|
|
|
|
|
|
.PHONY: vet
|
2021-08-18 11:11:07 -04:00
|
|
|
vet:
|
2020-12-02 10:09:37 -05:00
|
|
|
$(call message,Verify: $@)
|
|
|
|
@go vet ./...
|
|
|
|
|
|
|
|
.PHONY: detect-context
|
2021-08-18 11:11:07 -04:00
|
|
|
detect-context:
|
2020-12-02 10:09:37 -05:00
|
|
|
$(call message,Verify: $@)
|
|
|
|
_support/detect-context.sh
|
|
|
|
|
|
|
|
.PHONY: detect-assert
|
|
|
|
detect-assert:
|
|
|
|
$(call message,Verify: $@)
|
|
|
|
_support/detect-assert.sh
|
|
|
|
|
|
|
|
.PHONY: check-formatting
|
2021-08-18 11:11:07 -04:00
|
|
|
check-formatting: install-goimports
|
2020-12-02 10:09:37 -05:00
|
|
|
$(call message,Verify: $@)
|
2021-01-11 10:10:32 -05:00
|
|
|
@_support/fmt.sh check
|
2020-12-02 10:09:37 -05:00
|
|
|
|
|
|
|
# Megacheck will tailor some responses given a minimum Go version, so pass that through the CLI
|
|
|
|
# Additionally, megacheck will not return failure exit codes unless explicitly told to via the
|
|
|
|
# `-simple.exit-non-zero` `-unused.exit-non-zero` and `-staticcheck.exit-non-zero` flags
|
|
|
|
.PHONY: staticcheck
|
2021-08-18 11:11:07 -04:00
|
|
|
staticcheck:
|
2020-12-02 10:09:37 -05:00
|
|
|
$(call message,Verify: $@)
|
|
|
|
go install honnef.co/go/tools/cmd/staticcheck
|
|
|
|
@ $(GOBIN)/staticcheck -go $(MINIMUM_SUPPORTED_GO_VERSION) ./...
|
|
|
|
|
|
|
|
# In addition to fixing imports, goimports also formats your code in the same style as gofmt
|
|
|
|
# so it can be used as a replacement.
|
|
|
|
.PHONY: fmt
|
2021-08-18 11:11:07 -04:00
|
|
|
fmt: install-goimports
|
2020-12-02 10:09:37 -05:00
|
|
|
$(call message,$@)
|
2021-01-11 10:10:32 -05:00
|
|
|
@_support/fmt.sh
|
2020-12-02 10:09:37 -05:00
|
|
|
|
|
|
|
.PHONY: goimports
|
2021-08-18 11:11:07 -04:00
|
|
|
install-goimports:
|
2020-12-02 10:09:37 -05:00
|
|
|
$(call message,$@)
|
|
|
|
go install golang.org/x/tools/cmd/goimports
|
|
|
|
|
|
|
|
.PHONY: deps-check
|
|
|
|
deps-check:
|
|
|
|
go mod tidy
|
|
|
|
@if git diff --quiet --exit-code -- go.mod go.sum; then \
|
|
|
|
echo "go.mod and go.sum are ok"; \
|
|
|
|
else \
|
|
|
|
echo ""; \
|
|
|
|
echo "go.mod and go.sum are modified, please commit them";\
|
|
|
|
exit 1; \
|
|
|
|
fi;
|