generated from VG-Tech-Dojo/hakaru
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
90 lines (70 loc) · 2.27 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
export AWS_PROFILE ?= sunrise201911-team-d
export AWS_DEFAULT_REGION := ap-northeast-1
.PHONY: all install imports fmt test run build clean upload
GOOS ?=
GOARCH ?=
GOSRC := $(GOPATH)/src
COUNT := 1
all: install run
install:
imports:
goimports -w .
fmt:
gofmt -w .
test:
go test -v -tags=unit $$(go list ./... | grep -v '/vendor/')
test/curl:
curl -v localhost:8081/hakaru?name=denden&value=10
run: main.go
go run main.go
build: test
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o hakaru
clean:
rm -rf hakaru *.tgz
# lcoal mysqld on docker
mysql_run:
docker run --rm -d \
--name sunrise2019-hakaru-db \
-e MYSQL_ROOT_PASSWORD=password \
-e MYSQL_DATABASE=hakaru \
-e TZ=Asia/Tokyo \
-p 13306:3306 \
-v $(CURDIR)/db/data:/var/lib/mysql \
-v $(CURDIR)/db/my.cnf:/etc/mysql/conf.d/my.cnf:ro \
-v $(CURDIR)/db/init:/docker-entrypoint-initdb.d:ro \
mysql:5.6 \
mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
mysql_connect:
mysql -P 13306 -u root -h 127.0.0.1 -p
# deployment
artifacts.tgz: provisioning/instance
$(MAKE) build GOOS=linux GOARCH=amd64
tar czf artifacts.tgz hakaru db provisioning/instance
ARTIFACTS_BUCKET := $(AWS_PROFILE)-hakaru-artifacts
# ci からアップロードできなくなった場合のターゲット
upload: clean artifacts.tgz
aws s3 cp artifacts.tgz s3://$(ARTIFACTS_BUCKET)/latest/artifacts.tgz
aws s3 cp artifacts.tgz s3://$(ARTIFACTS_BUCKET)/$$(git rev-parse HEAD)/artifacts.tgz
new_instance:
aws ec2 run-instances \
--count $(COUNT) \
--key-name sunrise2019 \
--user-data file://user_data.sh \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=hakaru-from-cli}]' \
--image-id ami-0dc6cd9c334f3da26 \
--security-group-ids sg-0e7591374f4460444 \
--instance-type c5.large \
--subnet-id subnet-06487332afd2f4a55 \
--iam-instance-profile Name="hakaru"
tes:
cd _files \
aws ec2 describe-instances \
--profile sunrise201911-team-d \
--region ap-northeast-1 \
--filters Name=instance-state-name,Values=running |\
jq '.Reservations[].Instances[] |\
select( .Tags[].Key == "Name" and (.Tags[].Value | test("^hakaru"))) |\
.InstanceId' |\
uniq |\
sed '/s\"/d' |\
AWS_PROFILE=sunrise201911-team-d xargs -IIP_ADDR ssh -i id_rsa ec2-user@IP_ADDR "ulimit -n 4096"