-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
147 lines (118 loc) · 4.88 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
BUILD_DIR ?= build
COMMIT = $(shell git rev-parse HEAD)
VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='-dev' --always)
ORG := hyperscale
PROJECT := hyperpic
REPOPATH ?= github.com/$(ORG)/$(PROJECT)
VERSION_PACKAGE = $(REPOPATH)/pkg/$(PROJECT)/version
IMAGE ?= $(ORG)/$(PROJECT)
GO_LDFLAGS :="
GO_LDFLAGS += -X $(VERSION_PACKAGE).Version=$(VERSION)
GO_LDFLAGS += -X $(VERSION_PACKAGE).BuildAt=$(shell date +'%Y-%m-%dT%H:%M:%SZ')
GO_LDFLAGS += -X $(VERSION_PACKAGE).Revision=$(COMMIT)
GO_LDFLAGS +="
GO_FILES := $(shell find . -type f -name '*.go' -not -path "./vendor/*")
HYPERPIC_AUTH_SECRET ?= c8da8ded-f9a2-429c-8811-9b2a07de8ede
ifeq ($(shell uname -s), Darwin)
CGO_CFLAGS_ALLOW ?= "-Xpreprocessor"
PKG_CONFIG_PATH ?= "/usr/local/opt/libffi/lib/pkgconfig:/usr/local/opt/vips/lib/pkgconfig"
endif
.PHONY: release
release:
@echo "Release v$(version)"
@git pull
@git checkout master
@git pull
@git checkout develop
@git flow release start $(version)
@echo "$(version)" > .version
@sed -e "s/version: .*/version: \"v$(version)\"/g" docs/swagger.yaml > docs/swagger.yaml.new && rm -rf docs/swagger.yaml && mv docs/swagger.yaml.new docs/swagger.yaml
@git add .version docs/swagger.yaml
@git commit -m "feat(project): update version file" .version docs/swagger.yaml
@git flow release finish $(version)
@git push
@git push --tags
@git checkout master
@git push
@git checkout develop
@echo "Release v$(version) finished."
.PHONY: all
all: deps build test
.PHONY: deps
deps:
@go mod download
.PHONY: clean
clean:
@go clean -i ./...
create-build-dir:
@mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/coverage.out: $(GO_FILES) create-build-dir go.mod go.sum
@CGO_CFLAGS_ALLOW=-Xpreprocessor go test -race -cover -coverprofile $(BUILD_DIR)/coverage.out.tmp ./...
@cat $(BUILD_DIR)/coverage.out.tmp | grep -v '.pb.go' | grep -v 'mock_' > $(BUILD_DIR)/coverage.out
@rm $(BUILD_DIR)/coverage.out.tmp
.PHONY: ci-test
ci-test:
@go test -race -cover -coverprofile ./coverage.out.tmp -v ./... | go2xunit -fail -output tests.xml
@cat ./coverage.out.tmp | grep -v '.pb.go' | grep -v 'mock_' > ./coverage.out
@rm ./coverage.out.tmp
@echo ""
@go tool cover -func ./coverage.out
.PHONY: lint
lint:
@golangci-lint run ./...
.PHONY: test
test: $(BUILD_DIR)/coverage.out
.PHONY: coverage
coverage: $(BUILD_DIR)/coverage.out
@echo ""
@go tool cover -func ./$(BUILD_DIR)/coverage.out
.PHONY: coverage-html
coverage-html: $(BUILD_DIR)/coverage.out
@go tool cover -html ./$(BUILD_DIR)/coverage.out
generate:
@go generate ./...
${BUILD_DIR}/hyperpic: $(GO_FILES) go.mod go.sum
@echo "Building $@..."
@CGO_CFLAGS_ALLOW=-Xpreprocessor go generate ./cmd/$(subst ${BUILD_DIR}/,,$@)/
@CGO_CFLAGS_ALLOW=-Xpreprocessor go build -ldflags $(GO_LDFLAGS) -o $@ ./cmd/$(subst ${BUILD_DIR}/,,$@)/
.PHONY: run-hyperpic
run-hyperpic: ${BUILD_DIR}/hyperpic
@echo "Running $<..."
@./$< --config=./cmd/hyperpic/config.yml
.PHONY: run
run: run-hyperpic
.PHONY: run-docker
run-docker: docker
@docker run -e "HYPERPIC_AUTH_SECRET=$(HYPERPIC_AUTH_SECRET)" -p 8574:8080 -v $(shell pwd)/var/lib/hyperpic:/var/lib/hyperpic --rm $(IMAGE)
.PHONY: build
build: ${BUILD_DIR}/hyperpic
.PHONY: docker
docker:
@docker build -f cmd/hyperpic/Dockerfile --rm -t $(IMAGE) .
.PHONY: publish
publish: docker
@docker tag $(IMAGE) $(IMAGE):latest
@docker push $(IMAGE)
.PHONY: publish-dev
publish-dev: docker
@docker tag $(IMAGE) $(IMAGE):dev
@docker push $(IMAGE):dev
heroku: docker
@echo "Deploy Hyperpic on Heroku..."
@#heroku container:push web --app=hyperpic
@docker tag $(IMAGE) registry.heroku.com/hyperpic/web
@docker push registry.heroku.com/hyperpic/web
@heroku container:release web --app=hyperpic
upload-demo:
@curl -F 'image=@_resources/demo/kayaks.jpg' -H "Authorization: Bearer $(HYPERPIC_AUTH_SECRET)" https://hyperpic.herokuapp.com/kayaks.jpg
@curl -F 'image=@_resources/demo/smartcrop.jpg' -H "Authorization: Bearer $(HYPERPIC_AUTH_SECRET)" https://hyperpic.herokuapp.com/smartcrop.jpg
upload-demo-koyeb:
@curl -F 'image=@_resources/demo/kayaks.jpg' -H "Authorization: Bearer $(HYPERPIC_AUTH_SECRET)" https://hyperpic-euskadi31.koyeb.app/kayaks.jpg
@curl -F 'image=@_resources/demo/smartcrop.jpg' -H "Authorization: Bearer $(HYPERPIC_AUTH_SECRET)" https://hyperpic-euskadi31.koyeb.app/smartcrop.jpg
upload-demo-dev:
@curl -F 'image=@_resources/demo/kayaks.jpg' -H "Authorization: Bearer foo" http://localhost:8574/kayaks.jpg
@curl -F 'image=@_resources/demo/smartcrop.jpg' -H "Authorization: Bearer foo" http://localhost:8574/smartcrop.jpg
upload-demo-nomad:
@curl -F 'image=@_resources/demo/kayaks.jpg' -H "Authorization: Bearer $(HYPERPIC_AUTH_SECRET)" http://localhost:9999/kayaks.jpg
@curl -F 'image=@_resources/demo/smartcrop.jpg' -H "Authorization: Bearer $(HYPERPIC_AUTH_SECRET)" http://localhost:9999/smartcrop.jpg
@curl -F 'image=@_resources/demo/smartcrop.jpg' -H "Authorization: Bearer $(HYPERPIC_AUTH_SECRET)" http://localhost:9999/smartcrop.jpg