From dad4178f1ef5afcc2ded4acb1ab03fd564652452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AD=E7=BF=BC=E7=BE=8A=E7=8E=8B?= <1993333339@qq.com> Date: Mon, 29 May 2023 03:42:03 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=94=B9docker-compose=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 3 ++- dockerdata/start.sh | 29 ++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index d323b80..2dde1e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM pearadminflask/python3.7-flask:pillow COPY . /app/ +COPY dockerdata/start.sh /app/ COPY dockerdata/gunicorn.conf.py /app/ WORKDIR /app/ @@ -14,4 +15,4 @@ RUN chmod +x start.sh RUN sed -i 's/MYSQL_HOST = "127.0.0.1"/MYSQL_HOST = "mysql"/' applications/config.py RUN sed -i 's/REDIS_HOST = "127.0.0.1"/REDIS_HOST = "redis"/' applications/config.py -CMD /bin/sh \ No newline at end of file +CMD /bin/sh diff --git a/dockerdata/start.sh b/dockerdata/start.sh index 7191f70..54dfe08 100644 --- a/dockerdata/start.sh +++ b/dockerdata/start.sh @@ -1,6 +1,25 @@ -#!/bin/sh -while ! flask db init ; do - sleep 5 ; -done ; -flask db migrate && flask db upgrade && flask admin init +#!/bin/bash + +# Wait for MySQL container to be ready +echo "Waiting for MySQL container to start..." +until mysql -h mysql -uroot -p123456 -e ";" 2>/dev/null; do + echo "MySQL container not ready, sleeping for 5 seconds..." + sleep 5 +done +echo "MySQL container started successfully!" + +# to start create the dababase +echo " start to create the databse... " +mysql -uroot -p123456 -hmysql -e 'CREATE DATABASE PearAdminFlask DEFAULT CHARSET UTF8;' + + +# Initialize Flask database +echo "Initializing Flask database..." +flask db init +flask db migrate +flask db upgrade +flask admin init + +# Start gunicorn application +echo "Starting gunicorn application..." exec gunicorn -c gunicorn.conf.py "applications:create_app()" \ No newline at end of file -- Gitee From 386136b4db43e4d9aebaae02b32e8f374aef6279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AD=E7=BF=BC=E7=BE=8A=E7=8E=8B?= <1993333339@qq.com> Date: Mon, 29 May 2023 03:43:35 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=94=B9docker-compose=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- start.sh | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 start.sh diff --git a/start.sh b/start.sh deleted file mode 100644 index 54dfe08..0000000 --- a/start.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -# Wait for MySQL container to be ready -echo "Waiting for MySQL container to start..." -until mysql -h mysql -uroot -p123456 -e ";" 2>/dev/null; do - echo "MySQL container not ready, sleeping for 5 seconds..." - sleep 5 -done -echo "MySQL container started successfully!" - -# to start create the dababase -echo " start to create the databse... " -mysql -uroot -p123456 -hmysql -e 'CREATE DATABASE PearAdminFlask DEFAULT CHARSET UTF8;' - - -# Initialize Flask database -echo "Initializing Flask database..." -flask db init -flask db migrate -flask db upgrade -flask admin init - -# Start gunicorn application -echo "Starting gunicorn application..." -exec gunicorn -c gunicorn.conf.py "applications:create_app()" \ No newline at end of file -- Gitee