-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
177 lines (142 loc) · 7.06 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
## filemanager server version
SERVER_VERSION = latest
## File name for executing
FILE_NAME=file_manager
## Folder content generated files
BUILD_FOLDER = ./build
## command
GO = go
MKDIR_P = mkdir -p
TIMESTAMP = $(shell date +%s)
################################################
.PHONY: all
all: build build-linux test
.PHONY: build
build:
$(MAKE) src.build
.PHONY: build-darwin
build-darwin:
go build -o $(FILE_NAME) src/cmd/filemanger/main.go
.PHONY: build-linux
build-linux:
export GOOS=linux && export GOARCH=amd64 && go build -o $(FILE_NAME) src/cmd/filemanager/main.go
.PHONY: test
test: build-linux
$(MAKE) src.test
.PHONY: run
run:
go run src/cmd/filemanager/main.go
.PHONY: zip
zip:
zip -r config.zip ./config/
## src/ ########################################
.PHONY: src.build
src.build:
$(GO) build -v ./src/...
$(MKDIR_P) $(BUILD_FOLDER)/src/cmd/filemanager/
$(GO) build -v -o $(BUILD_FOLDER)/src/cmd/filemanager/$(FILE_NAME) ./src/cmd/filemanager/...
.PHONY: src.test
src.test:
$(GO) test -v ./src/...
.PHONY: src.test-coverage
src.test-coverage:
$(MKDIR_P) $(BUILD_FOLDER)/src/
$(GO) test -v -coverprofile=$(BUILD_FOLDER)/src/coverage.txt -covermode=atomic ./src/...
$(GO) tool cover -html=$(BUILD_FOLDER)/src/coverage.txt -o $(BUILD_FOLDER)/src/coverage.html
## launch apps #############################
define generate_gcr-registry-key
kubectl create secret docker-registry gcr-registry-key \
--docker-server=https://gcr.io \
--docker-username=_json_key \
--docker-password='$(shell cat < secret/gcr/$(1).json)' \
--dry-run -n filemanager -o yaml > deploy/helm/services/charts/secret/templates/gcr.yaml
endef
define generate_filemanager-config
kubectl create secret generic filemanager-config --from-file=config/$(1).json -n filemanager \
--dry-run -o yaml > deploy/helm/services/charts/secret/templates/gcs.yaml
endef
.PHONY: apps.init-helm
apps.init-helm:
helm init
kubectl create serviceaccount --namespace kube-system tiller
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
.PHONY: apps.install-local
apps.install-local:
$(call generate_filemanager-config,local)
yq -y .services deploy/helm/config/local.yaml | helm upgrade --install filemanager-services-local --debug -f - deploy/helm/services
yq -y .apps deploy/helm/config/local.yaml | helm upgrade --install filemanager-apps-local --debug -f - --set filemanager-server.controller.apiserverImageTag=$(SERVER_VERSION),filemanager-server.controller.timestamp=$(TIMESTAMP) deploy/helm/apps
.PHONY: apps.install-dev
apps.install-dev:
$(call generate_gcr-registry-key,develop)
$(call generate_filemanager-config,develop)
yq -y .services deploy/helm/config/development.yaml | helm upgrade --install filemanager-services-dev --debug -f - deploy/helm/services
yq -y .apps deploy/helm/config/development.yaml | helm upgrade --install filemanager-apps-dev --debug -f - --set filemanager-server.controller.apiserverImageTag=dev-$(SERVER_VERSION),filemanager-server.controller.timestamp=$(TIMESTAMP) deploy/helm/apps
.PHONY: apps.install-stage
apps.install-stage:
$(call generate_gcr-registry-key,staging)
$(call generate_filemanager-config,staging)
yq -y .services deploy/helm/config/staging.yaml | helm upgrade --install filemanager-services-stage --debug -f - deploy/helm/services
yq -y .apps deploy/helm/config/staging.yaml | helm upgrade --install filemanager-apps-stage --debug -f - --set filemanager-server.controller.apiserverImageTag=stage-$(SERVER_VERSION),filemanager-server.controller.timestamp=$(TIMESTAMP) deploy/helm/apps
.PHONY: apps.install-rc
apps.install-rc:
$(call generate_gcr-registry-key,rc)
$(call generate_filemanager-config,rc)
yq -y .services deploy/helm/config/rc.yaml | helm upgrade --install filemanager-services-rc --debug -f - deploy/helm/services
yq -y .apps deploy/helm/config/rc.yaml | helm upgrade --install filemanager-apps-rc --debug -f - --set filemanager-server.controller.apiserverImageTag=rc-$(SERVER_VERSION),filemanager-server.controller.timestamp=$(TIMESTAMP) deploy/helm/apps
.PHONY: apps.install-prod
apps.install-prod:
$(call generate_gcr-registry-key,production)
$(call generate_filemanager-config,production)
yq -y .services deploy/helm/config/production.yaml | helm upgrade --install filemanager-services-prod --debug -f - deploy/helm/services
yq -y .apps deploy/helm/config/production.yaml | helm upgrade --install filemanager-apps-prod --debug -f - --set filemanager-server.controller.apiserverImageTag=$(SERVER_VERSION),filemanager-server.controller.timestamp=$(TIMESTAMP) deploy/helm/apps
.PHONY: apps.teardown-local
apps.teardown-local:
helm delete --purge filemanager-services-local
helm delete --purge filemanager-apps-local
.PHONY: apps.teardown-dev
apps.teardown-dev:
helm delete --purge filemanager-services-dev
helm delete --purge filemanager-apps-dev
.PHONY: apps.teardown-stage
apps.teardown-stage:
helm delete --purge filemanager-services-stage
helm delete --purge filemanager-apps-stage
.PHONY: apps.teardown-rc
apps.teardown-rc:
helm delete --purge filemanager-services-rc
helm delete --purge filemanager-apps-rc
.PHONY: apps.teardown-prod
apps.teardown-prod:
helm delete --purge filemanager-services-prod
helm delete --purge filemanager-apps-prod
## dockerfiles/ ########################################
.PHONY: dockerfiles.build-local
dockerfiles.build-local:
docker build --build-arg CONFIG=config/local.json --tag yunchen/file-manager:$(SERVER_VERSION) .
.PHONY: dockerfiles.build-local.minikube
dockerfiles.build-local.minikube:
eval $$(minikube docker-env) && make dockerfiles.build-local
.PHONY: dockerfiles.build-dev
dockerfiles.build-dev:
docker build --cache-from=gcr.io/jello-test-222701/file-manager --build-arg CONFIG=config/develop.json --tag gcr.io/jello-test-222701/file-manager:dev-$(SERVER_VERSION) .
docker push gcr.io/jello-test-222701/file-manager:dev-$(SERVER_VERSION)
.PHONY: dockerfiles.build-stage
dockerfiles.build-stage:
docker build --cache-from=gcr.io/jello-stage-223210/file-manager --build-arg CONFIG=config/staging.json --tag gcr.io/jello-stage-223210/file-manager:stage-$(SERVER_VERSION) .
docker push gcr.io/jello-stage-223210/file-manager:stage-$(SERVER_VERSION)
.PHONY: dockerfiles.build-rc
dockerfiles.build-rc:
docker build --cache-from=gcr.io/jello-stage-223210/file-manager --build-arg CONFIG=config/rc.json --tag gcr.io/jello-stage-223210/file-manager:rc-$(SERVER_VERSION) .
docker push gcr.io/jello-stage-223210/file-manager:rc-$(SERVER_VERSION)
.PHONY: dockerfiles.build-prod
dockerfiles.build-prod:
docker build --cache-from=gcr.io/jello-000001/file-manager --build-arg CONFIG=config/production.json --tag gcr.io/jello-000001/file-manager:$(SERVER_VERSION) .
docker push gcr.io/jello-000001/file-manager:$(SERVER_VERSION)
## git tag version ########################################
.PHONY: push.tag
push.tag:
@echo "Current git tag version:"$(SERVER_VERSION)
git tag $(SERVER_VERSION)
git push --tags