forked from citradigital/toldata
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
102 lines (80 loc) · 2.92 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
# Copyright 2019 Citra Digital Lintas
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
DIR=deployments/docker
RECIPE=${DIR}/docker-compose.yaml
NAMESPACE=builder
DIND_PREFIX ?= $(HOME)
ifneq ($(HOST_PATH),)
DIND_PREFIX := $(HOST_PATH)
endif
ifeq ($(CACHE_PREFIX),)
CACHE_PREFIX=/tmp
endif
PREFIX=$(shell echo $(PWD) | sed -e s:$(HOME):$(DIND_PREFIX):)
include .env
export $(shell sed 's/=.*//' .env)
IMAGE_TAG ?= latest
export $IMAGE_TAG
.PHONY : test
test:
docker run \
--env-file .env \
-v $(CACHE_PREFIX)/cache/go:/go/pkg/mod \
-v $(CACHE_PREFIX)/cache/apk:/etc/apk/cache \
-v $(PREFIX)/deployments/docker/build:/build \
-v $(PREFIX)/:/src \
-v $(PREFIX)/scripts/test.sh:/test.sh \
-e UID=$(UID) \
golang:1.19-alpine /test.sh
buildtest:
docker-compose -f ${RECIPE} -p ${NAMESPACE} build testapi
infratest:
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d testnats
cleantest:
docker-compose -f ${RECIPE} -p ${NAMESPACE} stop
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f testapi
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f testnats
runtest: cleantest buildtest
docker-compose -f ${RECIPE} -p ${NAMESPACE} run testapi /start.sh
docker-compose -f ${RECIPE} -p ${NAMESPACE} down
gen_clean:
rm -f *.pb.go
rm -f test/*.pb.go
gen:
@docker run --platform linux/amd64 \
-v $(PREFIX):/gen \
-v $(PREFIX)/api:/api \
generator/toldata:$(IMAGE_TAG) -I /api /api/toldata.proto \
--toldata_out=grpc:/gen --go_out=./.
@docker run --platform linux/amd64 \
-v $(PREFIX)/test:/gen \
-v $(PREFIX)/api:/api \
generator/toldata:$(IMAGE_TAG) -I /api/ /api/toldata_test.proto \
--toldata_out=grpc,rest:/gen --go_out=./test --go-grpc_out=./test
generator:
go build -o protoc-gen-toldata cmd/protoc-gen-toldata/main.go
generator_gen:
protoc api/toldata.proto --go_out=./. --toldata_out=grpc:./.
protoc -I api/ api/toldata_test.proto --go_out=./test --go-grpc_out=./test --toldata_out=grpc,rest:./test
build-generator:
@mkdir -p tmp/src
@cp -a *.go go.mod cmd tmp/src
@cp api/toldata.proto deployments/docker/build/
@docker run \
-v $(CACHE_PREFIX)/cache/go:/go/pkg/mod \
-v $(CACHE_PREFIX)/cache/apk:/etc/apk/cache \
-v $(PREFIX)/deployments/docker/build:/build \
-v $(PREFIX)/tmp/src:/src \
-v $(PREFIX)/deployments/docker/build-generator/build.sh:/build.sh \
golang:1.19-alpine /build.sh
@docker build -t generator/toldata:$(IMAGE_TAG) -f deployments/docker/build-generator/Dockerfile deployments/docker/