-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
184 lines (153 loc) · 5.8 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
# Makefile for shipping and testing the container image.
MAKEFLAGS += --warn-undefined-variables
.DEFAULT_GOAL := build
.PHONY: *
# we get these from CI environment if available, otherwise from git
GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
WORKSPACE ?= $(shell pwd)
namespace ?= autopilotpattern
tag := branch-$(shell basename $(GIT_BRANCH))
image := $(namespace)/redis
testImage := $(namespace)/redis-testrunner
dockerLocal := DOCKER_HOST= DOCKER_TLS_VERIFY= DOCKER_CERT_PATH= docker
composeLocal := DOCKER_HOST= DOCKER_TLS_VERIFY= DOCKER_CERT_PATH= docker-compose
## Display this help message
help:
@awk '/^##.*$$/,/[a-zA-Z_-]+:/' $(MAKEFILE_LIST) | awk '!(NR%2){print $$0p}{p=$$0}' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' | sort
# ------------------------------------------------
# Container builds
## Builds the application container image locally
build: test-runner
$(dockerLocal) build -t=$(image):$(tag) .
## Build the test running container
test-runner:
$(dockerLocal) build -f test/Dockerfile -t=$(testImage):$(tag) .
## Push the current application container images to the Docker Hub
push:
$(dockerLocal) push $(image):$(tag)
$(dockerLocal) push $(testImage):$(tag)
## Tag the current images as 'latest'
tag:
$(dockerLocal) tag $(testImage):$(tag) $(testImage):latest
$(dockerLocal) tag $(image):$(tag) $(image):latest
## Push latest tag(s) to the Docker Hub
ship: tag
$(dockerLocal) push $(image):$(tag)
$(dockerLocal) push $(image):latest
# ------------------------------------------------
# Test running
## Pull the container images from the Docker Hub
pull:
docker pull $(image):$(tag)
docker pull $(testImage):$(tag)
$(DOCKER_CERT_PATH)/key.pub:
ssh-keygen -y -f $(DOCKER_CERT_PATH)/key.pem > $(DOCKER_CERT_PATH)/key.pub
# For Jenkins test runner only: make sure we have public keys available
SDC_KEYS_VOL ?= -v $(DOCKER_CERT_PATH):$(DOCKER_CERT_PATH)
keys: $(DOCKER_CERT_PATH)/key.pub
run-local:
cd examples/compose && TAG=$(tag) $(composeLocal) -p redis up -d
stop-local:
cd examples/compose && TAG=$(tag) $(composeLocal) -p redis stop || true
cd examples/compose && TAG=$(tag) $(composeLocal) -p redis rm -f || true
run:
$(call check_var, TRITON_PROFILE \
required to run the example on Triton.)
cd examples/triton && TAG=$(tag) docker-compose -p redis up -d
stop:
$(call check_var, TRITON_PROFILE \
required to run the example on Triton.)
cd examples/compose && TAG=$(tag) docker-compose -p redis stop || true
cd examples/compose && TAG=$(tag) docker-compose -p redis rm -f || true
test-image:
docker build -f test/Dockerfile .
run-test-image-local:
$(dockerLocal) run -it --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-e TAG=$(tag) \
-e COMPOSE_FILE=compose/docker-compose.yml \
-e COMPOSE_HTTP_TIMEOUT=300 \
-w /src \
`docker build -f test/Dockerfile . | tail -n 1 | awk '{print $$3}'` \
sh
run-test-image:
$(call check_var, TRITON_ACCOUNT TRITON_DC, \
required to run integration tests on Triton.)
$(dockerLocal) run -it --rm \
-e TAG=$(tag) \
-e COMPOSE_FILE=triton/docker-compose.yml \
-e COMPOSE_HTTP_TIMEOUT=300 \
-e DOCKER_HOST=$(DOCKER_HOST) \
-e DOCKER_TLS_VERIFY=1 \
-e DOCKER_CERT_PATH=$(DOCKER_CERT_PATH) \
-e TRITON_ACCOUNT=$(TRITON_ACCOUNT) \
-e TRITON_DC=$(TRITON_DC) \
$(SDC_KEYS_VOL) -w /src \
$(testImage):$(tag) sh
## Run integration tests against local Docker daemon
test-local:
$(dockerLocal) run -it --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-e TAG=$(tag) \
-e COMPOSE_FILE=compose/docker-compose.yml \
-e COMPOSE_HTTP_TIMEOUT=300 \
-w /src \
`docker build -f test/Dockerfile . | tail -n 1 | awk '{print $$3}'` \
python3 tests.py
## Run the integration test runner locally but target Triton
test:
$(call check_var, TRITON_ACCOUNT TRITON_DC, \
required to run integration tests on Triton.)
$(dockerLocal) run --rm \
-e TAG=$(tag) \
-e COMPOSE_FILE=triton/docker-compose.yml \
-e COMPOSE_HTTP_TIMEOUT=300 \
-e DOCKER_HOST=$(DOCKER_HOST) \
-e DOCKER_TLS_VERIFY=1 \
-e DOCKER_CERT_PATH=$(DOCKER_CERT_PATH) \
-e TRITON_ACCOUNT=$(TRITON_ACCOUNT) \
-e TRITON_DC=$(TRITON_DC) \
$(SDC_KEYS_VOL) -w /src \
$(testImage):$(tag) sh tests.sh
## Print environment for build debugging
debug:
@echo WORKSPACE=$(WORKSPACE)
@echo GIT_COMMIT=$(GIT_COMMIT)
@echo GIT_BRANCH=$(GIT_BRANCH)
@echo namespace=$(namespace)
@echo tag=$(tag)
@echo image=$(image)
@echo testImage=$(testImage)
# Create backup user/policies (usage: make manta [email protected] PASSWORD=pwd)
# -------------------------------------------------------
# Create user and policies for backups
# Requires SDC_ACCOUNT to be set
# usage:
# make manta [email protected] PASSWORD=strongpassword
#
## Create backup user and policies
manta:
$(call check_var, EMAIL PASSWORD SDC_ACCOUNT, \
Required to create a Manta login.)
ssh-keygen -t rsa -b 4096 -C "${EMAIL}" -f manta
sdc-user create --login=${MANTA_LOGIN} --password=${PASSWORD} --email=${EMAIL}
sdc-user upload-key $(ssh-keygen -E md5 -lf ./manta | awk -F' ' '{gsub("MD5:","");{print $2}}') --name=${MANTA_LOGIN}-key ${MANTA_LOGIN} ./manta.pub
sdc-policy create --name=${MANTA_POLICY} \
--rules='CAN getobject' \
--rules='CAN putobject' \
--rules='CAN putmetadata' \
--rules='CAN putsnaplink' \
--rules='CAN getdirectory' \
--rules='CAN putdirectory'
sdc-role create --name=${MANTA_ROLE} \
--policies=${MANTA_POLICY} \
--members=${MANTA_LOGIN}
mmkdir ${SDC_ACCOUNT}/stor/${MANTA_LOGIN}
mchmod -- +triton_redis /${SDC_ACCOUNT}/stor/${MANTA_LOGIN}
# -------------------------------------------------------
# helper functions for testing if variables are defined
#
check_var = $(foreach 1,$1,$(__check_var))
__check_var = $(if $(value $1),,\
$(error Missing $1 $(if $(value 2),$(strip $2))))