-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
60 lines (50 loc) · 2.01 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
BINARIES=bin/deadman-switch
IMAGE=containers.trusch.io/deadman-switch:latest
BASE_IMAGE=gcr.io/distroless/base-debian10:latest
BUILD_IMAGE=golang:1.15
GOOS=linux
GOARCH=amd64
GOARM=7 # for crosscompiling
COMMIT=$(shell git log --format="%H" -n 1)
VERSION=$(shell git describe)
default: image
run: image
podman pod create -p 8080:8080 --name deadman-switch-pod --replace
podman run -d --rm --pod deadman-switch-pod --name etcd quay.io/coreos/etcd
podman run -d --rm --pod deadman-switch-pod --name caddy -v ./configs/Caddyfile:/Caddyfile caddy caddy run -config /Caddyfile
podman run -d --rm --pod deadman-switch-pod --name deadman-switch-1 -v ./configs/config-node-1.yaml:/etc/deadman-switch/config.yaml $(IMAGE)
podman run -d --rm --pod deadman-switch-pod --name deadman-switch-2 -v ./configs/config-node-2.yaml:/etc/deadman-switch/config.yaml $(IMAGE)
stop:
podman pod rm -f deadman-switch-pod
# put binaries into image
image: .image
.image: $(BINARIES) Makefile
$(eval ID=$(shell buildah from $(BASE_IMAGE)))
buildah copy $(ID) $(shell pwd)/bin/* /bin/
buildah copy $(ID) $(shell pwd)/configs/default.yaml /etc/deadman-switch/config.yaml
buildah config --cmd "/bin/deadman-switch --config /etc/deadman-switch/config.yaml --log-level info --log-format console" $(ID)
buildah commit $(ID) $(IMAGE)
buildah rm $(ID)
touch .image
# build binaries
bin/%: $(shell find ./ -name "*.go")
podman run \
--rm \
-v ./:/app \
-w /app \
-e GOOS=${GOOS} \
-e GOARCH=${GOARCH} \
-e GOARM=${GOARM} \
-v go-build-cache:/root/.cache/go-build \
-v go-mod-cache:/go/pkg/mod $(BUILD_IMAGE) \
go build -v -o $@ -ldflags "-X main.Version=$(VERSION) -X main.Commit=$(COMMIT)" cmd/deadman-switch/main.go
# install locally
install: ${BINARIES}
cp -v ${BINARIES} $(shell go env GOPATH)/bin/
publish-image: .image
podman tag $(IMAGE) docker.io/trusch/deadman-switch:latest
podman push docker.io/trusch/deadman-switch:latest
# cleanup
clean:
-rm -r bin .image .buildimage /tmp/protoc-download
-podman volume rm go-build-cache go-mod-cache