From cb5d079bf68b2e3f27ab07bef29a97fa4efb8e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E4=BA=8C=E7=8C=9B?= Date: Fri, 1 Nov 2019 21:12:14 +0800 Subject: [PATCH] =?UTF-8?q?F=20-=20=E9=95=9C=E5=83=8F=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=9C=A8=E6=9F=90=E4=BA=9B=E6=83=85=E5=86=B5=E4=B8=8B=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++++- docs/Dockerfile/entrypoint.sh | 17 ++++++++++------- docs/Dockerfile/scripts/init_config.sh | 7 +++++-- 3 files changed, 20 insertions(+), 10 deletions(-) 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