-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
Makefile
739 lines (703 loc) · 25.9 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
# Additional Makefiles are pulled from:
# https://github.com/devilbox/makefiles/
ifneq (,)
.error This Makefile requires GNU Make.
endif
# Ensure additional Makefiles are present
MAKEFILES = Makefile.docker Makefile.lint
$(MAKEFILES): URL=https://raw.githubusercontent.com/devilbox/makefiles/master/$(@)
$(MAKEFILES):
@if ! (curl --fail -sS -o $(@) $(URL) || wget -O $(@) $(URL)); then \
echo "Error, curl or wget required."; \
echo "Exiting."; \
false; \
fi
include $(MAKEFILES)
# Set default Target
.DEFAULT_GOAL := help
# -------------------------------------------------------------------------------------------------
# Default configuration
# -------------------------------------------------------------------------------------------------
# Own vars
TAG = latest
# Makefile.docker overwrites
NAME = ansible
VERSION = latest
IMAGE = cytopia/ansible
FLAVOUR = default
STAGE = base
DIR = Dockerfiles
FILE = Dockerfile-$(STAGE)
DOCKER_TAG = $(VERSION)
ifeq ($(strip $(STAGE)),base)
DOCKER_TAG = $(VERSION)
else
DOCKER_TAG = $(VERSION)-$(STAGE)$(KOPS)$(HELM)
endif
# Makefile.lint overwrites
FL_IGNORES = .git/,.github/,tests/
SC_IGNORES = .git/,.github/,tests/
JL_IGNORES = .git/,.github/,./tests/
# -------------------------------------------------------------------------------------------------
# Default Target
# -------------------------------------------------------------------------------------------------
.PHONY: help
help:
@echo "--------------------------------------------------------------------------------"
@echo " Build Targets"
@echo "--------------------------------------------------------------------------------"
@echo
@echo "All Docker images are build as follows: $(IMAGE):\$$VERSION[-\$$STAGE[\$$KOPS|\$$HELM]]"
@echo
@echo "build [VERSION=] [ARCH=] [KOPS=] [HELM=] Build Docker image"
@echo "rebuild [VERSION=] [ARCH=] [KOPS=] [HELM=] Build Docker image without cache"
@echo
@echo " make build VERSION=2.3"
@echo " make build VERSION=2.3 STAGE=tools"
@echo " make build VERSION=2.3 STAGE=infra"
@echo " make build VERSION=2.3 STAGE=azure"
@echo " make build VERSION=2.3 STAGE=aws"
@echo " make build VERSION=2.3 STAGE=awsk8s"
@echo " make build VERSION=2.3 STAGE=awshelm HELM=2.11"
@echo " make build VERSION=2.3 STAGE=awskops KOPS=1.15"
@echo
@echo "--------------------------------------------------------------------------------"
@echo " Test Targets"
@echo "--------------------------------------------------------------------------------"
@echo
@echo "test [VERSION=] [ARCH=] [KOPS=] [HELM=] Test built Docker image"
@echo
@echo " make test VERSION=2.3"
@echo " make test VERSION=2.3 STAGE=tools"
@echo " make test VERSION=2.3 STAGE=infra"
@echo " make test VERSION=2.3 STAGE=azure"
@echo " make test VERSION=2.3 STAGE=aws"
@echo " make test VERSION=2.3 STAGE=awsk8s"
@echo " make test VERSION=2.3 STAGE=awshelm HELM=2.11"
@echo " make test VERSION=2.3 STAGE=awskops KOPS=1.15"
@echo
@echo "--------------------------------------------------------------------------------"
@echo " Tagging Target"
@echo "--------------------------------------------------------------------------------"
@echo
@echo "tag [VERSION=] [ARCH=] [KOPS=] [HELM=] [TAG=] Tag built Docker image"
@echo
@echo " make tag VERSION=2.3 TAG=2.3-mysuffix"
@echo " make tag VERSION=2.3 STAGE=tools TAG=2.3-tools-mysuffix"
@echo " make tag VERSION=2.3 STAGE=infra TAG=2.3-infra-mysuffix"
@echo " make tag VERSION=2.3 STAGE=azure TAG=2.3-azure-mysuffix"
@echo " make tag VERSION=2.3 STAGE=aws TAG=2.3-aws-mysuffix"
@echo " make tag VERSION=2.3 STAGE=awsk8s TAG=2.3-awsk8s-mysuffix"
@echo " make tag VERSION=2.3 STAGE=awshelm HELM=2.11 TAG=2.3-awshelm-mysuffix"
@echo " make tag VERSION=2.3 STAGE=awskops KOPS=1.15 TAG=2.3-awskops-mysuffix"
# -------------------------------------------------------------------------------------------------
# Docker Targets
# -------------------------------------------------------------------------------------------------
.PHONY: build
build: ARGS+=--build-arg VERSION=$(VERSION)
build: ARGS+=--build-arg KOPS=$(KOPS)
build: ARGS+=--build-arg HELM=$(HELM)
build: docker-arch-build
.PHONY: rebuild
rebuild: ARGS+=--build-arg VERSION=$(VERSION)
rebuild: ARGS+=--build-arg KOPS=$(KOPS)
rebuild: ARGS+=--build-arg HELM=$(HELM)
rebuild: docker-arch-rebuild
.PHONY: tag
tag:
@if [ "$(TAG)" = "latest" ]; then \
if [ "$(STAGE)" = "base" ]; then \
echo "docker tag $(IMAGE):$(DOCKER_TAG) $(IMAGE):$(VERSION)"; \
docker tag $(IMAGE):$(DOCKER_TAG) $(IMAGE):$(VERSION); \
else \
echo "docker tag $(IMAGE):$(DOCKER_TAG) $(IMAGE):$(VERSION)-$(STAGE)$(KOPS)$(HELM)"; \
docker tag $(IMAGE):$(DOCKER_TAG) $(IMAGE):$(VERSION)-$(STAGE)$(KOPS)$(HELM); \
fi \
else \
if [ "$(STAGE)" = "base" ]; then \
echo "docker tag $(IMAGE):$(DOCKER_TAG) $(IMAGE):$(VERSION)-$(TAG)"; \
docker tag $(IMAGE):$(DOCKER_TAG) $(IMAGE):$(VERSION)-$(TAG); \
else \
echo "docker tag $(IMAGE):$(DOCKER_TAG) $(IMAGE):$(VERSION)-$(STAGE)$(KOPS)$(HELM)-$(TAG)"; \
docker tag $(IMAGE):$(DOCKER_TAG) $(IMAGE):$(VERSION)-$(STAGE)$(KOPS)$(HELM)-$(TAG); \
fi \
fi
.PHONY: push
ifeq ($(strip $(TAG)),latest)
ifeq ($(strip $(STAGE)),base)
push: DOCKER_TAG = $(VERSION)
push: docker-arch-push
else
push: DOCKER_TAG = $(VERSION)-$(STAGE)$(KOPS)$(HELM)
push: docker-arch-push
endif
else
ifeq ($(strip $(STAGE)),base)
push: DOCKER_TAG = $(VERSION)-$(TAG)
push: docker-arch-push
else
push: DOCKER_TAG = $(VERSION)-$(STAGE)$(KOPS)$(HELM)-$(TAG)
push: docker-arch-push
endif
endif
# -------------------------------------------------------------------------------------------------
# Manifest Targets
# -------------------------------------------------------------------------------------------------
.PHONY: manifest-create
ifeq ($(strip $(TAG)),latest)
ifeq ($(strip $(STAGE)),base)
manifest-create: DOCKER_TAG = $(VERSION)
manifest-create: docker-manifest-create
else
manifest-create: DOCKER_TAG = $(VERSION)-$(STAGE)$(KOPS)$(HELM)
manifest-create: docker-manifest-create
endif
else
ifeq ($(strip $(STAGE)),base)
manifest-create: DOCKER_TAG = $(VERSION)-$(TAG)
manifest-create: docker-manifest-create
else
manifest-create: DOCKER_TAG = $(VERSION)-$(STAGE)$(KOPS)$(HELM)-$(TAG)
manifest-create: docker-manifest-create
endif
endif
.PHONY: manifest-push
ifeq ($(strip $(TAG)),latest)
ifeq ($(strip $(STAGE)),base)
manifest-push: DOCKER_TAG = $(VERSION)
manifest-push: docker-manifest-push
else
manifest-push: DOCKER_TAG = $(VERSION)-$(STAGE)$(KOPS)$(HELM)
manifest-push: docker-manifest-push
endif
else
ifeq ($(strip $(STAGE)),base)
manifest-push: DOCKER_TAG = $(VERSION)-$(TAG)
manifest-push: docker-manifest-push
else
manifest-push: DOCKER_TAG = $(VERSION)-$(STAGE)$(KOPS)$(HELM)-$(TAG)
manifest-push: docker-manifest-push
endif
endif
# -------------------------------------------------------------------------------------------------
# Save / Load Targets
# -------------------------------------------------------------------------------------------------
.PHONY: save
save: docker-save
.PHONY: load
load: docker-load
.PHONY: save-verify
save-verify: save
save-verify: load
# -------------------------------------------------------------------------------------------------
# Test Targets
# -------------------------------------------------------------------------------------------------
.PHONY: test
test: test-architecture-uname
test: test-architecture-inspect
test: test-ansible-version
test: test-python-libs
test: test-binaries
test: test-helm-version
test: test-kops-version
test: test-run-user-root
test: test-run-user-ansible
.PHONY: test-architecture-uname
test-architecture-uname:
@echo "################################################################################"
@echo "# Testing correct Architecture - uname ($(ARCH))"
@echo "################################################################################"
@echo "docker run --rm --platform $(ARCH) --entrypoint=sh $(IMAGE):$(DOCKER_TAG) -c 'uname -m'"
@\
if [ "$(ARCH)" = "linux/amd64" ]; then \
if ! docker run --rm --platform $(ARCH) --entrypoint=sh $(IMAGE):$(DOCKER_TAG) -c 'uname -m' | grep -E '^x86_64$$'; then \
echo "[FAILED]"; \
docker run --rm --platform $(ARCH) --entrypoint=sh $(IMAGE):$(DOCKER_TAG) -c 'uname -m'; \
exit 1; \
fi; \
elif [ "$(ARCH)" = "linux/arm64" ]; then \
if ! docker run --rm --platform $(ARCH) --entrypoint=sh $(IMAGE):$(DOCKER_TAG) -c 'uname -m' | grep -E '^aarch64$$'; then \
echo "[FAILED]"; \
docker run --rm --platform $(ARCH) --entrypoint=sh $(IMAGE):$(DOCKER_TAG) -c 'uname -m'; \
exit 1; \
fi; \
else \
echo "[FAILED]"; \
echo "Wrong ARCH variable specified: $(ARCH)"; \
exit 1; \
fi; \
echo "[SUCCESS]"; \
echo
.PHONY: test-architecture-inspect
test-architecture-inspect:
@echo "################################################################################"
@echo "# Testing correct Architecture - inspect ($(ARCH))"
@echo "################################################################################"
@echo "docker image inspect $(IMAGE):$(DOCKER_TAG) -f '{{ .Architecture }}'"
@\
if [ "$(ARCH)" = "linux/amd64" ]; then \
if ! docker image inspect $(IMAGE):$(DOCKER_TAG) -f '{{ .Architecture }}' | grep -E '^amd64$$'; then \
echo "[FAILED]"; \
docker image inspect $(IMAGE):$(DOCKER_TAG) -f '{{ .Architecture }}'; \
exit 1; \
fi; \
elif [ "$(ARCH)" = "linux/arm64" ]; then \
if ! docker image inspect $(IMAGE):$(DOCKER_TAG) -f '{{ .Architecture }}' | grep -E '^arm64$$'; then \
echo "[FAILED]"; \
docker image inspect $(IMAGE):$(DOCKER_TAG) -f '{{ .Architecture }}'; \
exit 1; \
fi; \
else \
echo "[FAILED]"; \
echo "Wrong ARCH variable specified: $(ARCH)"; \
exit 1; \
fi; \
echo "[SUCCESS]"; \
echo
.PHONY: test-ansible-version
test-ansible-version:
@echo "################################################################################"
@echo "# Testing correct Ansible version"
@echo "################################################################################"
@\
if echo '$(ANSIBLE)' | grep -Eq 'latest\-?'; then \
echo "Fetching latest version from GitHub"; \
TEST_VERSION="$$( \
curl -L -sS https://github.com/ansible/ansible/releases/ \
| tac | tac \
| grep -Eo "ansible/ansible/releases/tag/v[.0-9]+\"" \
| sed 's/.*v//g' \
| sed 's/\"//g' \
| sort -V \
| tail -1 \
)"; \
else \
TEST_VERSION="$$( echo '$(ANSIBLE)' )"; \
fi; \
\
\
echo "Testing against Ansible version: $${TEST_VERSION}"; \
echo "docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) ansible --version | grep -E \"^[Aa]nsible.+$${TEST_VERSION}\""; \
\
\
if ! docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) ansible --version | grep -E "^[Aa]nsible.+$${TEST_VERSION}"; then \
echo "[FAILED]"; \
docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) ansible --version; \
exit 1; \
fi; \
echo "[SUCCESS]"; \
echo
.PHONY: test-python-libs
test-python-libs:
@echo "################################################################################"
@echo "# Testing correct Python libraries"
@echo "################################################################################"
@echo "docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) pip3 freeze"
@\
\
\
LIBS="$$( docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) pip3 freeze )"; \
\
\
REQUIRED_BASE="cffi cryptography paramiko Jinja2 PyYAML"; \
REQUIRED_TOOLS="dnspython mitogen jmespath"; \
REQUIRED_INFRA="docker docker-compose jsondiff pexpect psycopg2 pypsexec pymongo PyMySQL smbprotocol pywinrm"; \
REQUIRED_AZURE="azure\-.*"; \
REQUIRED_AWS="awscli botocore boto boto3"; \
REQUIRED_AWSK8S="openshift"; \
REQUIRED_AWSKOPS=""; \
REQUIRED_AWSHELM=""; \
\
\
if [ "$(STAGE)" = "base" ]; then \
for lib in $$( echo $${REQUIRED_BASE} ); do \
if echo "$${LIBS}" | grep -E "^$${lib}" >/dev/null; then \
echo "[OK] required lib available: $${lib}"; \
else \
echo "[FAILED] required lib not available: $${lib}"; \
exit 1; \
fi; \
done; \
for lib in $${REQUIRED_TOOLS}; do \
if ! echo "$${LIBS}" | grep -E "^$${lib}" >/dev/null; then \
echo "[OK] unwanted lib not available: $${lib}"; \
else \
echo "[FAILED] unwanted lib available: $${lib}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(STAGE)" = "tools" ]; then \
for lib in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} ); do \
if echo "$${LIBS}" | grep -E "^$${lib}" >/dev/null; then \
echo "[OK] required lib available: $${lib}"; \
else \
echo "[FAILED] required lib not available: $${lib}"; \
exit 1; \
fi; \
done; \
for lib in $${REQUIRED_INFRA}; do \
if ! echo "$${LIBS}" | grep -E "^$${lib}" >/dev/null; then \
echo "[OK] unwanted lib not available: $${lib}"; \
else \
echo "[FAILED] unwanted lib available: $${lib}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(STAGE)" = "infra" ]; then \
for lib in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} $${REQUIRED_INFRA} ); do \
if echo "$${LIBS}" | grep -E "^$${lib}" >/dev/null; then \
echo "[OK] required lib available: $${lib}"; \
else \
echo "[FAILED] required lib not available: $${lib}"; \
exit 1; \
fi; \
done; \
for lib in $${REQUIRED_AZURE}; do \
if ! echo "$${LIBS}" | grep -E "^$${lib}" >/dev/null; then \
echo "[OK] unwanted lib not available: $${lib}"; \
else \
echo "[FAILED] unwanted lib available: $${lib}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(STAGE)" = "azure" ]; then \
for lib in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} $${REQUIRED_AZURE} ); do \
if echo "$${LIBS}" | grep -E "^$${lib}" >/dev/null; then \
echo "[OK] required lib available: $${lib}"; \
else \
echo "[FAILED] required lib not available: $${lib}"; \
exit 1; \
fi; \
done; \
for lib in $${REQUIRED_AWS}; do \
if ! echo "$${LIBS}" | grep -E "^$${lib}" >/dev/null; then \
echo "[OK] unwanted lib not available: $${lib}"; \
else \
echo "[FAILED] unwanted lib available: $${lib}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(STAGE)" = "aws" ]; then \
for lib in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} $${REQUIRED_AWS} ); do \
if echo "$${LIBS}" | grep -E "^$${lib}" >/dev/null; then \
echo "[OK] required lib available: $${lib}"; \
else \
echo "[FAILED] required lib not available: $${lib}"; \
exit 1; \
fi; \
done; \
for lib in $${REQUIRED_AWSK8S}; do \
if ! echo "$${LIBS}" | grep -E "^$${lib}" >/dev/null; then \
echo "[OK] unwanted lib not available: $${lib}"; \
else \
echo "[FAILED] unwanted lib available: $${lib}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(STAGE)" = "awsk8s" ]; then \
for lib in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} $${REQUIRED_AWS} $${REQUIRED_AWSK8S} ); do \
if echo "$${LIBS}" | grep -E "^$${lib}" >/dev/null; then \
echo "[OK] required lib available: $${lib}"; \
else \
echo "[FAILED] required lib not available: $${lib}"; \
exit 1; \
fi; \
done; \
for lib in $$( echo $${REQUIRED_AWSKOPS} $${REQUIRED_AWSHELM} ); do \
if ! echo "$${LIBS}" | grep -E "^$${lib}" >/dev/null; then \
echo "[OK] unwanted lib not available: $${lib}"; \
else \
echo "[FAILED] unwanted lib available: $${lib}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(STAGE)" = "awskops" ]; then \
for lib in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} $${REQUIRED_AWS} $${REQUIRED_AWSK8S} $${REQUIRED_AWSKOPS} ); do \
if echo "$${LIBS}" | grep -E "^$${lib}" >/dev/null; then \
echo "[OK] required lib available: $${lib}"; \
else \
echo "[FAILED] required lib not available: $${lib}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(STAGE)" = "awshelm" ]; then \
for lib in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} $${REQUIRED_AWS} $${REQUIRED_AWSK8S} $${REQUIRED_AWSHELM} ); do \
if echo "$${LIBS}" | grep -E "^$${lib}" >/dev/null; then \
echo "[OK] required lib available: $${lib}"; \
else \
echo "[FAILED] required lib not available: $${lib}"; \
exit 1; \
fi; \
done; \
\
fi; \
echo "[SUCCESS]"; \
echo
.PHONY: test-binaries
test-binaries:
@echo "################################################################################"
@echo "# Testing correct Binaries"
@echo "################################################################################"
@echo "docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) find /usr/bin/ -type f | sed 's|/usr/bin/||g'"
@\
\
\
BINS="$$( docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) find /usr/bin/ -type f | sed 's|/usr/bin/||g' )"; \
\
\
REQUIRED_BASE="python"; \
REQUIRED_TOOLS="git gpg jq yq ssh"; \
REQUIRED_INFRA="rsync"; \
REQUIRED_AZURE="az"; \
REQUIRED_AWS="aws aws-iam-authenticator"; \
REQUIRED_AWSK8S="kubectl oc"; \
REQUIRED_AWSKOPS="kops"; \
REQUIRED_AWSHELM="helm"; \
\
\
if [ "$(STAGE)" = "base" ]; then \
for bin in $$( echo $${REQUIRED_BASE} ); do \
if echo "$${BINS}" | grep -E "^$${bin}" >/dev/null; then \
echo "[OK] required bin available: $${bin}"; \
else \
echo "[FAILED] required bin not available: $${bin}"; \
exit 1; \
fi; \
done; \
for bin in $${REQUIRED_TOOLS}; do \
if ! echo "$${BINS}" | grep -E "^$${bin}" >/dev/null; then \
echo "[OK] unwanted bin not available: $${bin}"; \
else \
echo "[FAILED] unwanted bin available: $${bin}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(STAGE)" = "tools" ]; then \
for bin in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} ); do \
if echo "$${BINS}" | grep -E "^$${bin}" >/dev/null; then \
echo "[OK] required bin available: $${bin}"; \
else \
echo "[FAILED] required bin not available: $${bin}"; \
exit 1; \
fi; \
done; \
for bin in $${REQUIRED_INFRA}; do \
if ! echo "$${BINS}" | grep -E "^$${bin}" >/dev/null; then \
echo "[OK] unwanted bin not available: $${bin}"; \
else \
echo "[FAILED] unwanted bin available: $${bin}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(STAGE)" = "infra" ]; then \
for bin in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} $${REQUIRED_INFRA} ); do \
if echo "$${BINS}" | grep -E "^$${bin}" >/dev/null; then \
echo "[OK] required bin available: $${bin}"; \
else \
echo "[FAILED] required bin not available: $${bin}"; \
exit 1; \
fi; \
done; \
for bin in $${REQUIRED_AZURE}; do \
if ! echo "$${BINS}" | grep -E "^$${bin}" >/dev/null; then \
echo "[OK] unwanted bin not available: $${bin}"; \
else \
echo "[FAILED] unwanted bin available: $${bin}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(STAGE)" = "azure" ]; then \
for bin in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} $${REQUIRED_AZURE} ); do \
if echo "$${BINS}" | grep -E "^$${bin}" >/dev/null; then \
echo "[OK] required bin available: $${bin}"; \
else \
echo "[FAILED] required bin not available: $${bin}"; \
exit 1; \
fi; \
done; \
for bin in $${REQUIRED_AWS}; do \
if ! echo "$${BINS}" | grep -E "^$${bin}" >/dev/null; then \
echo "[OK] unwanted bin not available: $${bin}"; \
else \
echo "[FAILED] unwanted bin available: $${bin}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(STAGE)" = "aws" ]; then \
for bin in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} $${REQUIRED_AWS} ); do \
if echo "$${BINS}" | grep -E "^$${bin}" >/dev/null; then \
echo "[OK] required bin available: $${bin}"; \
else \
echo "[FAILED] required bin not available: $${bin}"; \
exit 1; \
fi; \
done; \
for bin in $${REQUIRED_AWSK8S}; do \
if ! echo "$${BINS}" | grep -E "^$${bin}" >/dev/null; then \
echo "[OK] unwanted bin not available: $${bin}"; \
else \
echo "[FAILED] unwanted bin available: $${bin}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(STAGE)" = "awsk8s" ]; then \
for bin in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} $${REQUIRED_AWS} $${REQUIRED_AWSK8S} ); do \
if echo "$${BINS}" | grep -E "^$${bin}" >/dev/null; then \
echo "[OK] required bin available: $${bin}"; \
else \
echo "[FAILED] required bin not available: $${bin}"; \
exit 1; \
fi; \
done; \
for bin in $$( echo $${REQUIRED_AWSKOPS} $${REQUIRED_AWSHELM} ); do \
if ! echo "$${BINS}" | grep -E "^$${bin}" >/dev/null; then \
echo "[OK] unwanted bin not available: $${bin}"; \
else \
echo "[FAILED] unwanted bin available: $${bin}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(STAGE)" = "awskops" ]; then \
for bin in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} $${REQUIRED_AWS} $${REQUIRED_AWSK8S} $${REQUIRED_AWSKOPS} ); do \
if echo "$${BINS}" | grep -E "^$${bin}" >/dev/null; then \
echo "[OK] required bin available: $${bin}"; \
else \
echo "[FAILED] required bin not available: $${bin}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(STAGE)" = "awshelm" ]; then \
for bin in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} $${REQUIRED_AWS} $${REQUIRED_AWSK8S} $${REQUIRED_AWSHELM} ); do \
if echo "$${BINS}" | grep -E "^$${bin}" >/dev/null; then \
echo "[OK] required bin available: $${bin}"; \
else \
echo "[FAILED] required bin not available: $${bin}"; \
exit 1; \
fi; \
done; \
\
fi; \
echo "[SUCCESS]"; \
echo
.PHONY: test-helm-version
test-helm-version:
@echo "################################################################################"
@echo "# Testing correct Helm version"
@echo "################################################################################"
@\
if [ "$(STAGE)" = "awshelm" ]; then \
if echo '$(HELM)' | grep -Eq 'latest\-?'; then \
echo "Fetching latest version from GitHub"; \
LATEST="$$( \
curl -L -sS https://github.com/helm/helm/releases \
| tac | tac \
| grep -Eo "helm/helm/releases/tag/v[.0-9]+\"" \
| head -1 \
| sed 's/.*v//g' \
| sed 's/\"//g' \
)"; \
echo "Testing for latest: $${LATEST}"; \
echo "docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) helm version --client --short | grep -E \"^(Client: )?v$${LATEST}\""; \
if ! docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) helm version --client --short | grep -E "^(Client: )?v$${LATEST}"; then \
echo "[FAILED]"; \
docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) helm version --client --short; \
exit 1; \
fi; \
else \
VERSION="$$( echo '$(HELM)' | grep -Eo '^[.0-9]+?' )"; \
echo "Testing for version: $${VERSION}"; \
echo "docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) helm version --client --short | grep -E \"^(Client: )?v$${VERSION}\.\""; \
if ! docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) helm version --client --short | grep -E "^(Client: )?v$${VERSION}\."; then \
echo "[FAILED]"; \
docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) helm version --client --short; \
exit 1; \
fi; \
fi; \
echo "[SUCCESS]"; \
else \
echo "[SKIPPING] Not a Helm image"; \
fi; \
echo
.PHONY: test-kops-version
test-kops-version:
@echo "################################################################################"
@echo "# Testing correct Kops version"
@echo "################################################################################"
@\
if [ "$(STAGE)" = "awskops" ]; then \
if echo '$(KOPS)' | grep -Eq 'latest\-?'; then \
echo "Fetching latest version from GitHub"; \
LATEST="$$( \
curl -L -sS https://github.com/kubernetes/kops/releases \
| tac | tac \
| grep -Eo "kubernetes/kops/releases/tag/v[.0-9]+\"" \
| head -1 \
| sed 's/.*v//g' \
| sed 's/\"//g' \
)"; \
echo "Testing for latest: $${LATEST}"; \
echo "docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) kops version | grep -E \"^([Cc]lient\s)?[Vv]ersion(:)?\s+v?$${LATEST}\""; \
if ! docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) kops version | grep -E "^([Cc]lient\s)?[Vv]ersion(:)?\s+v?$${LATEST}"; then \
echo "[FAILED]"; \
docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) kops version; \
exit 1; \
fi; \
else \
VERSION="$$( echo '$(KOPS)' | grep -Eo '^[.0-9]+?' )"; \
echo "Testing for version: $${VERSION}"; \
echo "docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) kops version | grep -E \"^([Cc]lient\s)?[Vv]ersion(:)?\s+v?$${VERSION}\.\""; \
if ! docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) kops version | grep -E "^([Cc]lient\s)?[Vv]ersion(:)?\s+v?$${VERSION}\."; then \
echo "[FAILED]"; \
docker run --rm --platform $(ARCH) $(IMAGE):$(DOCKER_TAG) kops version; \
exit 1; \
fi; \
fi; \
echo "[SUCCESS]"; \
else \
echo "[SKIPPING] Not a Kops image"; \
fi; \
echo
.PHONY: test-run-user-root
test-run-user-root:
@echo "################################################################################"
@echo "# Testing playbook (user: root)"
@echo "################################################################################"
@echo "docker run --rm --platform $(ARCH) $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR)/tests:/data $(IMAGE):$(DOCKER_TAG) ansible-playbook -i inventory playbook.yml"
@\
if ! docker run --rm --platform $(ARCH) $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR)/tests:/data $(IMAGE):$(DOCKER_TAG) ansible-playbook -i inventory playbook.yml; then \
echo "[FAILED]"; \
exit 1; \
fi; \
echo "[SUCCESS]"; \
echo
.PHONY: test-run-user-ansible
test-run-user-ansible:
@echo "################################################################################"
@echo "# Testing playbook (user: ansible)"
@echo "################################################################################"
@\
if [ "$(STAGE)" = "base" ]; then \
echo "[SKIPPING] Does not have user setup"; \
else \
echo "docker run --rm --platform $(ARCH) $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR)/tests:/data -e USER=ansible -e MY_UID=$$(id -u) -e MY_GID=$$(id -g) $(IMAGE):$(DOCKER_TAG) ansible-playbook -i inventory playbook.yml"; \
if ! docker run --rm --platform $(ARCH) $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR)/tests:/data -e USER=ansible -e MY_UID=$$(id -u) -e MY_GID=$$(id -g) $(IMAGE):$(DOCKER_TAG) ansible-playbook -i inventory playbook.yml ; then \
echo "[FAILED]"; \
exit 1; \
fi; \
fi; \
echo "[SUCCESS]"; \
echo