Skip to content

Commit 1255b7f

Browse files
authored
Merge pull request #623 from Lingghh/dev/update_dockerfile
🎨 规范镜像名称,增加健康探测脚本
2 parents a9ec312 + 66f34eb commit 1255b7f

15 files changed

Lines changed: 171 additions & 18 deletions

File tree

docker-compose.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ services:
3636
main-server:
3737
env_file:
3838
- ./server/dockerconfs/.env.local
39-
image: tca-main:latest
39+
image: tencenttca/tca-main:latest
4040
build:
4141
context: ./server/projects/main
4242
dockerfile: ../../dockerconfs/Dockerfile-common-${ORIGIN:-mirror}
@@ -59,7 +59,7 @@ services:
5959
main-worker:
6060
env_file:
6161
- ./server/dockerconfs/.env.local
62-
image: tca-main:latest
62+
image: tencenttca/tca-main:latest
6363
command:
6464
[
6565
"celery",
@@ -73,14 +73,18 @@ services:
7373
volumes:
7474
- ./server/configs/django/local_main.py:/var/www/django/codedog/codedog/settings/local.py
7575
- ./.docker_data/logs/main_worker:/var/www/django/codedog/log
76+
healthcheck:
77+
test: ["CMD-SHELL", "bash bin/healthy_check.sh"]
78+
interval: 60s
79+
restart: always
7680
depends_on:
7781
- mysql
7882
- redis
7983

8084
main-beat:
8185
env_file:
8286
- ./server/dockerconfs/.env.local
83-
image: tca-main:latest
87+
image: tencenttca/tca-main:latest
8488
command:
8589
[
8690
"celery",
@@ -98,11 +102,12 @@ services:
98102
depends_on:
99103
- mysql
100104
- redis
105+
restart: on-failure
101106

102107
analysis-server:
103108
env_file:
104109
- ./server/dockerconfs/.env.local
105-
image: tca-analysis:latest
110+
image: tencenttca/tca-analysis:latest
106111
build:
107112
context: ./server/projects/analysis
108113
dockerfile: ../../dockerconfs/Dockerfile-common-${ORIGIN:-mirror}
@@ -125,7 +130,7 @@ services:
125130
analysis-worker:
126131
env_file:
127132
- ./server/dockerconfs/.env.local
128-
image: tca-analysis:latest
133+
image: tencenttca/tca-analysis:latest
129134
command:
130135
[
131136
"celery",
@@ -139,6 +144,9 @@ services:
139144
volumes:
140145
- ./server/configs/django/local_analysis.py:/var/www/django/codedog/codedog/settings/local.py
141146
- ./.docker_data/logs/analysis_worker:/var/www/django/codedog/log
147+
healthcheck:
148+
test: ["CMD-SHELL", "bash bin/healthy_check.sh"]
149+
interval: 60s
142150
depends_on:
143151
- mysql
144152
- redis
@@ -149,6 +157,7 @@ services:
149157
build:
150158
context: ./server/projects/login
151159
dockerfile: ../../dockerconfs/Dockerfile-common-${ORIGIN:-mirror}
160+
image: tencenttca/tca-login:latest
152161
command:
153162
[
154163
"gunicorn",
@@ -170,6 +179,7 @@ services:
170179
build:
171180
context: ./server/projects/file
172181
dockerfile: ../../dockerconfs/Dockerfile-common-${ORIGIN:-mirror}
182+
image: tencenttca/tca-file:latest
173183
command:
174184
[
175185
"gunicorn",
@@ -202,6 +212,7 @@ services:
202212
build:
203213
context: ./server/projects/scmproxy
204214
dockerfile: ../../dockerconfs/Dockerfile-common-${ORIGIN:-mirror}
215+
image: tencenttca/tca-scmproxy:latest
205216
command: [ "python", "proxyserver.py" ]
206217
volumes:
207218
- ./.docker_data/logs/scmproxy:/var/www/django/codedog/logs
@@ -233,6 +244,7 @@ services:
233244
build:
234245
context: ./client
235246
dockerfile: Dockerfile
247+
image: tencenttca/tca-client:latest
236248
command:
237249
- /bin/bash
238250
- -c

server/projects/analysis/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
FROM python:3.7.12-slim
2-
# For ARM
3-
# FROM arm64v8/python:3.7.12-slim
42

53
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
64
echo 'deb http://mirrors.tencent.com/debian/ bullseye main non-free contrib' > /etc/apt/sources.list && \
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
function get_target_process(){
4+
proc_name=$1
5+
pids=`ps -ef | grep "$proc_name" | grep -v grep | awk '{print $2}'`
6+
echo $pids
7+
}
8+
9+
function check_target_process_exist() {
10+
proc_name=$1
11+
pids=$( get_target_process "$proc_name" )
12+
ret=""
13+
if [ ! -n "$pids" ]; then
14+
ret="false"
15+
else
16+
ret="true"
17+
fi
18+
echo "$ret"
19+
}
20+
21+
function ping_celery() {
22+
celery -A codedog inspect ping -d celery@$HOSTNAME 2>&1 >/dev/null
23+
echo $?
24+
}
25+
26+
function check_celery_healthy() {
27+
result=0
28+
for((i=1;i<=3;i++)); do
29+
result=`ping_celery`
30+
echo "check celery result: $result"
31+
if [ "$result" == "0" ]; then
32+
break
33+
fi
34+
sleep 10
35+
done
36+
37+
if [ "$result" != "0" ]; then
38+
pids=`get_target_process 'celery -A codedog'`
39+
kill -HUP $pids
40+
fi
41+
}
42+
43+
check_celery_healthy
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
function error_exit() {
4+
LOG_ERROR "$1" 1>&2
5+
exit 1
6+
}
7+
8+
python manage.py createcachetable || error_exit "create cache table failed"
9+
python manage.py migrate --noinput --traceback || error_exit "migrate table failed"
10+
python manage.py initialuser || error_exit "init project data failed"

server/projects/file/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
FROM python:3.7.12-slim
2-
# For ARM
3-
# FROM arm64v8/python:3.7.12-slim
42

53
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
64
echo 'deb http://mirrors.tencent.com/debian/ bullseye main non-free contrib' > /etc/apt/sources.list && \

server/projects/file/bin/init.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
function error_exit() {
4+
LOG_ERROR "$1" 1>&2
5+
exit 1
6+
}
7+
8+
python manage.py migrate --noinput --traceback || error_exit "migrate table failed"

server/projects/file/codedog_file_server/settings.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,17 @@
9292
# Database
9393
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
9494

95+
# 数据库配置
9596
DATABASES = {
9697
"default": {
97-
"ENGINE": "django.db.backends.sqlite3",
98-
"NAME": PROJECT_PATH / "db.sqlite3",
99-
}
98+
"ENGINE": "django.db.backends.mysql",
99+
"NAME": os.environ.get("FILE_DB_NAME", "codedog_file"),
100+
"USER": os.environ.get("FILE_DB_USER"),
101+
"PASSWORD": os.environ.get("FILE_DB_PASSWORD"),
102+
"HOST": os.environ.get("FILE_DB_HOST"),
103+
"PORT": os.environ.get("FILE_DB_PORT"),
104+
"OPTIONS": {"charset":"utf8mb4"},
105+
},
100106
}
101107

102108
# Password validation
@@ -238,6 +244,12 @@
238244
send_default_pii=True
239245
)
240246

247+
# ==============================================
248+
# 服务配置
249+
# ==============================================
250+
API_TICKET_SALT = os.environ.get("API_TICKET_SALT")
251+
API_TICKET_TOKEN = os.environ.get("API_TICKET_TOKEN")
252+
241253
# ==============================================
242254
# 加载本地local.py
243255
# ==============================================

server/projects/login/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
FROM python:3.7.12-slim
2-
# For ARM
3-
# FROM arm64v8/python:3.7.12-slim
42

53
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
64
echo 'deb http://mirrors.tencent.com/debian/ bullseye main non-free contrib' > /etc/apt/sources.list && \

server/projects/login/bin/init.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
function error_exit() {
4+
LOG_ERROR "$1" 1>&2
5+
exit 1
6+
}
7+
8+
python manage.py createcachetable >/dev/null || error_exit "create cache table failed"
9+
python manage.py migrate --noinput --traceback >/dev/null || error_exit "migrate table failed"
10+
python manage.py initializedb || error_exit "init project data failed"

server/projects/main/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
FROM python:3.7.12-slim
2-
# For ARM
3-
# FROM arm64v8/python:3.7.12-slim
42

53
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
64
echo 'deb http://mirrors.tencent.com/debian/ bullseye main non-free contrib' > /etc/apt/sources.list && \

0 commit comments

Comments
 (0)