F - 镜像 修复在某些情况下启动失败的问题

1.x
雷二猛 2019-11-01 21:12:14 +08:00
parent 485725d185
commit cb5d079bf6
3 changed files with 20 additions and 10 deletions

View File

@ -55,7 +55,11 @@ $ -e MYSQL_HOST = "192.168.1.10" // 指定数据库地址
-e REGISTRY_USER="hubuser" // 指定私有镜像仓库用户名
-e REGISTRY_PASSWORD="hubpwd" // 指定私有镜像仓库密码
```
⚠️注意:如果使用了 `-e MYSQL_HOST` 意味着你将使用外部数据库,容器内自带的数据库将不会启动,且你需要通过以下方式手动执行数据库的初始化操作
```
# 在容器内执行
/usr/bin/python3 /scripts/init_spug.py
```
更多Dockerfile [Dockerfile](https://github.com/openspug/spug/tree/master/docs/Dockerfile)

View File

@ -4,10 +4,13 @@ set -e
# init db
if [ ! -d /var/lib/mysql/mysql ]; then
echo 'Initializing db, please wait ...'
REQUIRE_INIT_OPS=true
/bin/sh /scripts/init_db.sh
if [ -z $MYSQL_HOST ]; then
if [ ! -d /var/lib/mysql/mysql ]; then
echo 'Initializing db, please wait ...'
REQUIRE_INIT_OPS=true
/bin/sh /scripts/init_db.sh
fi
nohup /usr/bin/mysqld_safe --datadir=/var/lib/mysql --user=root &
fi
# init nginx
@ -25,8 +28,8 @@ fi
cd /spug/spug_api
nginx
nohup /usr/bin/mysqld_safe --datadir=/var/lib/mysql --user=root &
sleep 3
/usr/local/bin/python /scripts/init_spug.py
if [ $REQUIRE_INIT_OPS == true ]; then
/usr/bin/python3 /scripts/init_spug.py
fi
gunicorn --threads=32 main:app -b 0.0.0.0:3000

View File

@ -21,9 +21,12 @@ LDAP_CONFIG = {
}
EOF
# echo "SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://${MYSQL_USER:-spuguser}:${MYSQL_PASSWORD:-spugpwd}@${MYSQL_HOST:-localhost}:${MYSQL_PORT:-3306}/${MYSQL_DATABASE:-spug}?unix_socket=/run/mysqld/mysqld.sock'" >> /spug/spug_api/config.py
echo "SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://${MYSQL_USER:-spuguser}:${MYSQL_PASSWORD:-spugpwd}@${MYSQL_HOST:-localhost}:${MYSQL_PORT:-3306}/${MYSQL_DATABASE:-spug}'" >> /spug/spug_api/config.py
if [ -z $MYSQL_HOST ]; then
echo "SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://${MYSQL_USER:-spuguser}:${MYSQL_PASSWORD:-spugpwd}@localhost/${MYSQL_DATABASE:-spug}?unix_socket=/run/mysqld/mysqld.sock'" >> /spug/spug_api/config.py
else
echo "SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://${MYSQL_USER:-spuguser}:${MYSQL_PASSWORD:-spugpwd}@${MYSQL_HOST:-localhost}:${MYSQL_PORT:-3306}/${MYSQL_DATABASE:-spug}'" >> /spug/spug_api/config.py
fi
echo "DOCKER_REGISTRY_SERVER = '${REGISTRY_SERVER:-hub.qbangmang.com}'" >> /spug/spug_api/config.py
echo "DOCKER_REGISTRY_AUTH = {'username': '${REGISTRY_USER}', 'password': '${REGISTRY_PASSWORD}'}" >> /spug/spug_api/config.py