forked from simonswine/kube-latency
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
60 lines (43 loc) · 1.57 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
ACCOUNT=cellebyte
APP_NAME=kube-latency
PACKAGE_NAME=github.com/${ACCOUNT}/${APP_NAME}
GO_VERSION=1.21
DOCKER_IMAGE=${ACCOUNT}/${APP_NAME}
BUILD_DIR=_build
CONTAINER_DIR=/go/src/${PACKAGE_NAME}
.PHONY: version
all: build
depend:
rm -rf ${BUILD_DIR}/
mkdir $(BUILD_DIR)/
version:
$(eval GIT_STATE := $(shell if test -z "`git status --porcelain 2> /dev/null`"; then echo "clean"; else echo "dirty"; fi))
$(eval GIT_COMMIT := $(shell git rev-parse HEAD))
$(eval APP_VERSION := $(shell cat VERSION))
build: depend version
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build \
-a -tags netgo \
-o ${BUILD_DIR}/${APP_NAME}-linux-amd64 \
-ldflags "-X main.AppGitState=${GIT_STATE} -X main.AppGitCommit=${GIT_COMMIT} -X main.AppVersion=${APP_VERSION}"
# docker: docker_all
# docker_%:
# # create a container
# $(eval CONTAINER_ID := $(shell docker create \
# -i \
# -w $(CONTAINER_DIR) \
# golang:${GO_VERSION} \
# /bin/bash -c "tar xf - && make $*" \
# ))
# # run build inside container
# tar cf - . | docker start -a -i $(CONTAINER_ID)
# # copy artifacts over
# rm -rf $(BUILD_DIR)/
# docker cp $(CONTAINER_ID):$(CONTAINER_DIR)/$(BUILD_DIR)/ .
# # remove container
# docker rm $(CONTAINER_ID)
image: version
docker build --build-arg VCS_REF=$(GIT_COMMIT) -t ghcr.io/$(ACCOUNT)/$(APP_NAME):latest .
imageX86: version
docker build --platform linux/amd64 --build-arg GIT_COMMIT=$(GIT_COMMIT) --build-arg APP_VERSION=$(APP_VERSION) --build-arg GIT_STATE=$(GIT_STATE) -t ghcr.io/$(ACCOUNT)/$(APP_NAME):latest .
push: image
docker push ghcr.io/$(ACCOUNT)/$(APP_NAME):latest