diff --git a/README.md b/README.md index 84b5fb2..38229e4 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/docs/Dockerfile/entrypoint.sh b/docs/Dockerfile/entrypoint.sh index 6b84097..522c179 100644 --- a/docs/Dockerfile/entrypoint.sh +++ b/docs/Dockerfile/entrypoint.sh @@ -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 diff --git a/docs/Dockerfile/scripts/init_config.sh b/docs/Dockerfile/scripts/init_config.sh index 134f1fa..a83553a 100644 --- a/docs/Dockerfile/scripts/init_config.sh +++ b/docs/Dockerfile/scripts/init_config.sh @@ -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