-
Notifications
You must be signed in to change notification settings - Fork 0
/
Justfile
180 lines (145 loc) · 5.54 KB
/
Justfile
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
NAME := "qicoo-api-kt"
DOTENV_EXISTS := `if [ -f ./.env ]; then echo 0; else echo 1; fi`
MYSQL_DOCKER := "qicoo-test-mysql"
MYSQL_DOCKER_EXISTS_FLAG := `if [ ! -z ${CIRCLECI:-} ]; then echo 1; exit 0; fi; docker ps --format "{{ .Names }}" --filter "name=qicoo-test-mysql" | wc -l`
MYSQL_VERSION := "8.0.11"
REDIS_DOCKER := "qicoo-test-redis"
REDIS_DOCKER_EXISTS_FLAG := `if [ ! -z ${CIRCLECI:-} ]; then echo 1; exit 0; fi; docker ps --format "{{ .Names }}" --filter "name=qicoo-test-redis" | wc -l`
REDIS_VERSION := "5.0.0"
DOCKER_REGISTORY := "docker.io"
DOCKER_NAME := "qicoo-api-kt"
DOCKER_IMAGE_NAME := "cndjp/qicoo-api-kt"
WARM_IMAGE_NAME := "cndjp/warm-curl"
DOCKER_TAG := `git rev-parse HEAD`
version:
./gradlew --version
test: load_dotenv
./gradlew test --stacktrace --info
lint:
ktlint "src/main/**/*.kt" '!src/test/**/*.kt'
lint-fmt:
ktlint -F "src/main/**/*.kt" '!src/test/**/*.kt'
clean:
rm $HOME/.gradle/caches/
build: load_dotenv
./gradlew --gradle-user-home=.gradle shadowJar
run: build
java -jar build/libs/qicoo-all.jar
docker-image:
`docker images -a --filter='dangling=false' --format '{{ "{{" }}.Repository{{ "}}" }}:{{ "{{" }}.Tag{{ "}}" }}'| grep "{{ DOCKER_IMAGE_NAME }}"`
docker-build: load_dotenv
docker build -t {{ DOCKER_IMAGE_NAME }}:base -f base.Dockerfile .
./gradlew jibDockerBuild
warm-docker-build: load_dotenv
docker build -t {{ WARM_IMAGE_NAME }}:{{ DOCKER_TAG }} -f warm.Dockerfile .
warm-docker-release: warm-docker-build
docker tag {{ WARM_IMAGE_NAME }}:{{ DOCKER_TAG }} {{ DOCKER_REGISTORY }}/{{ WARM_IMAGE_NAME }}:{{ DOCKER_TAG }}
docker push {{ DOCKER_REGISTORY }}/{{ WARM_IMAGE_NAME }}:{{ DOCKER_TAG }}
docker-run: load_dotenv
#!/bin/bash
docker run --name {{ DOCKER_NAME }} -it --rm -p 8080:8080 {{ DOCKER_IMAGE_NAME }}:{{ DOCKER_TAG }} .
docker-login: load_dotenv
echo ${DOCKERHUB_PASSWORD} | docker login -u cndjpintegrate --password-stdin
docker-release: docker-build
docker tag {{ DOCKER_IMAGE_NAME }}:{{ DOCKER_TAG }} {{ DOCKER_REGISTORY }}/{{ DOCKER_IMAGE_NAME }}:{{ DOCKER_TAG }}
docker push {{ DOCKER_REGISTORY }}/{{ DOCKER_IMAGE_NAME }}:{{ DOCKER_TAG }}
create_dotenv:
#!/bin/bash
if [ ! {{ DOTENV_EXISTS }} = 0 ]; then
echo 'MYSQL_USER="root"' >> ./.env
echo 'MYSQL_PASSWORD=""' >> ./.env
echo 'MYSQL_PORT="3306"' >> ./.env
echo 'MYSQL_DB="qicoo2db"' >> ./.env
echo 'MYSQL_OPTS="prefer_socket=false&timeout=30s&parseTime=true&loc=Asia%2FTokyo"' >> ./.env
echo 'DOCKERHUB_PASSWORD=' >> ./.env
echo 'REDIS_HOST="localhost"' >> ./.env
echo 'REDIS_PORT="6379"' >> ./.env
fi
load_dotenv: create_dotenv
#!/bin/bash
if [ ! -z ${TRAVIS:-} ]; then
echo 'Do not load dotenv'
exit 0
fi
if [ {{ DOTENV_EXISTS }} = 0 ]; then
export $(sed 's/=.*//' ./.env)
else
echo '.env is not found'
fi
mysql-db-is-exist:
#!/bin/bash
echo MYSQL_DOCKER_EXISTS_FLAG is {{ MYSQL_DOCKER_EXISTS_FLAG }}
if [ ! {{ MYSQL_DOCKER_EXISTS_FLAG }} = 0 ]; then
echo "{{ MYSQL_DOCKER }} is exists"
else
echo "{{ MYSQL_DOCKER }} is not exists"
fi
check-mysql-db: load_dotenv
#!/bin/bash
STATUS=1
COUNT=0
while [ ${STATUS} = 1 ]
do
mysqladmin ping -u root -h ${MYSQL_HOST} -p${MYSQL_PORT} > /dev/null 2>&1 && STATUS=0
if [ ${STATUS} = 1 ]; then
echo -n '.'
fi
sleep 1
(( COUNT++ ))
if [ ${COUNT} = 50 ]; then
echo "Sorry, Cannot connect the mysql docker."
exit 1
fi
done
echo '!'
echo {{ MYSQL_DOCKER }} is alive
lunch-mysql-db: load_dotenv
#!/bin/bash
if [ ! {{ MYSQL_DOCKER_EXISTS_FLAG }} = 0 ]; then
echo "{{ MYSQL_DOCKER }} is exists. Not work."
else
echo 'set up the mysql docker'
docker run --name {{ MYSQL_DOCKER }} \
--rm \
-d \
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes \
-p ${MYSQL_PORT}:${MYSQL_PORT} mysql:{{ MYSQL_VERSION }} \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_unicode_ci
fi
setup-mysql-db: load_dotenv
echo "CREATE DATABASE IF NOT EXISTS ${MYSQL_DB} DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" | mysql -h${MYSQL_HOST} -u${MYSQL_USER} 2>/dev/null
echo 'set global time_zone = "Asia/Tokyo"' | mysql -h${MYSQL_HOST} -u${MYSQL_USER} 2>/dev/null
data-migrate-db: load_dotenv
./gradlew runMigrate
data-clean-db: load_dotenv
./gradlew runClean
run-mysql-db: lunch-mysql-db check-mysql-db setup-mysql-db
run-redis-db: load_dotenv
#!/bin/bash
if [ ! {{ REDIS_DOCKER_EXISTS_FLAG }} = 0 ]; then
echo "{{ REDIS_DOCKER }} is exists. Not work."
else
echo 'set up the redis docker'
docker run --name {{ REDIS_DOCKER }} \
--rm \
-d \
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes \
-p ${REDIS_PORT}:${REDIS_PORT} redis:{{ REDIS_VERSION }}
fi
run-db: run-redis-db run-mysql-db data-migrate-db
clean-mysql-db:
#!/bin/bash
if [ {{ MYSQL_DOCKER_EXISTS_FLAG }} = 0 ]; then
echo "{{ MYSQL_DOCKER }} is not exists. Not work."
else
docker kill {{ MYSQL_DOCKER }} > /dev/null && echo 'clean up the mysql docker'
fi
clean-redis-db:
#!/bin/bash
if [ {{ REDIS_DOCKER_EXISTS_FLAG }} = 0 ]; then
echo "{{ REDIS_DOCKER }} is not exists. Not work."
else
docker kill {{ REDIS_DOCKER }} > /dev/null && echo 'clean up the redis docker'
fi
clean-db: clean-mysql-db clean-redis-db