-
Notifications
You must be signed in to change notification settings - Fork 17
/
Makefile
105 lines (86 loc) · 3.69 KB
/
Makefile
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
SHELL := /usr/bin/env bash -euo pipefail -c
PRODUCT_NAME ?= consul-aws
BIN_NAME ?= $(PRODUCT_NAME)
GOPATH ?= $(shell go env GOPATH)
GOBIN ?= $(GOPATH)/bin
VERSION = $(shell head -n 1 version/VERSION)
GOLANG_VERSION ?= $(shell head -n 1 .go-version)
DEV_IMAGE?=consul-aws-dev
GO_BUILD_TAG?=consul-aws-build-go
GIT_COMMIT?=$(shell git rev-parse --short HEAD)
GIT_DIRTY?=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true)
GIT_DESCRIBE?=$(shell git describe --tags --always)
GIT_IMPORT=github.com/hashicorp/consul-aws/version
GOLDFLAGS=-X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT)$(GIT_DIRTY)
# Get local ARCH; on Intel Mac, 'uname -m' returns x86_64 which we turn into amd64.
# Not using 'go env GOOS/GOARCH' here so 'make docker' will work without local Go install.
ARCH ?= $(shell A=$$(uname -m); [ $$A = x86_64 ] && A=amd64; echo $$A)
OS ?= $(shell go env GOOS)
PLATFORM = $(OS)/$(ARCH)
DIST = dist/$(PLATFORM)
BIN = $(DIST)/$(BIN_NAME)
# Docker Stuff.
export DOCKER_BUILDKIT=1
BUILD_ARGS = BIN_NAME=$(BIN_NAME) PRODUCT_VERSION=$(VERSION) PRODUCT_REVISION=$(REVISION)
TAG = $(PRODUCT_NAME):$(VERSION)
BA_FLAGS = $(addprefix --build-arg=,$(BUILD_ARGS))
FLAGS = --target $(TARGET) --platform linux/$(ARCH) --tag $(TAG) $(BA_FLAGS)
HTTP_FLAGS_PACKAGE_DIR=internal/flags
dist: ## make dist directory and ignore everything
mkdir -p $(DIST)
echo '*' > dist/.gitignore
.PHONY: bin
bin: dist ## Build the binary
GOARCH=$(ARCH) GOOS=$(OS) CGO_ENABLED=0 go build -trimpath -buildvcs=false -ldflags="$(GOLDFLAGS)" -o $(BIN) .
linux: ## Linux builds a linux binary compatible with the source platform
@mkdir -p ./dist/linux/$(ARCH)/$(BIN_NAME)
CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build -o ./dist/linux/$(ARCH)/$(BIN_NAME) -ldflags "$(GOLDFLAGS)" -tags "$(GOTAGS)"
.PHONY: dev
dev: bin ## Build binary and copy to the destination
cp $(BIN) $(GOBIN)/$(BIN_NAME)
# build is used for the CRT build.yml workflow.
# Environment variables are populated by hashicorp/actions-go-build, not the makefile.
# https://github.com/hashicorp/actions-go-build
.PHONY: build
build:
CGO_ENABLED=0 go build \
-a \
-o="${BIN_PATH}" \
-ldflags " \
-X 'github.com/hashicorp/http-echo/version.GitCommit=${PRODUCT_REVISION}' \
" \
-tags "${GOTAGS}" \
-trimpath \
-buildvcs=false
.PHONY: docker
docker: linux ## build the release-target docker image
$(eval TARGET := release-default) # there are many targets in the Dockerfile, add more build if you need to customize the target
docker build $(FLAGS) .
@echo 'Image built; run "docker run --rm $(TAG)" to try it out.'
docker-run: docker ## run the image of $(TAG)
docker run --rm $(TAG)
.PHONY: dev-docker
dev-docker: docker ## build docker image and tag the image to local
docker tag '$(PRODUCT_NAME):$(VERSION)' '$(PRODUCT_NAME):local'
test:
go test ./...
tools:
go get -u -v $(GOTOOLS)
clean:
@rm -rf \
$(CURDIR)/bin \
$(CURDIR)/pkg
# We support all the same CLI flags for connecting to Consul as the main CLI.
# Rather than import the root Consul module, which is not supported, we copy the
# relevant module. This is similar to what we do in consul-dataplane.
# We don't include config_test.go because it pulls in a directory with test data.
.PHONY: copy-http-flags
copy-http-flags: ## copy http flags modules from consul
for file in config.go http.go http_test.go merge.go usage.go; do \
curl --fail https://raw.githubusercontent.com/hashicorp/consul/main/command/flags/$$file | \
sed 's/BUSL-1.1/MPL-2.0/' | \
sed '1s:^:// Code generated by make copy-http-flags. DO NOT EDIT.\n:' | \
gofmt \
> $(HTTP_FLAGS_PACKAGE_DIR)/$$file; \
done
.PHONY: all bin clean dev dist docker-images go-build-image test tools docker-publish