-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
235 lines (186 loc) · 7.07 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
SHELL := /bin/bash
WEB_APP_NAME = eklhad-web
WEB_APP_TAR_NAME = eklhad-web.tar.gz
CWD := $(shell pwd)
PACKER_GCP_DEF_PATH=packer/gcp/image.pkr.hcl
PACKER_AWS_DEF_PATH=packer/aws/image.pkr.hcl
# TODO: fix the AWS one as well
PACKER_AWS_IMAGE_CMD=`tail -n 1 /Users/neildahlke/src/github.com/dahlke/eklhad/packer/aws/output/image.txt | awk '{print $$6}' | cut -c 1-21`
PACKER_GCP_IMAGE_CMD=`tail -n 1 /Users/neildahlke/src/github.com/dahlke/eklhad/packer/gcp/output/image.txt | awk '{print $$12}'`
PACKER_GCP_OUTPUT_DIR=packer/gcp/output/
PACKER_AWS_OUTPUT_DIR=packer/aws/output/
ARTIFACT_DIR_LINUX=${CWD}/artifact/tar/linux
ARTIFACT_DIR_MACOS=${CWD}/artifact/tar/macos
TF_GCP_APP_DIR=${CWD}/terraform/gcp
TF_AWS_APP_DIR=${CWD}/terraform/aws
WEB_APP_SRC_DIR=web/
WEB_APP_FRONTEND_BUILD_DIR=web/frontend/build/
WEB_APP_GO_BINARY_PATH=web/main
WEB_APP_CONFIG_PATH=web/config.json
DOCKER_HUB_USER=eklhad
DOCKER_WEB_IMAGE_NAME=eklhad-web
DOCKER_WEB_IMAGE_VERSION=0.1.1
DOCKER_TEST_IMAGE_NAME=eklhad-web-circleci
DOCKER_TEST_IMAGE_VERSION=0.1.2
##########################
# JS HELPERS
##########################
.PHONY: npm
npm:
cd web/frontend && npm config set strict-ssl false && npm install
.PHONY: js_lint
js_lint:
cd web/frontend/ && \
node node_modules/eslint/bin/eslint.js src/*.js* src/**/*.js*
.PHONY: js_lint_fix
js_lint_fix:
cd web/frontend/ && \
node node_modules/eslint/bin/eslint.js --fix src/**/*.js*
# node node_modules/eslint/bin/eslint.js --fix src/*.js* src/**/*.js*
.PHONY: js_lint_fix_dry
js_lint_fix_dry:
cd web/frontend/ && \
node node_modules/eslint/bin/eslint.js --fix-dry-run src/*.js src/**/*.js
.PHONY: resume
resume: npm
cd web/frontend/conf/ && \
npx resume export resume.html --format html --theme classic && \
mv ${CWD}/web/frontend/conf/resume.html ${CWD}/web/frontend/public/static/resume.html;
.PHONY: frontend_test
frontend_test: npm resume
cd web/frontend/ && npm run test
.PHONY: frontend_test_coverage
frontend_test_coverage: npm resume
cd web/frontend/ && npm run test:coverage
.PHONY: frontend_test_watch
frontend_test_watch: npm resume
cd web/frontend/ && npm run test:watch
.PHONY: frontend_run
frontend_run: npm resume
cd web/frontend/ && npm run dev
.PHONY: frontend_build
frontend_build: npm resume
PUBLIC_URL=/static cd web/frontend/ && npm run build
##########################
# GO HELPERS
##########################
.PHONY: go_lint
go_lint:
golint web/...
.PHONY: go_get
go_get:
cd web && go get -u && go mod tidy
.PHONY: go_test
go_test:
cd web && go test -v ./... -coverprofile=coverage.out
.PHONY: go_server_run
go_server_run:
cd web && go run main.go
.PHONY: go_build_linux
go_build_linux:
cd web && GOOS=linux GOARCH=amd64 go build main.go
.PHONY: go_build_macos
go_build_macos:
cd web && GOOS=darwin GOARCH=amd64 go build main.go
##########################
# DATA COLLECTION HELPERS
##########################
.PHONY: collect_data
collect_data:
cd web && go run main.go -gsheets;
##########################
# IMAGE BUILD HELPERS
##########################
.PHONY: artifact_linux_web
artifact_linux_web: go_build_linux
mkdir -p ${ARTIFACT_DIR_LINUX};
tar zcf ${ARTIFACT_DIR_LINUX}/${WEB_APP_TAR_NAME} ${WEB_APP_FRONTEND_BUILD_DIR} ${WEB_APP_GO_BINARY_PATH} ${WEB_APP_CONFIG_PATH};
.PHONY: artifact_macos_web
artifact_macos_web: go_build_macos
mkdir -p ${ARTIFACT_DIR_MACOS};
tar zcf ${ARTIFACT_DIR_MACOS}/${WEB_APP_TAR_NAME} ${WEB_APP_FRONTEND_BUILD_DIR} ${WEB_APP_GO_BINARY_PATH} ${WEB_APP_CONFIG_PATH};
.PHONY: image_gcp
image_gcp:
mkdir -p ${PACKER_GCP_OUTPUT_DIR};
packer -machine-readable build ${PACKER_GCP_DEF_PATH} >> ${PACKER_GCP_OUTPUT_DIR}image.txt;
.PHONY: image_aws
image_aws:
mkdir -p ${PACKER_AWS_OUTPUT_DIR};
packer -machine-readable build ${PACKER_AWS_DEF_PATH} >> ${PACKER_AWS_OUTPUT_DIR}image.txt;
###############################
# GCP / TERRAFORM DEV HELPERS
###############################
.PHONY: tf_init_gcp
tf_init_gcp:
cd ${TF_GCP_APP_DIR} && terraform init
.PHONY: tf_plan_gcp
tf_plan_gcp: tf_init_gcp
cd ${TF_GCP_APP_DIR} && terraform plan -var "gcp_image_id=$(PACKER_GCP_IMAGE_CMD)"
.PHONY: tf_apply_gcp
tf_apply_gcp: tf_init_gcp
cd ${TF_GCP_APP_DIR} && terraform apply -var "gcp_image_id=${PACKER_GCP_IMAGE_CMD}"
.PHONY: tf_apply_gcp_auto
tf_apply_gcp_auto: tf_init_gcp
cd ${TF_GCP_APP_DIR} && terraform apply -var "gcp_image_id=${PACKER_GCP_IMAGE_CMD}" -auto-approve
.PHONY: tf_apply_gcp_rotate_certs_auto
tf_apply_gcp_rotate_certs_auto: tf_init_gcp
cd ${TF_GCP_APP_DIR} && terraform apply -var "gcp_image_id=${PACKER_GCP_IMAGE_CMD}" -replace "acme_certificate.certificate" -auto-approve
.PHONY: tf_out_gcp
tf_out_gcp:
cd ${TF_GCP_APP_DIR} && terraform output
.PHONY: tf_destroy_gcp
tf_destroy_gcp:
cd ${TF_GCP_APP_DIR} && terraform destroy -var "gcp_image_id=${PACKER_GCP_IMAGE_CMD}"
.PHONY: tf_destroy_gcp_auto
tf_destroy_gcp_auto:
cd ${TF_GCP_APP_DIR} && terraform destroy -var "gcp_image_id=${PACKER_GCP_IMAGE_CMD}" -auto-approve
###############################
# AWS / TERRAFORM DEV HELPERS
###############################
.PHONY: tf_aws_init
tf_aws_init:
cd ${TF_AWS_APP_DIR} && terraform init
.PHONY: tf_plan_aws
tf_plan_aws: tf_aws_init
cd ${TF_AWS_APP_DIR} && terraform plan -var "aws_image_id=$(PACKER_AWS_IMAGE_CMD)"
.PHONY: tf_apply_aws
tf_apply_aws: tf_aws_init
cd ${TF_AWS_APP_DIR} && terraform apply -var "aws_image_id=${PACKER_AWS_IMAGE_CMD}"
.PHONY: tf_apply_aws_auto
tf_apply_aws_auto: tf_aws_init
cd ${TF_AWS_APP_DIR} && terraform apply -var "aws_image_id=${PACKER_AWS_IMAGE_CMD}" -auto-approve
# TODO: remove this or add it to GCP?
.PHONY: tf_apply_aws_rotate_certs_auto
tf_apply_aws_rotate_certs_auto: tf_init_aws
cd ${TF_AWS_APP_DIR} && terraform apply -var "aws_image_id=${PACKER_AWS_IMAGE_CMD}" -replace "acme_certificate.certificate" -auto-approve
.PHONY: tf_out_aws
tf_out_aws:
cd ${TF_AWS_APP_DIR} && terraform output
.PHONY: tf_destroy_aws
tf_destroy_aws:
cd ${TF_AWS_APP_DIR} && terraform destroy -var "aws_image_id=${PACKER_AWS_IMAGE_CMD}"
.PHONY: tf_destroy_aws_auto
tf_destroy_aws_auto:
cd ${TF_AWS_APP_DIR} && terraform destroy -var "aws_image_id=${PACKER_AWS_IMAGE_CMD}" -auto-approve
##########################
# DOCKER HELPERS
##########################
docker_build_web:
docker build --platform linux/amd64 -t ${DOCKER_HUB_USER}/$(DOCKER_WEB_IMAGE_NAME):$(DOCKER_WEB_IMAGE_VERSION) . && \
docker tag ${DOCKER_HUB_USER}/$(DOCKER_WEB_IMAGE_NAME):$(DOCKER_WEB_IMAGE_VERSION) ${DOCKER_HUB_USER}/$(DOCKER_WEB_IMAGE_NAME):$(DOCKER_WEB_IMAGE_VERSION) && \
docker tag ${DOCKER_HUB_USER}/$(DOCKER_WEB_IMAGE_NAME):$(DOCKER_WEB_IMAGE_VERSION) ${DOCKER_HUB_USER}/$(DOCKER_WEB_IMAGE_NAME):latest
docker_push_web:
docker push ${DOCKER_HUB_USER}/$(DOCKER_WEB_IMAGE_NAME):$(DOCKER_WEB_IMAGE_VERSION)
docker push ${DOCKER_HUB_USER}/$(DOCKER_WEB_IMAGE_NAME):latest
docker_run_web:
docker run \
-it \
-p 3554:3554 \
${DOCKER_HUB_USER}/$(DOCKER_WEB_IMAGE_NAME):$(DOCKER_WEB_IMAGE_VERSION)
docker_run_web_dev:
docker run \
-v ${CWD}/web:/web \
-it \
-p 3554:3554 \
${DOCKER_HUB_USER}/$(DOCKER_WEB_IMAGE_NAME):$(DOCKER_WEB_IMAGE_VERSION)
# ${DOCKER_HUB_USER}/$(DOCKER_WEB_IMAGE_NAME):$(DOCKER_WEB_IMAGE_VERSION) -port 3000