generated from alexejk/go-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
72 lines (58 loc) · 1.6 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
# We don't need make's built-in rules.
MAKEFLAGS += --no-builtin-rules
GO_FLAGS= CGO_ENABLED=0
GO_LDFLAGS= -ldflags=""
GO_BUILD_CMD=$(GO_FLAGS) go build $(GO_LDFLAGS)
BINARY_NAME=go-xmlrpc
BUILD_DIR=build
.PHONY: all
all: clean lint test build
#--------------------------------
# Validation steps
#--------------------------------
.PHONY: lint
lint: pre-build
@echo "Linting code..."
@sh hack/linter.sh
.PHONY: test
test: pre-build
@echo "Running tests..."
ifeq ($(CI), true)
@go test -short -coverprofile=build/coverage.txt -json ./... > build/test-report.json
else
@go test -short -coverprofile=build/coverage.txt -covermode=atomic ./...
endif
#--------------------------------
# Build steps
#--------------------------------
.PHONY: pre-build
pre-build:
@mkdir -p $(BUILD_DIR)
.PHONY: build
build:
@echo "Building..."
$(GO_BUILD_CMD)
#--------------------------------
# Docker steps
#--------------------------------
.PHONY: docker
docker:
# Build a new image (delete old one)
docker build --force-rm --build-arg GOPROXY --build-arg CI -t $(BINARY_NAME) .
.PHONY: build-in-docker
build-in-docker: docker
# Force-stop any containers with this name
docker rm -f $(BINARY_NAME) || true
# Create a new container with newly built image (but don't run it)
docker create --name $(BINARY_NAME) $(BINARY_NAME)
# Copy over the binary to disk (from container)
docker cp '$(BINARY_NAME):/opt/' $(BUILD_DIR)
# House-keeping: removing container
docker rm -f $(BINARY_NAME)
#--------------------------------
# Cleanup steps
#--------------------------------
.PHONY: clean
clean:
@echo "Cleaning..."
@rm -Rf $(BUILD_DIR)