-
Notifications
You must be signed in to change notification settings - Fork 365
/
Makefile
203 lines (162 loc) · 5.66 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
VERSION := v1.3.0-rc0
# Name of this service/application
SERVICE_NAME := redis-operator
# Docker image name for this project
IMAGE_NAME := spotahome/$(SERVICE_NAME)
# Repository url for this project
REPOSITORY := quay.io/$(IMAGE_NAME)
# Shell to use for running scripts
SHELL := $(shell which bash)
# Get docker path or an empty string
DOCKER := $(shell command -v docker)
# Get the main unix group for the user running make (to be used by docker-compose later)
GID := $(shell id -g)
# Get the unix user id for the user running make (to be used by docker-compose later)
UID := $(shell id -u)
# Commit hash from git
COMMIT=$(shell git rev-parse HEAD)
GITTAG_COMMIT := $(shell git rev-list --tags --max-count=1)
GITTAG := $(shell git describe --abbrev=0 --tags ${GITTAG_COMMIT} 2>/dev/null || true)
# Branch from git
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
TAG := $(GITTAG)
ifneq ($(COMMIT), $(GITTAG_COMMIT))
TAG := $(COMMIT)
endif
ifneq ($(shell git status --porcelain),)
TAG := $(TAG)-dirty
endif
PROJECT_PACKAGE := github.com/spotahome/redis-operator
CODEGEN_IMAGE := ghcr.io/slok/kube-code-generator:v1.27.0
PORT := 9710
# CMDs
UNIT_TEST_CMD := go test `go list ./... | grep -v /vendor/` -v
GO_GENERATE_CMD := go generate `go list ./... | grep -v /vendor/`
GO_INTEGRATION_TEST_CMD := go test `go list ./... | grep test/integration` -v -tags='integration'
GET_DEPS_CMD := dep ensure
UPDATE_DEPS_CMD := dep ensure
MOCKS_CMD := go generate ./mocks
# environment dirs
DEV_DIR := docker/development
APP_DIR := docker/app
# workdir
WORKDIR := /go/src/github.com/spotahome/redis-operator
# The default action of this Makefile is to build the development docker image
.PHONY: default
default: build
# Run the development environment in non-daemonized mode (foreground)
.PHONY: docker-build
docker-build: deps-development
docker build \
--build-arg uid=$(UID) \
-t $(REPOSITORY)-dev:latest \
-t $(REPOSITORY)-dev:$(COMMIT) \
-f $(DEV_DIR)/Dockerfile \
.
# Run a shell into the development docker image
.PHONY: shell
shell: docker-build
docker run -ti --rm -v ~/.kube:/.kube:ro -v $(PWD):$(WORKDIR) -u $(UID):$(UID) --name $(SERVICE_NAME) -p $(PORT):$(PORT) $(REPOSITORY)-dev /bin/bash
# Build redis-failover executable file
.PHONY: build
build: docker-build
docker run -ti --rm -v $(PWD):$(WORKDIR) -u $(UID):$(UID) --name $(SERVICE_NAME) $(REPOSITORY)-dev ./scripts/build.sh
# Run the development environment in the background
.PHONY: run
run: docker-build
docker run -ti --rm -v ~/.kube:/.kube:ro -v $(PWD):$(WORKDIR) -u $(UID):$(UID) --name $(SERVICE_NAME) -p $(PORT):$(PORT) $(REPOSITORY)-dev ./scripts/run.sh
# Build the production image based on the public one
.PHONY: image
image: deps-development
docker build \
-t $(SERVICE_NAME) \
-t $(REPOSITORY):latest \
-t $(REPOSITORY):$(COMMIT) \
-t $(REPOSITORY):$(BRANCH) \
-f $(APP_DIR)/Dockerfile \
.
.PHONY: image-release
image-release:
docker buildx build \
--platform linux/amd64,linux/arm64,linux/arm/v7 \
--push \
--build-arg VERSION=$(TAG) \
-t $(REPOSITORY):latest \
-t $(REPOSITORY):$(COMMIT) \
-t $(REPOSITORY):$(TAG) \
-f $(APP_DIR)/Dockerfile \
.
.PHONY: testing
testing: image
docker push $(REPOSITORY):$(BRANCH)
.PHONY: tag
tag:
git tag $(VERSION)
.PHONY: publish
publish:
@COMMIT_VERSION="$$(git rev-list -n 1 $(VERSION))"; \
docker tag $(REPOSITORY):"$$COMMIT_VERSION" $(REPOSITORY):$(VERSION)
docker push $(REPOSITORY):$(VERSION)
docker push $(REPOSITORY):latest
.PHONY: release
release: tag image-release
# Test stuff in dev
.PHONY: unit-test
unit-test: docker-build
docker run -ti --rm -v $(PWD):$(WORKDIR) -u $(UID):$(UID) --name $(SERVICE_NAME) $(REPOSITORY)-dev /bin/sh -c '$(UNIT_TEST_CMD)'
.PHONY: ci-unit-test
ci-unit-test:
$(UNIT_TEST_CMD)
.PHONY: ci-integration-test
ci-integration-test:
$(GO_INTEGRATION_TEST_CMD)
.PHONY: integration-test
integration-test:
./scripts/integration-tests.sh
.PHONY: helm-test
helm-test:
./scripts/helm-tests.sh
# Run all tests
.PHONY: test
test: ci-unit-test ci-integration-test helm-test
.PHONY: go-generate
go-generate: docker-build
docker run -ti --rm -v $(PWD):$(WORKDIR) -u $(UID):$(UID) --name $(SERVICE_NAME) $(REPOSITORY)-dev /bin/sh -c '$(GO_GENERATE_CMD)'
.PHONY: generate
generate: go-generate
.PHONY: get-deps
get-deps: docker-build
docker run -ti --rm -v $(PWD):$(WORKDIR) -u $(UID):$(UID) --name $(SERVICE_NAME) $(REPOSITORY)-dev /bin/sh -c '$(GET_DEPS_CMD)'
.PHONY: update-deps
update-deps: docker-build
docker run -ti --rm -v $(PWD):$(WORKDIR) -u $(UID):$(UID) --name $(SERVICE_NAME) $(REPOSITORY)-dev /bin/sh -c '$(UPDATE_DEPS_CMD)'
.PHONY: mocks
mocks: docker-build
docker run -ti --rm -v $(PWD):$(WORKDIR) -u $(UID):$(UID) --name $(SERVICE_NAME) $(REPOSITORY)-dev /bin/sh -c '$(MOCKS_CMD)'
.PHONY: deps-development
# Test if the dependencies we need to run this Makefile are installed
deps-development:
ifndef DOCKER
@echo "Docker is not available. Please install docker"
@exit 1
endif
# Generate kubernetes code for types..
.PHONY: update-codegen
update-codegen:
@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-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