forked from phenixblue/imageswap-webhook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
229 lines (165 loc) · 6.88 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# Copyright 2020 The WebRoot, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
IMAGESWAP_VERSION := v1.3.0
IMAGESWAP_INIT_VERSION := v0.0.1
REPO_ROOT := $(CURDIR)
APP_NAME ?= "imageswap.py"
DEPLOY_DIR ?= $(CURDIR)/deploy
TESTING_DIR ?= $(CURDIR)/testing
WEBHOOK_NAMESPACE ?= "imageswap-system"
TEST_NAMESPACE ?= "test1"
DOCKER := docker
###############################################################################
# K8s Related Targets #########################################################
###############################################################################
# Create Namespace for ImageSwap
.PHONY: ns-create-imageswap
ns-create-imageswap:
kubectl create ns $(WEBHOOK_NAMESPACE)
# Create Namespace for testing
.PHONY: ns-create-test
ns-create-test:
kubectl create ns $(TEST_NAMESPACE)
kubectl label ns $(TEST_NAMESPACE) k8s.twr.io/imageswap=enabled --overwrite
# Delete Namespace for ImageSwap
.PHONY: ns-delete-imageswap
ns-delete-imageswap:
kubectl delete ns $(WEBHOOK_NAMESPACE)
# Delete Namespace for testing
.PHONY: ns-delete-test
ns-delete-test:
kubectl delete ns $(TEST_NAMESPACE)
# DEPRECATED - Moved to init application. Will be removed in the future.
.PHONY: cert-gen
cert-gen:
hack/ssl-cert-gen.sh \
--service imageswap \
--secret imageswap-certs \
--namespace $(WEBHOOK_NAMESPACE)
# Install ImageSwap (Demo Install)
.PHONY: install
install:
kubectl apply -f $(DEPLOY_DIR)/install.yaml
# Uninstall ImageSwap (Demo Install)
.PHONY: uninstall
uninstall:
kubectl delete -f $(DEPLOY_DIR)/install.yaml --ignore-not-found
kubectl delete mutatingwebhookconfiguration imageswap-webhook --ignore-not-found
kubectl delete csr imageswap.imageswap-system.cert-request --ignore-not-found
# Restart ImageSwap Pods (Demo Install)
.PHONY: restart
restart:
kubectl rollout restart deploy imageswap -n imageswap-system
# Cleanup ImageSwap (Demo Install)
.PHONY: clean
clean: uninstall
###############################################################################
# Python Targets ##############################################################
###############################################################################
# Run unit tests for ImageSwap/ImageSwap-Init
.PHONY: unit-python
unit-python:
hack/run-python-tests.sh
# Run unit tests for ImageSwap/ImageSwap-Init
.PHONY: test-python
test-python: unit-python
# Lint Python and update python code
.Phony: lint-python
lint-python:
black app/imageswap-init/ --line-length 160
black app/imageswap/ --line-length 160
# Verify linting of Python during CI
.PHONY: ci-lint-python
ci-lint-python:
black --check app/imageswap-init/ --line-length 160
black --check app/imageswap/ --line-length 160
###############################################################################
# Functional Test Targets #####################################################
###############################################################################
# Run ImageSwap functional tests for Deployments
.PHONY: test-functional
test-functional:
hack/run-functional-tests.sh test all all test1
# Run ImageSwap functional tests for Deployments
.PHONY: test-clean
test-clean:
hack/run-functional-tests.sh clean all all test1
# Run all unit and functional tests for ImageSwap/ImageSwap-Init
.PHONY: test-all
test-all: test test-functional
###############################################################################
# Misc Repo Targets ###########################################################
###############################################################################
# Verify copyright boilerplate in files
.PHONY: boilerplate
boilerplate:
hack/verify-boilerplate.sh
# Build dmeo install manifest for ImageSwap
.PHONY: build-single-manifest
build-single-manifest:
hack/build-single-manifest.sh build
PHONY: compare-single-manifest
compare-single-manifest:
hack/build-single-manifest.sh compare
# Set release version in deployment manifest
.PHONY: set-release-version
set-release-version:
sed -i='' "s/\(image: thewebroot\/imageswap-init:\).*/\1${IMAGESWAP_INIT_VERSION}/" deploy/manifests/imageswap-deploy.yaml
sed -i='' "s/\(image: thewebroot\/imageswap:\).*/\1${IMAGESWAP_VERSION}/" deploy/manifests/imageswap-deploy.yaml
sed -i='' "s/\(version\)=\"latest\"\(.*\)/\1=\"${IMAGESWAP_VERSION}\"\2/" app/imageswap/imageswap.py
sed -i='' "s/\(ImageSwap\).*\(Startup\)/\1 ${IMAGESWAP_VERSION} \2/" app/imageswap/imageswap.py
# Cut new ImageSwap release
.PHONY: release
release: echo
###############################################################################
# Container Image Targets #####################################################
###############################################################################
# Build ImageSwap-Init container image
.PHONY: build-imageswap-init-latest
build-imageswap-init-latest:
$(DOCKER) build -t thewebroot/imageswap-init:latest app/imageswap-init/
# Push ImageSwap-Init container image to DockerHub
.PHONY: push-imageswap-init-latest
push-imageswap-init-latest:
$(DOCKER) push thewebroot/imageswap-init:latest
# Build ImageSwap container image
.PHONY: build-imageswap-latest
build-imageswap-latest:
$(DOCKER) build -t thewebroot/imageswap:latest app/imageswap/
# Push ImageSwap container image to DockerHub
.PHONY: push-imageswap-latest
push-imageswap-latest:
$(DOCKER) push thewebroot/imageswap:latest
# Build and push all ImageSwap container images to DockerHub
.PHONY: build-latest
build-latest: build-imageswap-init-latest push-imageswap-init-latest build-imageswap-latest push-imageswap-latest
# Build ImageSwap-Init container image
.PHONY: build-imageswap-init-versioned
build-imageswap-init-versioned:
$(DOCKER) build -t thewebroot/imageswap-init:${IMAGESWAP_INIT_VERSION} app/imageswap-init/
# Push ImageSwap-Init container image to DockerHub
.PHONY: push-imageswap-init-versioned
push-imageswap-init-versioned:
$(DOCKER) push thewebroot/imageswap-init:${IMAGESWAP_INIT_VERSION}
# Build ImageSwap container image
.PHONY: build-imageswap-versioned
build-imageswap-versioned:
$(DOCKER) build -t thewebroot/imageswap:${IMAGESWAP_VERSION} app/imageswap/
# Push ImageSwap container image to DockerHub
.PHONY: push-imageswap-versioned
push-imageswap-versioned:
$(DOCKER) push thewebroot/imageswap:${IMAGESWAP_VERSION}
# Build and push all ImageSwap container images to DockerHub
.PHONY: build-versioned
build-versioned: build-imageswap-init-versioned push-imageswap-init-versioned build-imageswap-versioned push-imageswap-versioned