forked from kbst/terraform-kubestack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
106 lines (90 loc) · 2.75 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
_all: dist build
GIT_REF ?= $(shell echo "refs/heads/"`git rev-parse --abbrev-ref HEAD`)
GIT_SHA ?= $(shell echo `git rev-parse --verify HEAD^{commit}`)
DOCKER_PUSH ?= false
DOCKER_TARGET ?= multi-cloud
ifeq ("${DOCKER_PUSH}", "true")
BUILD_CACHE_DIST := --cache-to type=registry,mode=max,ref=kubestack/framework-dev:buildcache-dist-helper,push=${DOCKER_PUSH}
BUILD_OUTPUT := --output type=registry,push=${DOCKER_PUSH}
BUILD_CACHE := --cache-to type=registry,mode=max,ref=kubestack/framework-dev:buildcache-${DOCKER_TARGET},push=${DOCKER_PUSH}
else
BUILD_OUTPUT := --output type=docker
endif
dist:
rm -rf quickstart/_dist
docker buildx build \
--build-arg GIT_REF=${GIT_REF} \
--build-arg GIT_SHA=${GIT_SHA} \
--file oci/Dockerfile \
--output type=docker \
--cache-from type=registry,ref=kubestack/framework-dev:buildcache-dist-helper \
${BUILD_CACHE_DIST} \
--progress plain \
-t dist-helper:latest \
--target dist-helper \
.
docker run \
--detach \
--name dist-helper \
--rm dist-helper:latest \
sleep 600
docker cp dist-helper:/quickstart/_dist quickstart/_dist
docker stop dist-helper
build:
docker buildx build \
--build-arg GIT_REF=${GIT_REF} \
--build-arg GIT_SHA=${GIT_SHA} \
--file oci/Dockerfile \
${BUILD_OUTPUT} \
--cache-from type=registry,ref=kubestack/framework-dev:buildcache-${DOCKER_TARGET} \
${BUILD_CACHE} \
--progress plain \
--target ${DOCKER_TARGET} \
-t kubestack/framework-dev:test-$(GIT_SHA)-${DOCKER_TARGET} \
.
validate: .init
docker exec \
test-container-$(GIT_SHA) \
entrypoint terraform validate
test: validate
docker exec \
test-container-$(GIT_SHA) \
entrypoint terraform apply --target module.aks_zero --target module.eks_zero --target module.gke_zero --input=false --auto-approve
docker exec \
test-container-$(GIT_SHA) \
entrypoint terraform apply --input=false --auto-approve
cleanup: .init
docker exec \
-ti \
test-container-$(GIT_SHA) \
entrypoint terraform destroy --input=false --auto-approve
$(MAKE) .stop-container
shell: .check-container
docker exec \
-ti \
test-container-$(GIT_SHA) \
entrypoint bash
.check-container:
docker inspect test-container-${GIT_SHA} > /dev/null || $(MAKE) .run-container
.run-container: build
docker run \
--detach \
--name test-container-${GIT_SHA} \
--rm \
-v `pwd`:/infra:z \
-e KBST_AUTH_AWS \
-e KBST_AUTH_AZ \
-e KBST_AUTH_GCLOUD \
-e HOME=/infra/tests/.user \
--workdir /infra/tests \
kubestack/framework-dev:test-$(GIT_SHA)-${DOCKER_TARGET} \
sleep infinity
.stop-container:
docker stop test-container-${GIT_SHA} || true
.init: .check-container
docker exec \
test-container-$(GIT_SHA) \
entrypoint terraform init
docker exec \
test-container-$(GIT_SHA) \
entrypoint terraform workspace select ops