forked from spotahome/redis-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
154 lines (128 loc) · 4.11 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
148
149
150
151
152
153
154
VERSION := v4.0.0
# Name of this service/application
SERVICE_NAME := redis-operator
# Docker image name for this project
IMAGE_NAME := powerhome/$(SERVICE_NAME)
# Repository url for this project
REPOSITORY := $(IMAGE_NAME)
# Get docker path or an empty string
DOCKER := $(shell command -v docker)
# Get the unix user id for the user running make (to be used by docker bake)
UID := $(shell id -u)
GIT_COMMIT=$(shell git rev-parse HEAD)
IMAGE_TAG := $(GIT_COMMIT)
ifneq ($(shell git status --porcelain),)
IMAGE_TAG := $(IMAGE_TAG)-dirty
endif
PROJECT_PACKAGE := github.com/spotahome/redis-operator
CODEGEN_IMAGE := ghcr.io/slok/kube-code-generator:v1.27.0
PORT := 9710
# workdir
WORKDIR := /go/src/github.com/spotahome/redis-operator
# CMDs
UNIT_TEST_CMD := go test `go list ./... | grep -v /vendor/` -v
HELM_TEST_CMD := ./scripts/helm-tests.sh
GO_GENERATE_CMD := go generate `go list ./... | grep -v /vendor/`
GO_INTEGRATION_TEST_CMD := go test `go list ./... | grep test/integration` -v -tags='integration'
MOCKS_CMD := go generate ./mocks
DOCKER_RUN_CMD := $(DOCKER) run -ti --rm \
-v $(PWD):$(WORKDIR) \
-u $(UID):$(UID) \
--name $(SERVICE_NAME) \
-p $(PORT):$(PORT) \
$(REPOSITORY)-dev
# The default action of this Makefile is to build the development docker image
.PHONY: default
default: test
.PHONY: ensure-docker
# Test if the dependencies we need to run this Makefile are installed
ensure-docker:
ifndef DOCKER
@echo "Docker is not available. Please install docker"
@exit 1
endif
# Build the operator image for local, end-to-end testing purposes
.PHONY: image-local
image-local: ensure-docker
docker buildx bake \
--set build-local.tags="$(IMAGE_NAME):latest" \
--set build-local.tags="$(IMAGE_NAME):$(IMAGE_TAG)" \
build-local
# Build the development environment docker image
.PHONY: image-dev-tools
image-dev-tools: ensure-docker
docker buildx bake \
--set dev.args.uid=$(UID) \
--set dev.tags="$(IMAGE_NAME)-dev:latest" \
dev
# Connect to a BASH shell the development docker image
.PHONY: shell
shell: image-dev-tools
$(DOCKER_RUN_CMD) /bin/bash
# Create a git tag using the VERSION
.PHONY: tag
tag:
git tag $(VERSION)
# Run unit tests in the development docker container (DEV)
.PHONY: test-unit
test-unit: image-dev-tools
$(DOCKER_RUN_CMD) /bin/sh -c '$(UNIT_TEST_CMD)'
# Run helm tests in the development docker container (DEV)
.PHONY: test-helm
test-helm:
$(DOCKER_RUN_CMD) $(HELM_TEST_CMD)
# Run all (DEV) tests
.PHONY: test
test: test-unit test-helm
# Run unit tests on the host (CI)
.PHONY: test-unit-ci
test-unit-ci:
$(UNIT_TEST_CMD)
# Run integration tests on the host (CI)
.PHONY: test-integration-ci
test-integration-ci:
$(GO_INTEGRATION_TEST_CMD)
# Run helm tests on the host (CI)
.PHONY: test-helm-ci
test-helm-ci:
$(HELM_TEST_CMD)
# Generate kubernetes client
.PHONY: generate-client
generate-client:
@echo ">> Generating code for Kubernetes CRD types..."
docker run --rm -it \
-v $(PWD):/go/src/$(PROJECT_PACKAGE) \
-e PROJECT_PACKAGE=$(PROJECT_PACKAGE) \
-e CLIENT_GENERATOR_OUT=$(PROJECT_PACKAGE)/client/k8s \
-e APIS_ROOT=$(PROJECT_PACKAGE)/api \
-e GROUPS_VERSION="redisfailover:v1" \
-e GENERATION_TARGETS="deepcopy,client" \
$(CODEGEN_IMAGE)
# Generate kubernetes Custom Resource Definitions
.PHONY: generate-crd
generate-crd:
docker run -it --rm \
-v $(PWD):/go/src/$(PROJECT_PACKAGE) \
-e GO_PROJECT_ROOT=/go/src/$(PROJECT_PACKAGE) \
-e CRD_TYPES_PATH=/go/src/$(PROJECT_PACKAGE)/api \
-e CRD_OUT_PATH=/go/src/$(PROJECT_PACKAGE)/manifests \
$(CODEGEN_IMAGE) update-crd.sh
cp -f manifests/databases.spotahome.com_redisfailovers.yaml manifests/kustomize/base
.PHONY: generate-go
generate-go: image-dev-tools
docker run -ti --rm \
-v $(PWD):$(WORKDIR) \
-u $(UID):$(UID) \
--name $(SERVICE_NAME) $(REPOSITORY)-dev \
/bin/sh -c '$(GO_GENERATE_CMD)'
# Generate testing mocks
.PHONY: generate-mocks
generate-mocks: image-dev-tools
docker run -ti --rm \
-v $(PWD):$(WORKDIR) \
-u $(UID):$(UID) \
--name $(SERVICE_NAME) \
$(REPOSITORY)-dev /bin/sh -c '$(MOCKS_CMD)'
# Run all code generators
.PHONY: generate
generate: generate-go generate-mocks generate-client generate-crd