This repository has been archived by the owner on Aug 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Makefile
90 lines (75 loc) · 2.09 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
ifeq ($(GOARCH),)
GOARCH := $(shell go env GOARCH)
endif
ifeq ($(GOOS),)
GOOS := $(shell go env GOOS)
endif
ifneq ($(DRONE_TAG),)
TAG := $(DRONE_TAG)
endif
DOCKER_BUILDKIT ?= 1
ORG ?= rancher
PKG ?= github.com/rancher/k3c
TAG ?= v0.0.0-dev
ifeq ($(GO_BUILDTAGS),)
GO_BUILDTAGS := static_build,netgo,osusergo
#ifeq ($(GOOS),linux)
#GO_BUILDTAGS := $(GO_BUILDTAGS),seccomp,selinux
#endif
endif
GO_LDFLAGS ?= -w -extldflags=-static
GO_LDFLAGS += -X $(PKG)/pkg/version.GitCommit=$(shell git rev-parse HEAD)
GO_LDFLAGS += -X $(PKG)/pkg/version.Version=$(TAG)
GO_LDFLAGS += -X $(PKG)/pkg/server.DefaultAgentImage=docker.io/$(ORG)/k3c
GO ?= go
GOLANG ?= docker.io/library/golang:1.15-alpine
ifeq ($(GOOS),windows)
BINSUFFIX := .exe
endif
BIN ?= bin/k3c
BIN := $(BIN)$(BINSUFFIX)
.PHONY: build package validate ci publish
build: $(BIN)
package: | dist image-build
validate:
publish: | image-build image-push image-manifest
ci: | build package validate
.PHONY: $(BIN)
$(BIN):
$(GO) build -ldflags "$(GO_LDFLAGS)" -tags "$(GO_BUILDTAGS)" -o $@ .
.PHONY: dist
dist:
@mkdir -p dist/artifacts
@make GOOS=$(GOOS) GOARCH=$(GOARCH) BIN=dist/artifacts/k3c-$(GOOS)-$(GOARCH)$(BINSUFFIX) -C .
.PHONY: clean
clean:
rm -rf bin dist
.PHONY: image-build
image-build:
DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) docker build \
--build-arg GOLANG=$(GOLANG) \
--build-arg ORG=$(ORG) \
--build-arg PKG=$(PKG) \
--build-arg TAG=$(TAG) \
--tag $(ORG)/k3c:$(TAG) \
--tag $(ORG)/k3c:$(TAG)-$(GOARCH) \
.
.PHONY: image-push
image-push:
docker push $(ORG)/k3c:$(TAG)-$(GOARCH)
.PHONY: image-manifest
image-manifest:
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create --amend \
$(ORG)/k3c:$(TAG) \
$(ORG)/k3c:$(TAG)-$(GOARCH)
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push \
$(ORG)/k3c:$(TAG)
./.dapper:
@echo Downloading dapper
@curl -sL https://releases.rancher.com/dapper/v0.5.0/dapper-$$(uname -s)-$$(uname -m) > .dapper.tmp
@@chmod +x .dapper.tmp
@./.dapper.tmp -v
@mv .dapper.tmp .dapper
dapper-%: .dapper
@mkdir -p ./bin/ ./dist/
env DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) ./.dapper -f Dockerfile --target dapper make $*