-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
58 lines (47 loc) · 1.49 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
SHELL := /bin/bash
# Service specific vars
export COMPONENT_NAME := go-user-api
export COMPONENT_ARGS := $(if $(COMPONENT_ARGS),$(COMPONENT_ARGS),)
export SERVICE_PORT := $(if $(SERVICE_ADDR),$(SERVICE_ADDR),8899)
export SERVICE_ADDR := $(if $(SERVICE_ADDR),$(SERVICE_ADDR),:$(SERVICE_PORT))
export GOLANG_IMAGE :=golang:1.22
export GOLANG_LINTER_IMAGE :=golangci/golangci-lint:v1.21.0
export GOFLAGS:=-buildvcs=false
export E2E_TESTS_BIN := $(COMPONENT_NAME)_e2e_tests
.PHONY: proto
proto:
./pkg/proto/gen-go.sh
.PHONY: run
run: build
docker build -t ${COMPONENT_NAME}-image .
docker run -u 1000:1000 -p ${SERVICE_PORT}:${SERVICE_PORT} ${COMPONENT_NAME}-image
.PHONY: build
build:
docker run --rm \
-v ${PWD}:/usr/src/${COMPONENT_NAME} -w /usr/src/${COMPONENT_NAME} \
-e GOFLAGS=${GOFLAGS} \
-e GOOS=linux -e GOARCH=amd64 \
${GOLANG_IMAGE} go build -ldflags="-w -s" -o ./bin/$(COMPONENT_NAME) ./cmd/$(COMPONENT_NAME)/
.PHONY: lint
lint:
docker run --rm \
-v ${PWD}:/go \
${GOLANG_LINTER_IMAGE} golangci-lint run ${GOLANG_LINTER_ARGS}
.PHONY: test-all
test-all: test test-e2e
.PHONY: test
test:
docker run --rm \
-v ${PWD}:/usr/src/${COMPONENT_NAME} -w /usr/src/${COMPONENT_NAME} \
-e GOFLAGS=${GOFLAGS} \
${GOLANG_IMAGE} go test ./... -timeout 30s -count=1 ${ARGS}
.PHONY: test-e2e
test-e2e: build
docker run --rm \
-v ${PWD}:/go/app \
-e COMPONENT_NAME=${COMPONENT_NAME} \
-e GOFLAGS=${GOFLAGS} \
-e SERVICE_ADDR=${SERVICE_ADDR} \
-w /go/app \
${GOLANG_IMAGE} \
bash -c "./e2e.sh"