This repository has been archived by the owner on Mar 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
131 lines (102 loc) · 2.85 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
APP ?= chart-streams
MODULE = $(subst -,,$(APP))
IMAGE = quay.io/otaviof/$(APP)
IMAGE_TAG = $(IMAGE):latest
IMAGE_DEV_TAG = $(IMAGE)-dev:latest
OUTPUT_DIR ?= _output
DEVCONTAINER_ARGS ?=
RUN_ARGS ?= serve
TEST_ARGS ?=
WORKING_DIR ?= /var/tmp/chart-streams
COMMON_FLAGS ?= -v -mod=vendor
CHARTS_REPO_ARCHIVE ?= test/charts-repo.tar.gz
CHARTS_REPO_DIR ?= $(OUTPUT_DIR)/charts-repo
TEST_TIMEOUT ?= 10m
TEST_FLAGS ?= -failfast -timeout=$(TEST_TIMEOUT)
UNIT_TEST_TARGET ?= ./cmd/... ./pkg/...
E2E_TEST_TARGET ?= ./test/e2e/...
COVERAGE_DIR ?= $(OUTPUT_DIR)/coverage
LIBGIT_VERSION ?=
LD_LIBRARY_PATH ?= /usr/local/lib
# all variables are exported to environment
.EXPORT_ALL_VARIABLES:
default: build
# initialize Go modules vendor directory
.PHONY: vendor
vendor:
@go mod vendor
# clean up build directory
.PHONY: clean
clean:
@rm -rf $(OUTPUT_DIR)
# compress local charts test repository
archive-charts-repo:
tar zcvpf $(CHARTS_REPO_ARCHIVE) $(CHARTS_REPO_DIR)
# uncompress test charts repository archive tarball
unarchive-charts-repo:
@rm -rf "$(CHARTS_REPO_DIR)"
@tar zxpf $(CHARTS_REPO_ARCHIVE)
# create build and coverage directories
.PHONY: prepare
prepare: unarchive-charts-repo
@mkdir -p $(COVERAGE_DIR) > /dev/null 2>&1 || true
# build application command-line
build: prepare vendor $(OUTPUT_DIR)/$(APP)
# application binary
$(OUTPUT_DIR)/$(APP):
go build $(COMMON_FLAGS) -o="$(OUTPUT_DIR)/$(APP)" cmd/$(MODULE)/*
# installs all development dependencies in the development container
devcontainer-deps:
./hack/fedora.sh
./hack/golang.sh
./hack/libgit2.sh
./hack/libgit2-devel.sh
./hack/yum-clean-up.sh
./hack/helm.sh
# build devcontainer image
devcontainer-image:
docker build --tag="$(IMAGE_DEV_TAG)" --file="Dockerfile.dev" .
# execute devcontainer mounting local project directory
devcontainer-run:
./hack/devcontainer-run.sh
# start a bash shell in devcontainer
devcontainer-exec:
@docker exec --interactive --tty --workdir="/workspaces/$(APP)" $(APP) bash
# installs final application image dependencies
image-deps:
./hack/fedora.sh
./hack/libgit2.sh
./hack/yum-clean-up.sh
# build container image with Docker
image:
docker build --tag="$(IMAGE_TAG)" .
# execute "go run" against cmd
run:
@test -d $(WORKING_DIR) && rm -rf $(WORKING_DIR)
@mkdir $(WORKING_DIR)
go run $(COMMON_FLAGS) cmd/$(MODULE)/* $(RUN_ARGS) --working-dir=$(WORKING_DIR)
# running all test targets
test: test-unit test-e2e
# run unit tests
.PHONY: test-unit
test-unit: prepare
go test \
$(COMMON_FLAGS) \
$(TEST_FLAGS) \
-coverprofile=$(COVERAGE_DIR)/coverage-unit.txt \
$(TEST_ARGS) \
$(UNIT_TEST_TARGET) \
# run end-to-end tests
.PHONY: test-e2e
test-e2e: prepare
go test \
$(COMMON_FLAGS) \
$(TEST_FLAGS) \
-coverprofile=$(COVERAGE_DIR)/coverage-e2e.txt \
$(E2E_TEST_TARGET)
.PHONY: lint
lint:
@golangci-lint run
.PHONY: libgit2
libgit2:
./hack/ubuntu/libgit2.sh