-
Notifications
You must be signed in to change notification settings - Fork 195
/
Makefile
64 lines (47 loc) · 1.71 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
.PHONY: build push test
TAG ?= $(shell git log -n 1 --pretty=format:"%H")
IMAGE ?= databack/mysql-backup
BUILDIMAGE ?= $(IMAGE):build
TARGET ?= $(IMAGE):$(TAG)
OCIPLATFORMS ?= linux/amd64,linux/arm64
LOCALPLATFORMS ?= linux/386 linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64 windows/386
DIST ?= dist
GOOS?=$(shell uname -s | tr '[:upper:]' '[:lower:]')
GOARCH?=$(shell uname -m)
BIN ?= $(DIST)/mysql-backup-$(GOOS)-$(GOARCH)
build-docker:
docker buildx build -t $(BUILDIMAGE) --platform $(OCIPLATFORMS) .
.PRECIOUS: $(foreach platform,$(LOCALPLATFORMS),$(DIST)/mysql-backup-$(subst /,-,$(platform)))
build-all: $(foreach platform,$(LOCALPLATFORMS),build-local-$(subst /,-,$(platform)))
build-local-%: $(DIST)/mysql-backup-%;
$(DIST):
mkdir -p $@
$(DIST)/mysql-backup-%: GOOS=$(word 1,$(subst -, ,$*))
$(DIST)/mysql-backup-%: GOARCH=$(word 2,$(subst -, ,$*))
$(DIST)/mysql-backup-%: $(DIST)
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $@ .
build-local: $(BIN)
push: build
docker tag $(BUILDIMAGE) $(TARGET)
docker push $(TARGET)
integration_test:
go test -v ./test --tags=integration
integration_test_debug:
dlv --wd=./test test ./test --build-flags="-tags=integration"
vet:
go vet --tags=integration ./...
test: unit_test integration_test
unit_test:
go test -v ./...
.PHONY: clean-test-stop clean-test-remove clean-test
clean-test-stop:
@echo Kill Containers
$(eval IDS:=$(strip $(shell docker ps --filter label=mysqltest -q)))
@if [ -n "$(IDS)" ]; then docker kill $(IDS); fi
@echo
clean-test-remove:
@echo Remove Containers
$(eval IDS:=$(shell docker ps -a --filter label=mysqltest -q))
@if [ -n "$(IDS)" ]; then docker rm $(IDS); fi
@echo
clean-test: clean-test-stop clean-test-remove