forked from digitalocean/doctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
86 lines (69 loc) · 1.91 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
# need to set go version to at least 1.11
export CGO=0
export GO111MODULE := on
# These builds are for convenience. This logic isn't used in the build-release process
my_d=$(shell pwd)
OUT_D = $(shell echo $${OUT_D:-$(my_d)/builds})
UNAME_S := $(shell uname -s)
UNAME_P := $(shell uname -p)
GOOS = linux
ifeq ($(UNAME_S),Darwin)
GOOS = darwin
endif
GOARCH = amd64
ifneq ($(UNAME_P), x86_64)
GOARCH = 386
endif
.PHONY: _build
_build:
@mkdir -p builds
@echo "building doctl via go build"
@cd cmd/doctl && env GOOS=$(GOOS) GOARCH=$(GOARCH) GOFLAGS=-mod=vendor \
go build -o $(OUT_D)/doctl_$(GOOS)_$(GOARCH)
@echo "built $(OUT_D)/doctl_$(GOOS)_$(GOARCH)"
.PHONY: native
native: _build
@mv $(OUT_D)/doctl_$(GOOS)_$(GOARCH) $(OUT_D)/doctl
@echo "built $(OUT_D)/doctl"
# end convenience builds
# docker targets for developing in docker
.PHONY: build_mac
build_mac: GOOS = darwin
build_mac: GOARCH = 386
build_mac: _build
.PHONY: build_linux_386
build_linux_386: GOOS = linux
build_linux_386: GOARCH = 386
build_linux_386: _build
.PHONY: build_linux_amd64
build_linux_amd64: GOOS = linux
build_linux_amd64: GOARCH = amd64
build_linux_amd64: _build
.PHONY: _base_docker_cntr
_base_docker_cntr:
docker build -f Dockerfile.build . -t doctl_builder
.PHONY: docker_build
docker_build: _base_docker_cntr
@mkdir -p $(OUT_D)
@docker build -f Dockerfile.cntr . -t doctl_local
@docker run --rm \
-v $(OUT_D):/copy \
-it --entrypoint /usr/bin/rsync \
doctl_local -av /app/ /copy/
@docker run --rm \
-v $(OUT_D):/copy \
-it --entrypoint /bin/chown \
alpine -R $(shell whoami | id -u): /copy
@echo "Built binaries to $(OUT_D)"
@echo "Created a local Docker container. To use, run: docker run --rm -it doctl_local"
# end docker targets
.PHONY: clean
clean:
@rm -rf builds
.PHONY: test
test:
go test ./cmd/... ./commands/... ./do/... ./install/... ./pkg/... ./pluginhost/... .
.PHONY: vendor
vendor:
@go mod tidy
@go mod vendor