-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
109 lines (89 loc) · 3.29 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
DOCKER_TAG := $(or ${GITHUB_TAG_NAME},latest)
BACKUP_PROVIDER := $(or ${BACKUP_PROVIDER},local)
SHA := $(shell git rev-parse --short=8 HEAD)
GITVERSION := $(shell git describe --long --all)
# gnu date format iso-8601 is parsable with Go RFC3339
BUILDDATE := $(shell date --iso-8601=seconds)
VERSION := $(or ${VERSION},$(shell git describe --tags --exact-match 2> /dev/null || git symbolic-ref -q --short HEAD || git rev-parse --short HEAD))
GO111MODULE := on
CGO_ENABLED := 1
LINKMODE := -extldflags '-static -s -w' \
-X 'github.com/metal-stack/v.Version=$(VERSION)' \
-X 'github.com/metal-stack/v.Revision=$(GITVERSION)' \
-X 'github.com/metal-stack/v.GitSHA1=$(SHA)' \
-X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)'
KUBECONFIG := $(shell pwd)/.kubeconfig
GO_RUN := $(or $(GO_RUN),)
ifneq ($(GO_RUN),)
GO_RUN_ARG := -run $(GO_RUN)
endif
.PHONY: build
build: generate-examples
go mod tidy
go build -ldflags "$(LINKMODE)" -tags 'osusergo netgo static_build' -o bin/backup-restore-sidecar github.com/metal-stack/backup-restore-sidecar/cmd
strip bin/backup-restore-sidecar
.PHONY: test
test: build
go test -cover ./...
.PHONY: generate-examples
generate-examples:
go run ./pkg/generate/examples/dump.go
.PHONY: test-integration
test-integration: kind-cluster-create
kind --name backup-restore-sidecar load docker-image ghcr.io/metal-stack/backup-restore-sidecar:latest
KUBECONFIG=$(KUBECONFIG) go test $(GO_RUN_ARG) -tags=integration -count 1 -v -p 1 -timeout 20m ./...
.PHONY: proto
proto:
make -C proto protoc
.PHONY: dockerimage
dockerimage: build
docker build -t ghcr.io/metal-stack/backup-restore-sidecar:${DOCKER_TAG} .
# # #
# the following tasks can be used to set up a development environment
# # #
.PHONY: start-postgres
start-postgres:
$(MAKE) start DB=postgres
.PHONY: start-rethinkdb
start-rethinkdb:
$(MAKE) start DB=rethinkdb
.PHONY: start-etcd
start-etcd:
$(MAKE) start DB=etcd
.PHONY: start-meilisearch
start-meilisearch:
$(MAKE) start DB=meilisearch
.PHONY: start-redis
start-redis:
$(MAKE) start DB=redis
.PHONY: start-localfs
start-localfs:
$(MAKE) start DB=localfs
.PHONY: start
start: kind-cluster-create
kind --name backup-restore-sidecar load docker-image ghcr.io/metal-stack/backup-restore-sidecar:latest
ifneq ($(BACKUP_PROVIDER),local)
# if you want to use other providers, please fill in your credentials and backup config!
# for this, you need to edit deploy/provider-secret-$(BACKUP_PROVIDER)
# take care not to push your provider secrets to origin
kubectl --kubeconfig $(KUBECONFIG) apply -f deploy/provider-secret-$(BACKUP_PROVIDER).yaml
endif
kubectl --kubeconfig $(KUBECONFIG) delete -f "deploy/$(DB)-$(BACKUP_PROVIDER).yaml" || true # for idempotence
kubectl --kubeconfig $(KUBECONFIG) apply -f "deploy/$(DB)-$(BACKUP_PROVIDER).yaml"
# tailing
stern --kubeconfig $(KUBECONFIG) '.*'
.PHONY: kind-cluster-create
kind-cluster-create: dockerimage
@if ! which kind > /dev/null; then echo "kind needs to be installed"; exit 1; fi
@if ! kind get clusters | grep backup-restore-sidecar > /dev/null; then \
kind create cluster \
--name backup-restore-sidecar \
--config kind.yaml \
--kubeconfig $(KUBECONFIG); fi
.PHONY: cleanup
cleanup:
kind delete cluster --name backup-restore-sidecar
rm -f $(KUBECONFIG)
.PHONY: dev-env
dev-env:
@echo "export KUBECONFIG=$(KUBECONFIG)"