forked from spotahome/redis-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
157 lines (122 loc) · 4.36 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
VERSION := v1.0.0
# 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)
# Branch from git
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
PORT := 9710
# CMDs
UNIT_TEST_CMD := go test `go list ./... | grep -v /vendor/` -v
GO_GENERATE_CMD := go generate `go list ./... | grep -v /vendor/`
GET_DEPS_CMD := dep ensure
UPDATE_DEPS_CMD := dep ensure
UPDATE_CODEGEN_CMD := ./hack/update-codegen.sh
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: 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 publish
# 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: 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 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: docker-build
@echo ">> Generating code for Kubernetes CRD types..."
docker run --rm -v $(PWD):/go/src/github.com/spotahome/redis-operator/ $(REPOSITORY)-dev /bin/bash -c '$(UPDATE_CODEGEN_CMD)'