diff --git a/docs/Dockerfile/Dockerfile b/docs/Dockerfile/Dockerfile index df615b8..75744bb 100644 --- a/docs/Dockerfile/Dockerfile +++ b/docs/Dockerfile/Dockerfile @@ -1,19 +1,17 @@ -FROM alpine:3.6 +FROM python:3.6-alpine + +RUN echo -e "http://mirrors.aliyun.com/alpine/v3.9/main\nhttp://mirrors.aliyun.com/alpine/v3.9/community" > /etc/apk/repositories +RUN apk update && apk add --no-cache nginx mariadb nodejs-npm git +RUN apk add --no-cache --virtual .build-deps openssl-dev gcc musl-dev python3-dev libffi-dev openssl-dev make +RUN git clone https://github.com/openspug/spug.git --depth=1 /spug && cd /spug && git pull +RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && pip install --upgrade pip && pip install --no-cache-dir -r /spug/spug_api/requirements.txt \ + && pip install --no-cache-dir gunicorn \ + && apk del .build-deps +RUN cd /spug/spug_web/ && npm i && npm run build \ + && mv /spug/spug_web/dist /var/www/ -RUN echo -e "http://mirrors.aliyun.com/alpine/v3.6/main\nhttp://mirrors.aliyun.com/alpine/v3.6/community" > /etc/apk/repositories -RUN apk update && apk add --no-cache ca-certificates python3 nginx mariadb nodejs-npm git -RUN apk add --no-cache --virtual .build-deps python3-dev gcc musl-dev libffi-dev openssl-dev make \ - && git clone https://github.com/openspug/spug.git /spug \ - && cd /spug && git pull \ - && pip3 install --no-cache-dir -r /spug/spug_api/requirements.txt \ - && pip3 install --no-cache-dir gunicorn \ - && apk del .build-deps -RUN cd /spug/spug_web/ && npm i -d --registry=https://registry.npm.taobao.org \ - && npm run build \ - && mv /var/lib/nginx/html /var/lib/nginx/html.bak && mv /spug/spug_web/dist /var/lib/nginx/html - ADD default.conf /etc/nginx/conf.d/default.conf ADD entrypoint.sh /entrypoint.sh ADD scripts /scripts -ENTRYPOINT ["sh", "/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["sh", "/entrypoint.sh"] diff --git a/docs/Dockerfile/default.conf b/docs/Dockerfile/default.conf index da5b688..af29b3c 100644 --- a/docs/Dockerfile/default.conf +++ b/docs/Dockerfile/default.conf @@ -14,7 +14,7 @@ server { } location / { - root /var/lib/nginx/html; + root /var/www/dist/; } error_page 404 =200 /index.html; diff --git a/docs/Dockerfile/entrypoint.sh b/docs/Dockerfile/entrypoint.sh index e79edbe..6b84097 100644 --- a/docs/Dockerfile/entrypoint.sh +++ b/docs/Dockerfile/entrypoint.sh @@ -26,7 +26,7 @@ fi cd /spug/spug_api nginx nohup /usr/bin/mysqld_safe --datadir=/var/lib/mysql --user=root & -sleep 2 -/usr/bin/python3 /scripts/init_spug.py +sleep 3 +/usr/local/bin/python /scripts/init_spug.py 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 1277bbd..7155aef 100644 --- a/docs/Dockerfile/scripts/init_config.sh +++ b/docs/Dockerfile/scripts/init_config.sh @@ -11,6 +11,8 @@ DOCKER_URL = 'unix:///var/run/docker.sock' SQLALCHEMY_ECHO = False EOF -echo "SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://${MYSQL_USER:-spuguser}:${MYSQL_PASSWORD:-spugpwd}@localhost/${MYSQL_DATABASE:-spug}'" >> /spug/spug_api/config.py +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 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 + +cat /spug/spug_api/config.py diff --git a/docs/Dockerfile/scripts/init_db.sh b/docs/Dockerfile/scripts/init_db.sh index f612c5e..b87cd1e 100644 --- a/docs/Dockerfile/scripts/init_db.sh +++ b/docs/Dockerfile/scripts/init_db.sh @@ -1,7 +1,9 @@ set -e if [ ! -d /var/lib/mysql/mysql ]; then - mysql_install_db &> /dev/null + echo 'start init mysql.........' + # mysql_install_db &> /dev/null + mysql_install_db --datadir=/var/lib/mysql mkdir -p /run/mysqld tfile=`mktemp` echo "USE mysql;" >> $tfile