修改了基于docker 一键部署的Dockerfile 和dockercompose.yaml

This commit is contained in:
ranee@ubuntu
2023-05-07 02:34:58 +08:00
parent 0d0998ec3c
commit 157a83711f
6 changed files with 146 additions and 1 deletions
+31
View File
@@ -0,0 +1,31 @@
FROM python:3.7-alpine
COPY . /app/
WORKDIR /app/
ENV TIME_ZONE Asia/Shanghai
ENV PIPURL "https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.douban.com"
RUN apk update \
&& apk add --virtual mysqlclient-build gcc python3-dev musl-dev \
&& apk add --no-cache mariadb-dev \
&& apk add --virtual system-build linux-headers libffi-dev \
&& apk add --no-cache jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
&& apk add --no-cache bash bash-doc bash-completion \
&& apk add --no-cache libxslt-dev tzdata g++
RUN echo "${TIME_ZONE}" > /etc/timezone \
&& ln -sf /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime
RUN pip --no-cache-dir install -i ${PIPURL} --upgrade pip \
&& pip --no-cache-dir install -i ${PIPURL} -r requirements.txt \
&& pip --no-cache-dir install -i ${PIPURL} gunicorn
RUN apk add mysql-client
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
WORKDIR /app
CMD /bin/sh
+27
View File
@@ -0,0 +1,27 @@
version: '3'
services:
redis:
image: redis
ports:
- "63799:6379"
mysql:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: 123456
LANG: C.UTF-8
TZ: Asia/Shanghai
MYSQL_CHARSET: utf8mb4
MYSQL_COLLATION: utf8mb4_unicode_ci
ports:
- "3306:3306"
flask:
build:
context: .
dockerfile: Dockerfile
ports:
- "5000:5000"
depends_on:
- redis
- mysql
restart: always
command: sh -c "./start.sh"
+3 -1
View File
@@ -8,6 +8,8 @@ WORKDIR /app/
ENV TIME_ZONE Asia/Shanghai
RUN chmod +x /app/start.sh
RUN echo "${TIME_ZONE}" > /etc/timezone \
&& ln -sf /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime \
&& chmod +x /app/start.sh
CMD ./start.sh
+40
View File
@@ -0,0 +1,40 @@
version: '3'
services:
mysql:
image: "mysql:5.7"
container_name: mysql
restart: always
ports:
- "3306:3306"
volumes:
- "./dockerdata/mysql/data:/var/lib/mysql"
- "./dockerdata/mysql/initdb:/docker-entrypoint-initdb.d"
environment:
LANG: C.UTF-8
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: 123456
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
networks:
flask-network:
ipv4_address: 172.10.1.31
flask:
build:
context: .
dockerfile: Dockerfile.server
container_name: flask
restart: always
ports:
- "8000:8000"
depends_on:
- mysql
networks:
flask-network:
ipv4_address: 172.10.1.11
networks:
flask-network:
driver: bridge
ipam:
config:
- subnet: 172.10.0.0/16
+19
View File
@@ -0,0 +1,19 @@
import os
import multiprocessing
bind = '0.0.0.0:8000'
backlog = 512
chdir = os.path.dirname(os.path.abspath(__file__))
timeout = 30
worker_class = 'sync'
workers = multiprocessing.cpu_count() * 2 + 1
threads = 2
loglevel = 'info'
access_log_format = '%(t)s %(p)s %(h)s "%(r)s" %(s)s %(L)s %(b)s %(f)s" "%(a)s"'
if not os.path.exists('logs'):
os.mkdir('logs')
accesslog = os.path.join(chdir, "logs/gunicorn_access.log")
errorlog = os.path.join(chdir, "logs/gunicorn_error.log")
+26
View File
@@ -0,0 +1,26 @@
#!/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 Flask application
echo "Starting Flask application..."
python3 app.py