-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmakefile
61 lines (51 loc) · 1.68 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
VERSION = $(shell cat VERSION)
INFO_PATH := github.com/prometheus/common/version
APP_NAME = air-co2-exporter
BIN_NAME = air_co2_exporter
DOCKER_REGISTRY ?=
GOPATH ?= `pwd`/../../
OS ?= linux
ARCH ?= amd64
.PHONY: lint
lint:
${GOPATH}/bin/golint -set_exit_status ./...
.PHONY: build
build:
@echo "> building ${BIN_NAME}"
@CC_FOR_TARGET="x86_64-linux-musl-gcc" GOPATH=${GOPATH} go build -ldflags "\
-X ${INFO_PATH}.Version=${VERSION} \
-X ${INFO_PATH}.Revision=`git rev-parse HEAD` \
-X ${INFO_PATH}.Branch=`git rev-parse --abbrev-ref HEAD` \
-X ${INFO_PATH}.BuildUser=${USER} \
-X ${INFO_PATH}.BuildDate=`date -u '+%Y-%m-%d_%H:%M:%S_UTC'`" \
-gcflags "all=-trimpath=${GOPATH}" \
-o ./bin/${BIN_NAME} \
main.go
archive:
@mkdir -p ./dist
tar -czf ./dist/${BIN_NAME}-${VERSION}-${OS}-${ARCH}.tar.gz \
bin/${BIN_NAME} \
README.md \
LICENSE
docker-build:
docker build -f Dockerfile \
-t ${DOCKER_REGISTRY}/${APP_NAME}:${VERSION}-${OS}-${ARCH} \
.
docker-push:
docker push ${DOCKER_REGISTRY}/${APP_NAME}:${VERSION}-${OS}-${ARCH}
docker-run:
docker run --privileged ${APP_NAME}:${VERSION}
docker-merge-manifest:
docker manifest create \
${DOCKER_REGISTRY}/${APP_NAME}:latest \
${DOCKER_REGISTRY}/${APP_NAME}:${VERSION}-linux-amd64 \
${DOCKER_REGISTRY}/${APP_NAME}:${VERSION}-linux-arm64
docker manifest create \
${DOCKER_REGISTRY}/${APP_NAME}:${VERSION} \
${DOCKER_REGISTRY}/${APP_NAME}:${VERSION}-linux-amd64 \
${DOCKER_REGISTRY}/${APP_NAME}:${VERSION}-linux-arm64
docker manifest push --purge ${DOCKER_REGISTRY}/${APP_NAME}:latest
docker manifest push --purge ${DOCKER_REGISTRY}/${APP_NAME}:${VERSION}
.PHONY: clean
clean:
rm -rf ./bin/* ./dist/*