add deploy.py

ready for deploy
This commit is contained in:
David 2019-05-08 13:25:35 +08:00
parent 437234f60b
commit dc599b04b4
5 changed files with 70 additions and 2 deletions

2
.gitignore vendored
View File

@ -1,6 +1,6 @@
.DS_Store
frontend/node_modules
/dist
frontend/dist
# Editor directories and files
.idea

22
Dockerfile Normal file
View File

@ -0,0 +1,22 @@
FROM python:3.7-alpine
LABEL AUTHOR="DavidZ"
# 更改alpine镜像源并安装依赖
RUN sed -i 's/dl-cdn.alpinelinux.org/mirror.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \
&& apk add -U --no-cache gcc musl-dev postgresql-dev
# 更换pip镜像源并更新pip
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple \
&& pip install --upgrade pip
# 安装uwsgi
RUN apk add -U --no-cache linux-headers --virtual .uwsgi-deps \
&& pip3 install uwsgi \
&& apk del .uwsgi-deps
# 安装pipenv
RUN pip install pipenv
# 安装node.js
RUN apk add -U --no-cache nodejs

View File

@ -12,6 +12,7 @@ django-filter = "*"
flower = "*"
celery = "*"
eventlet = "*"
psycopg2 = "*"
[requires]
python_version = "3.7"

19
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "cddda4d1837db6f95f5827fdd013a1a3b026fe2e9a8b7af1fd195cbbbe87d151"
"sha256": "d4ed3f93f7138a3827f3b5461a31c868bd6f1bb187168837bd3319df74611876"
},
"pipfile-spec": 6,
"requires": {
@ -128,6 +128,23 @@
],
"version": "==1.5"
},
"psycopg2": {
"hashes": [
"sha256:00cfecb3f3db6eb76dcc763e71777da56d12b6d61db6a2c6ccbbb0bff5421f8f",
"sha256:076501fc24ae13b2609ba2303d88d4db79072562f0b8cc87ec1667dedff99dc1",
"sha256:4e2b34e4c0ddfeddf770d7df93e269700b080a4d2ec514fec668d71895f56782",
"sha256:5cacf21b6f813c239f100ef78a4132056f93a5940219ec25d2ef833cbeb05588",
"sha256:61f58e9ecb9e4dc7e30be56b562f8fc10ae3addcfcef51b588eed10a5a66100d",
"sha256:8954ff6e47247bdd134db602fcadfc21662835bd92ce0760f3842eacfeb6e0f3",
"sha256:b6e8c854cdc623028e558a409b06ea2f16d13438335941c7765d0a42b5bedd33",
"sha256:baca21c0f7344576346e260454d0007313ccca8c170684707a63946b27a56c8f",
"sha256:bb1735378770fb95dbe392d29e71405d45c8bdcfa064f916504833a92ab03c55",
"sha256:de3d3c46c1ee18f996db42d1eb44cf1565cc9e38fb1dbd9b773ff6b3fa8035d7",
"sha256:dee885602bb200bdcb1d30f6da6c7bb207360bc786d0a364fe1540dd14af0bab"
],
"index": "pypi",
"version": "==2.8.2"
},
"pytz": {
"hashes": [
"sha256:303879e36b721603cc54604edcac9d20401bdbe31e1e4fdee5b9f98d5d31dfda",

28
deploy/deploy.sh Normal file
View File

@ -0,0 +1,28 @@
ROOT_DIR=$(cd $(dirname ${BASH_SOURCE[0]}); pwd)
CONTAINER_NAME=BookingService
cd $ROOT_DIR/../
echo
echo Git
git pull
echo
echo Install python dependencies and migrate
docker exec $CONTAINER_NAME /bin/sh -c "cd /project
&& pipenv run pip freeze > requirements.txt
&& pip install -r requirements.txt
&& python manage.py makemigrations
&& python manage.py migrate"
echo
echo Build new frontend files
docker exec $CONTAINER_NAME /bin/sh -c "cd /project
&& python manage.py collectstatic --noinput
&& cd /project/frontend
&& npm install
&& npm run build"
echo
echo Restart Container
docker restart $CONTAINER_NAME