-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathMakefile
More file actions
61 lines (50 loc) · 2.01 KB
/
Makefile
File metadata and controls
61 lines (50 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
ENV := $(shell cat ../../.last_used_env || echo "not-set")
-include ../../.env.${ENV}
LOCAL_BUILD_TARGET ?= build-debug
PREFIX := $(strip $(subst ",,$(PREFIX)))
HOSTNAME := $(shell hostname 2> /dev/null || hostnamectl hostname 2> /dev/null)
$(if $(HOSTNAME),,$(error Failed to determine hostname: both 'hostname' and 'hostnamectl' failed))
# Architecture for builds. Defaults to local arch; override for cross-compilation
# (e.g., BUILD_ARCH=amd64 make build-and-upload from an ARM64 host).
BUILD_ARCH ?= $(shell go env GOARCH)
# Docker platform string. Override for multi-arch builds:
# BUILD_PLATFORM=linux/amd64,linux/arm64 make build-and-upload
BUILD_PLATFORM ?= linux/$(BUILD_ARCH)
ifeq ($(PROVIDER),aws)
IMAGE_REGISTRY := $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(PREFIX)core/client-proxy
else
IMAGE_REGISTRY := $(GCP_REGION)-docker.pkg.dev/$(GCP_PROJECT_ID)/$(PREFIX)core/client-proxy
endif
.PHONY: build
build:
# Allow for passing commit sha directly for docker builds
$(eval COMMIT_SHA ?= $(shell git rev-parse --short HEAD))
CGO_ENABLED=0 GOOS=linux GOARCH=$(BUILD_ARCH) go build -o bin/client-proxy -ldflags "-X=main.commitSHA=$(COMMIT_SHA)" .
.PHONY: build-debug
build-debug:
$(eval COMMIT_SHA ?= $(shell git rev-parse --short HEAD))
CGO_ENABLED=1 go build -race -gcflags=all="-N -l" -o bin/client-proxy -ldflags "-X=main.commitSHA=$(COMMIT_SHA)" .
.PHONY: build-and-upload
build-and-upload:
$(eval COMMIT_SHA := $(shell git rev-parse --short HEAD))
@docker buildx build --platform $(BUILD_PLATFORM) --tag $(IMAGE_REGISTRY) --push --build-arg COMMIT_SHA="$(COMMIT_SHA)" -f ./Dockerfile ..
.PHONY: run
run:
make build-debug
NODE_ID=integration-tests \
NODE_IP=127.0.0.1 \
./bin/client-proxy
define setup_local_env
$(eval include .env.local)
$(eval export $(shell sed 's/=.*//' .env.local))
endef
.PHONY: run-local
run-local: $(LOCAL_BUILD_TARGET)
$(call setup_local_env)
NODE_ID=$(HOSTNAME) ./bin/client-proxy
.PHONY: generate
generate:
go generate ./...
.PHONY: test
test:
go test -race -v ./...