From f0a336a6214d0c9f5c334dff6b18e5dd1e7a18d0 Mon Sep 17 00:00:00 2001 From: CS-Tao <990296951@qq.com> Date: Thu, 13 Sep 2018 12:01:33 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E9=92=88=E5=AF=B9=20Django=20=E7=9A=84?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- django/gtd_uwsgi.ini | 11 ----------- nginx/Dockerfile | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 django/gtd_uwsgi.ini diff --git a/django/gtd_uwsgi.ini b/django/gtd_uwsgi.ini deleted file mode 100644 index 343f567..0000000 --- a/django/gtd_uwsgi.ini +++ /dev/null @@ -1,11 +0,0 @@ -[uwsgi] -chdir = /opt/AQI-Background -module = server.wsgi -# http = :8080 -socket = /var/aqi/uwsgi-sock/aqi-background.sock -master = true -process = 4 -vacuum = true -enable-threads = true -chmod-socket = 666 -logto = /var/aqi/logs/django-uwsgi/aqi_uwsgi.log diff --git a/nginx/Dockerfile b/nginx/Dockerfile index f56f7b5..aeb4911 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -5,7 +5,7 @@ ENV TZ UTC ENV LANG C.UTF-8 ENV WEB_REPO_URL https://github.com/CS-Tao/AQI-Visualization.git ENV WEB_REPO_BRANCH gh-pages -ENV WEB_FOLDER web +ENV WEB_FOLDER ./ ENV WEB_OLD_SRC_URL http://localhost:2002 ENV WEB_NEW_SRC_URL ../ From a4cd70953396d794a6801c2e8ebf281de762a8c8 Mon Sep 17 00:00:00 2001 From: CS-Tao Date: Thu, 13 Sep 2018 22:08:44 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 2 +- .travis-ci/deploy | 5 --- .travis.yml | 29 ------------- appveyor.yml | 14 +++--- django/Dockerfile | 22 ++++++++-- django/aqi_uwsgi.ini | 12 ++++++ django/docker-uwsgi-entrypoint.sh | 4 +- django/settings.py | 72 ++++++++++++++++++++++++------- django/update_django | 12 ++++++ docker-compose.yml | 12 +++--- nginx/Dockerfile | 16 ++++--- nginx/default.conf | 4 +- nginx/docker-entrypoint.sh | 2 + postgis/Dockerfile | 13 +++++- postgis/_import_data | 4 +- postgis/create_role.sh | 8 ++-- postgis/import_data | 4 +- postgis/init_db.sh | 2 +- 18 files changed, 147 insertions(+), 90 deletions(-) delete mode 100644 .travis-ci/deploy delete mode 100644 .travis.yml create mode 100644 django/aqi_uwsgi.ini create mode 100644 django/update_django diff --git a/.env b/.env index fbcdd39..80fce01 100644 --- a/.env +++ b/.env @@ -17,4 +17,4 @@ ENV_POSTGRES_USER=cstao ENV_POSTGRES_PASSWD=cstao # 'postgres' 用户的数据库密码 -ENV_POSTGRES_PASSWD_ADMIN=0000 +ENV_POSTGRES_PASSWD_ADMIN=cstao diff --git a/.travis-ci/deploy b/.travis-ci/deploy deleted file mode 100644 index 17612f1..0000000 --- a/.travis-ci/deploy +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin -docker-compose push postgis -docker-compose push django -docker-compose push nginx diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2064a28..0000000 --- a/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -sudo: required - -language: ruby - -services: - - docker - -env: - - DOCKER_COMPOSE_VERSION=1.21.1 - -before_install: - - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - - sudo rm /usr/local/bin/docker-compose - - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose - - chmod +x docker-compose - - sudo mv docker-compose /usr/local/bin - -install: - - docker-compose build - -script: - - docker-compose up -d - -deploy: - provider: script - script: bash .travis-ci/deploy - on: - branch: - - master diff --git a/appveyor.yml b/appveyor.yml index 9226170..4e89143 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,12 +15,12 @@ install: build_script: - docker-compose up -d - # - sleep 10s + - sleep 10s -# before_test: -# - docker exec -i $(docker ps -a | grep django | cut -c1-12) python manage.py migrate -# - sleep 3s +before_test: + - docker exec -i $(docker ps -a | grep django | cut -c1-12) python manage.py migrate + - sleep 3s -# test_script: - # - chmod +x .appveyor/test - # - .appveyor/test http://127.0.0.1:2101/web/#/dashboard +test_script: + - chmod +x .appveyor/test + - .appveyor/test http://127.0.0.1:2101/web/#/ diff --git a/django/Dockerfile b/django/Dockerfile index 1ff10b2..5054802 100644 --- a/django/Dockerfile +++ b/django/Dockerfile @@ -4,17 +4,29 @@ LABEL maintainer="CS-Tao " version="1.0.0" ENV LANG C.UTF-8 ENV TZ UTC ENV DJANGO_REPO_URL https://github.com/RS-GIS-Geeks/AQI-Background.git -ENV DJANGO_REPO_BRANCH master +ENV DJANGO_REPO_BRANCH docker RUN echo "Installing packages ..." \ - # && sed -i 's|deb.debian.org|mirrors.ustc.edu.cn|g' /etc/apt/sources.list \ - # && sed -i 's|security.debian.org|mirrors.ustc.edu.cn/debian-security|g' /etc/apt/sources.list \ + # <切换 apt 中国源> + && echo 'deb http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' > /etc/apt/sources.list \ + && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' >> /etc/apt/sources.list \ + && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ + && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ + && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ + && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ + # && apt-get update \ && apt-get install -y --no-install-recommends libgdal-dev git \ && cd /opt \ && git clone ${DJANGO_REPO_URL} -b ${DJANGO_REPO_BRANCH} AQI-Background \ && cd AQI-Background \ && ls -a -l \ + && mkdir -p ~/.pip/ \ + && echo '[global]' > ~/.pip/pip.conf \ + && echo 'index-url = https://pypi.tuna.tsinghua.edu.cn/simple' >> ~/.pip/pip.conf \ + && echo '[install]' >> ~/.pip/pip.conf \ + && echo 'trusted-host = pypi.tuna.tsinghua.edu.cn' >> ~/.pip/pip.conf \ + # && pip install -r requirements.txt \ && apt-get purge -y --auto-remove git \ && rm -rf /var/lib/apt/lists/* @@ -22,8 +34,10 @@ RUN echo "Installing packages ..." \ COPY docker-uwsgi-entrypoint.sh /docker-uwsgi-entrypoint.sh COPY settings.py /opt/settings.py COPY aqi_uwsgi.ini /opt/uwsgi.ini +COPY update_django /usr/local/bin/update_django -RUN chmod +x /docker-uwsgi-entrypoint.sh +RUN chmod +x /docker-uwsgi-entrypoint.sh \ + && chmod +x /usr/local/bin/update_django ENV PYTHONHOME /usr/local ENV PYTHONPATH /usr/local/lib/python3.6 diff --git a/django/aqi_uwsgi.ini b/django/aqi_uwsgi.ini new file mode 100644 index 0000000..544bbc4 --- /dev/null +++ b/django/aqi_uwsgi.ini @@ -0,0 +1,12 @@ +[uwsgi] +chdir = /opt/AQI-Background +module = server.wsgi +# http = :8080 +socket = /var/aqi/uwsgi-sock/aqi-background.sock +master = true +process = 4 +vacuum = true +enable-threads = true +chmod-socket = 666 +logto = /var/aqi/logs/django-uwsgi/aqi_uwsgi.log +py-autoreload = 1 \ No newline at end of file diff --git a/django/docker-uwsgi-entrypoint.sh b/django/docker-uwsgi-entrypoint.sh index 3b10d9c..0eea249 100644 --- a/django/docker-uwsgi-entrypoint.sh +++ b/django/docker-uwsgi-entrypoint.sh @@ -24,10 +24,10 @@ DATABASES = { 'default': { 'ENGINE': 'django.contrib.gis.db.backends.postgis', 'NAME': '$POSTGRES_DB', - 'USER': '$POSTGRES_USER', + 'USER': '$POSTGRES_USER_FOR_DB', 'HOST': '$POSTGRES_HOST', 'PORT': '$POSTGRES_PORT', - 'PASSWORD': '$POSTGRES_PASSWD', + 'PASSWORD': '$POSTGRES_PASSWD_FOR_USER', } } diff --git a/django/settings.py b/django/settings.py index 507eb7b..5c91b5d 100644 --- a/django/settings.py +++ b/django/settings.py @@ -12,6 +12,19 @@ import os +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +""" +Django settings for server project. +Generated by 'django-admin startproject' using Django 2.0.2. +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/ref/settings/ +""" + +import os + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -20,34 +33,32 @@ # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'l9r6#medm(&dxjl&16ur8tze&jx*v*-(!%ap_mn6slnz1=g+b$' +SECRET_KEY = 'hm04xp^ffsd_6(cmy&t+8a#f6^*^8b&h$1xium23x0y*q4trr2' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False +DEBUG = True ALLOWED_HOSTS = ['*'] + # Application definition INSTALLED_APPS = [ - 'rear_end_services.apps.SuitConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'rear_end_services.apps.RearEndServicesConfig', - 'django.contrib.gis', + 'corsheaders', 'rest_framework', - 'rest_framework_gis', - 'rest_framework_swagger', - 'web', + 'aqiserver' ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', @@ -60,8 +71,7 @@ TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [os.path.join(BASE_DIR, 'templates')] - , + 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -77,6 +87,21 @@ WSGI_APPLICATION = 'server.wsgi.application' +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': '', + 'USER': '', + 'PASSWORD': '', + 'HOST': 'localhost', + 'PORT': 5432 + } +} + + # Password validation # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators @@ -99,9 +124,9 @@ # Internationalization # https://docs.djangoproject.com/en/2.0/topics/i18n/ -LANGUAGE_CODE = 'zh-hans' +LANGUAGE_CODE = 'en-us' -TIME_ZONE = 'Asia/Shanghai' +TIME_ZONE = 'UTC' USE_I18N = True @@ -117,7 +142,22 @@ STATIC_URL = '/aqi-static/' -REST_FRAMEWORK = { - 'PAGE_SIZE': 10, - 'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',), -} +#跨域增加忽略 +CORS_ALLOW_CREDENTIALS = True +CORS_ORIGIN_ALLOW_ALL = True +# CORS_ORIGIN_WHITELIST = () + + +CORS_ALLOW_METHODS = ( + 'DELETE', + 'GET', + 'OPTIONS', + 'PATCH', + 'POST', + 'PUT', + 'VIEW', +) + +CORS_ALLOW_HEADERS = ( + "*", +) diff --git a/django/update_django b/django/update_django new file mode 100644 index 0000000..fe162fe --- /dev/null +++ b/django/update_django @@ -0,0 +1,12 @@ +#!/bin/bash +set -e + +apt-get update +apt-get install -y --no-install-recommends libgdal-dev git +git pull origin ${DJANGO_REPO_BRANCH} +git log -n2 +pip install -r requirements.txt +apt-get purge -y --auto-remove git +rm -rf /var/lib/apt/lists/* + +echo "Django updated" diff --git a/docker-compose.yml b/docker-compose.yml index a06fe7f..2baab0e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -26,11 +26,11 @@ services: POSTGRES_HOST: "postgis" POSTGRES_PORT: "5432" POSTGRES_DB: "${ENV_POSTGRES_DB}" - POSTGRES_USER: "${ENV_POSTGRES_USER}" - POSTGRES_PASSWD: "${ENV_POSTGRES_PASSWD}" + POSTGRES_USER_FOR_DB: "${ENV_POSTGRES_USER}" + POSTGRES_PASSWD_FOR_USER: "${ENV_POSTGRES_PASSWD}" volumes: - uwsgi-sock:/var/aqi/uwsgi-sock - - static-files:/opt/aqi/static + - static-files:/opt/aqidjango/static - logs:/var/aqi/logs networks: - network @@ -43,10 +43,10 @@ services: dockerfile: Dockerfile restart: always environment: - POSTGRES_USER: ${ENV_POSTGRES_USER} - POSTGRES_PASSWD: ${ENV_POSTGRES_PASSWD} - POSTGRES_PASSWORD: ${ENV_POSTGRES_PASSWD_ADMIN} + POSTGRES_USER_FOR_DB: ${ENV_POSTGRES_USER} + POSTGRES_PASSWD_FOR_USER: ${ENV_POSTGRES_PASSWD} POSTGRES_DB: ${ENV_POSTGRES_DB} + POSTGRES_PASSWORD: ${ENV_POSTGRES_PASSWD_ADMIN} PGDATA: /var/lib/postgresql/data/pgdata POSTGRES_INITDB_XLOGDIR: /var/aqi/logs/postgresql volumes: diff --git a/nginx/Dockerfile b/nginx/Dockerfile index aeb4911..b3dabcf 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -10,12 +10,14 @@ ENV WEB_OLD_SRC_URL http://localhost:2002 ENV WEB_NEW_SRC_URL ../ RUN echo "Installing packages ..." \ - # && echo 'deb http://mirrors.ustc.edu.cn/debian jessie main contrib non-free' > /etc/apt/sources.list \ - # && echo 'deb-src http://mirrors.ustc.edu.cn/debian jessie main contrib non-free' >> /etc/apt/sources.list \ - # && echo 'deb http://mirrors.ustc.edu.cn/debian jessie-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ - # && echo 'deb-src http://mirrors.ustc.edu.cn/debian jessie-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ - # && echo 'deb http://mirrors.ustc.edu.cn/debian jessie-updates main contrib non-free' >> /etc/apt/sources.list \ - # && echo 'deb-src http://mirrors.ustc.edu.cn/debian jessie-updates main contrib non-free' >> /etc/apt/sources.list \ + # <切换 apt 中国源> + && echo 'deb http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' > /etc/apt/sources.list \ + && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' >> /etc/apt/sources.list \ + && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ + && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ + && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ + && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ + # && apt-get update \ && apt-get install -y --no-install-recommends ca-certificates git \ && mkdir -p /usr/share/nginx/html/ \ @@ -29,8 +31,8 @@ RUN echo "Installing packages ..." \ COPY docker-entrypoint.sh /docker-entrypoint.sh COPY django_check.sh /usr/local/bin/django_check.sh -COPY default.conf /etc/nginx/conf.d/default.conf COPY nginx.conf /etc/nginx/nginx.conf +COPY default.conf /etc/nginx/conf.d/default.conf COPY start_nginx.sh /usr/local/bin/start_nginx.sh COPY update_website /usr/local/bin/update_website diff --git a/nginx/default.conf b/nginx/default.conf index dcbb511..03d845e 100644 --- a/nginx/default.conf +++ b/nginx/default.conf @@ -21,12 +21,12 @@ server { } location /aqi-static { - alias /usr/share/nginx/html/static; + alias AQI_STATIC_FOLDER; } location /web { proxy_set_header Host $host:$server_port; - alias /usr/share/nginx/html/aqi-visualization/web; + alias /usr/share/nginx/html/aqi-visualization; } # redirect server error pages to the static page /50x.html diff --git a/nginx/docker-entrypoint.sh b/nginx/docker-entrypoint.sh index 8d17d48..a94e7ed 100644 --- a/nginx/docker-entrypoint.sh +++ b/nginx/docker-entrypoint.sh @@ -7,6 +7,8 @@ else echo "Directory '/var/aqi/logs/nginx' has already existed." fi +sed -i "s?AQI_STATIC_FOLDER?/usr/share/nginx/html/static/${WEB_FOLDER}?" /etc/nginx/conf.d/default.conf \ + /usr/local/bin/django_check.sh /usr/local/bin/start_nginx.sh diff --git a/postgis/Dockerfile b/postgis/Dockerfile index fe46878..e67b377 100644 --- a/postgis/Dockerfile +++ b/postgis/Dockerfile @@ -1,13 +1,22 @@ FROM postgres:9.6 LABEL maintainer="CS-Tao " version="1.0.0" -ENV PG_DUMPED_DATA_DEFAULT_URL https://github.com/CS-Tao/AQI-Docker/releases/download/v1.0.0/aqidb.sql +ENV PG_DUMPED_DATA_DEFAULT_URL https://github.com/RS-GIS-Geeks/AQI-Docker/releases/download/v1.0.0/aqidb.sql ENV POSRGRESQL_MAJOR 9.6 ENV POSTGIS_MAJOR 2.4 -RUN apt-get update \ +RUN echo "Installing packages ..." \ + # <切换 apt 中国源> + && echo 'deb http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' > /etc/apt/sources.list \ + && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' >> /etc/apt/sources.list \ + && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ + && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ + && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ + && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ + # + && apt-get update \ && apt-get install -y --no-install-recommends \ postgis \ postgresql-${POSRGRESQL_MAJOR}-postgis-${POSTGIS_MAJOR} \ diff --git a/postgis/_import_data b/postgis/_import_data index e2c72c1..274b631 100644 --- a/postgis/_import_data +++ b/postgis/_import_data @@ -4,7 +4,7 @@ set -e PG_DUMPED_DATA_URL=${PG_DUMPED_DATA_DEFAULT_URL} if [ ! "$( psql -tAc "SELECT 1 FROM pg_database WHERE datname='${POSTGRES_DB}'" )" = '1' ]; then - psql -tc "CREATE DATABASE ${POSTGRES_DB} WITH OWNER = ${POSTGRES_USER}" + psql -tc "CREATE DATABASE ${POSTGRES_DB} WITH OWNER = ${POSTGRES_USER_FOR_DB}" fi if [ ! -d "/usr/local/bin" ];then @@ -27,6 +27,6 @@ wget -O "/usr/local/bin/aqidb.sql" ${PG_DUMPED_DATA_URL} sed -i "1s/^/\\\connect ${POSTGRES_DB}\n/" /usr/local/bin/aqidb.sql chmod 755 /usr/local/bin/aqidb.sql echo "Import data ..." -psql -v aqidb_user=${POSTGRES_USER} -f /usr/local/bin/aqidb.sql +psql -v aqidb_user=${POSTGRES_USER_FOR_DB} -f /usr/local/bin/aqidb.sql rm -f /usr/local/bin/aqidb.sql echo "Data imported into ${POSTGRES_DB}" diff --git a/postgis/create_role.sh b/postgis/create_role.sh index f13f7ed..482f140 100644 --- a/postgis/create_role.sh +++ b/postgis/create_role.sh @@ -1,14 +1,14 @@ #!/bin/bash set -e -psql -tc "SELECT * FROM pg_roles WHERE rolname='${POSTGRES_USER}'" | grep -q 1 || psql -tc "CREATE USER ${POSTGRES_USER} WITH PASSWORD '${POSTGRES_PASSWD}'"; +psql -tc "SELECT * FROM pg_roles WHERE rolname='${POSTGRES_USER_FOR_DB}'" | grep -q 1 || psql -tc "CREATE USER ${POSTGRES_USER_FOR_DB} WITH PASSWORD '${POSTGRES_PASSWD_FOR_USER}'"; psql <<- EOSQL - ALTER USER ${POSTGRES_USER} WITH PASSWORD '${POSTGRES_PASSWD}'; + ALTER USER ${POSTGRES_USER_FOR_DB} WITH PASSWORD '${POSTGRES_PASSWD_FOR_USER}'; ALTER USER postgres WITH PASSWORD '${POSTGRES_PASSWORD}'; - ALTER USER ${POSTGRES_USER} WITH VALID UNTIL 'infinity'; + ALTER USER ${POSTGRES_USER_FOR_DB} WITH VALID UNTIL 'infinity'; EOSQL -echo "Created user ${POSTGRES_USER}" +echo "Created user ${POSTGRES_USER_FOR_DB}" diff --git a/postgis/import_data b/postgis/import_data index 8777e69..7a1ca97 100644 --- a/postgis/import_data +++ b/postgis/import_data @@ -1,10 +1,10 @@ #!/bin/bash set -e +echo "Update packages..." apt-get update +echo "Install required packages..." apt-get install -y --no-install-recommends ca-certificates wget - su - postgres --preserve-environment /usr/local/bin/_import_data $@ - apt-get purge -y --auto-remove wget ca-certificates rm -rf /var/lib/apt/lists/* diff --git a/postgis/init_db.sh b/postgis/init_db.sh index 2813266..08d8ca9 100644 --- a/postgis/init_db.sh +++ b/postgis/init_db.sh @@ -4,5 +4,5 @@ set -e if [ "$( psql -tAc "SELECT 1 FROM pg_database WHERE datname='${POSTGRES_DB}'" )" = '1' ]; then echo "Database ${POSTGRES_DB} has already existed." else - psql -tc "CREATE DATABASE ${POSTGRES_DB} WITH OWNER = ${POSTGRES_USER}" + psql -tc "CREATE DATABASE ${POSTGRES_DB} WITH OWNER = ${POSTGRES_USER_FOR_DB}" fi From 3a589307a6c768518984432c3990b72857af8c9b Mon Sep 17 00:00:00 2001 From: CS-Tao Date: Thu, 13 Sep 2018 22:25:33 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20travis-ci=20?= =?UTF-8?q?=E6=8C=81=E7=BB=AD=E9=83=A8=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis-ci/deploy | 5 +++++ .travis.yml | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 .travis-ci/deploy create mode 100644 .travis.yml diff --git a/.travis-ci/deploy b/.travis-ci/deploy new file mode 100644 index 0000000..17612f1 --- /dev/null +++ b/.travis-ci/deploy @@ -0,0 +1,5 @@ +#!/bin/bash +echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin +docker-compose push postgis +docker-compose push django +docker-compose push nginx diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2064a28 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,29 @@ +sudo: required + +language: ruby + +services: + - docker + +env: + - DOCKER_COMPOSE_VERSION=1.21.1 + +before_install: + - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin + - sudo rm /usr/local/bin/docker-compose + - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose + - chmod +x docker-compose + - sudo mv docker-compose /usr/local/bin + +install: + - docker-compose build + +script: + - docker-compose up -d + +deploy: + provider: script + script: bash .travis-ci/deploy + on: + branch: + - master From 346bd67d1fbeecd114032ab8045265b2c2171e6d Mon Sep 17 00:00:00 2001 From: CS-Tao <990296951@qq.com> Date: Thu, 13 Sep 2018 23:01:00 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=20appveyor=20=E6=8C=81?= =?UTF-8?q?=E7=BB=AD=E9=9B=86=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .appveyor/test | 18 ------------------ appveyor.yml | 26 -------------------------- 2 files changed, 44 deletions(-) delete mode 100644 .appveyor/test delete mode 100644 appveyor.yml diff --git a/.appveyor/test b/.appveyor/test deleted file mode 100644 index b7c81c2..0000000 --- a/.appveyor/test +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# usage: test http://127.0.0.1:2001/web/#/dashboard - -set -e - -if [ ! x$1 == x ]; then - if [ `curl -I -s $1|head -1|cut -d" " -f2` == "200" ]; then - echo -e "\033[32m√\033[0m\t1 test(s) passed." - exit 0 - else - echo -e "\033[31mㄨ\033[0m\t1 test(s) failed." - exit 1 - fi -else - echo -e "\033[31mErr: No test url specified.\033[0m" - exit 2 -fi diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 4e89143..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,26 +0,0 @@ - - -image: ubuntu - -services: - - docker - -init: - - curl -L https://github.com/docker/compose/releases/download/1.21.1/docker-compose-`uname -s`-`uname -m` > docker-compose - - chmod +x docker-compose - - sudo mv docker-compose /usr/local/bin - -install: - - docker-compose build - -build_script: - - docker-compose up -d - - sleep 10s - -before_test: - - docker exec -i $(docker ps -a | grep django | cut -c1-12) python manage.py migrate - - sleep 3s - -test_script: - - chmod +x .appveyor/test - - .appveyor/test http://127.0.0.1:2101/web/#/ From 528d9ff131ef7cceea10ab4d362748343c8382bb Mon Sep 17 00:00:00 2001 From: CS-Tao <990296951@qq.com> Date: Thu, 13 Sep 2018 23:29:39 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/README.md b/README.md index 03178d0..fc5ce37 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,98 @@ + +[![Build Status](https://travis-ci.com/RS-GIS-Geeks/AQI-Docker.svg?branch=master)](https://travis-ci.com/RS-GIS-Geeks/AQI-Docker) +[![license](https://img.shields.io/badge/license-MIT-yellow.svg)](https://opensource.org/licenses/MIT) + # 空气污染数据可视化系统 - Docker 部署方案 > AQI Data Visualization System - Deploy Solution by Docker-compose + +## 项目结构 + +- 项目地址:[https://github.com/RS-GIS-Geeks/AQI-Docker](https://github.com/RS-GIS-Geeks/AQI-Docker) + +- 镜像仓库: + - [cstao/aqi-postgis](https://store.docker.com/community/images/cstao/aqi-postgis) + - [cstao/aqi-django](https://store.docker.com/community/images/cstao/aqi-django) + - [cstao/aqi-nginx](https://store.docker.com/community/images/cstao/aqi-nginx) + +## 编排命令 + +- 构建镜像 + + 本地构建: + ```bash + docker-compose build + ``` + 或者从 [store.docker.com](https://store.docker.com/profiles/cstao) 拉取: + ```bash + docker-compose pull + ``` + +- 创建并启动服务 + + 同步: + ```bash + docker-compose up + ``` + 异步: + ```bash + docker-compose up -d + ``` + +- 导入数据到 postgresql 数据库 + + 利用 `docker ps` 命令得到 `postgis` 容器的 `ID`,然后在 `postgis` 容器中执行导入数据的命令(`pg_dumped_data-url` 应该替换为自定义的 sql 数据的 URL,如果不指定该参数,则默认使用 `https://github.com/RS-GIS-Geeks/AQI-Docker/releases/download/v1.0.0/aqidb.sql` 作为源数据): + ```bash + docker exec -i import_data [pg_dumped_data-url] + ``` + +- 更新后台服务 + + ```bash + docker exec -i update_django + ``` + +- 更新网站 + + ```bash + docker exec -i update_website + ``` + +- 启动/停止/重启服务 + + 启动: + ```bash + docker-compose start + ``` + 停止: + ```bash + docker-compose stop + ``` + 重启: + ```bash + docker-compose restart + ``` + +- 暂停/恢复服务 + + 暂停: + ```bash + docker-compose pause + ``` + 恢复: + ```bash + docker-compose unpause + ``` + +- 停止并移除由 `docker-compose.yml` 定义的服务容器和网络 + ```bash + docker-compose down [--rmi |] [-v|--volume] + ``` + + - 添加 `--rmi type` 参数可以移除镜像,`tpye` 可以为 `all` 或 `local`,`all` 表示移除所有镜像,`local` 表示只移除没有定义标签的镜像 + - 添加 `-v` 或 `--volume` 参数可以移除所有在 `docker-compose.yml` 中定义的数据卷 + +## Maintainer + + | [
CS-Tao](https://github.com/CS-Tao) | + | :---: | From 05e20ad218afcb318f38609b0f8231973d542919 Mon Sep 17 00:00:00 2001 From: CS-Tao <990296951@qq.com> Date: Fri, 14 Sep 2018 00:04:27 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E5=8F=96=E6=B6=88=E5=9B=BD=E5=86=85?= =?UTF-8?q?=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- django/Dockerfile | 23 ++++++++++++----------- nginx/Dockerfile | 12 ++++++------ postgis/Dockerfile | 12 ++++++------ 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/django/Dockerfile b/django/Dockerfile index 5054802..ca12785 100644 --- a/django/Dockerfile +++ b/django/Dockerfile @@ -8,12 +8,12 @@ ENV DJANGO_REPO_BRANCH docker RUN echo "Installing packages ..." \ # <切换 apt 中国源> - && echo 'deb http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' > /etc/apt/sources.list \ - && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' >> /etc/apt/sources.list \ - && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ - && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ - && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ - && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ + # && echo 'deb http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' > /etc/apt/sources.list \ + # && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' >> /etc/apt/sources.list \ + # && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ + # && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ + # && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ + # && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ # && apt-get update \ && apt-get install -y --no-install-recommends libgdal-dev git \ @@ -21,11 +21,12 @@ RUN echo "Installing packages ..." \ && git clone ${DJANGO_REPO_URL} -b ${DJANGO_REPO_BRANCH} AQI-Background \ && cd AQI-Background \ && ls -a -l \ - && mkdir -p ~/.pip/ \ - && echo '[global]' > ~/.pip/pip.conf \ - && echo 'index-url = https://pypi.tuna.tsinghua.edu.cn/simple' >> ~/.pip/pip.conf \ - && echo '[install]' >> ~/.pip/pip.conf \ - && echo 'trusted-host = pypi.tuna.tsinghua.edu.cn' >> ~/.pip/pip.conf \ + # <切换 pip 中国源> + # && mkdir -p ~/.pip/ \ + # && echo '[global]' > ~/.pip/pip.conf \ + # && echo 'index-url = https://pypi.tuna.tsinghua.edu.cn/simple' >> ~/.pip/pip.conf \ + # && echo '[install]' >> ~/.pip/pip.conf \ + # && echo 'trusted-host = pypi.tuna.tsinghua.edu.cn' >> ~/.pip/pip.conf \ # && pip install -r requirements.txt \ && apt-get purge -y --auto-remove git \ diff --git a/nginx/Dockerfile b/nginx/Dockerfile index b3dabcf..9e48002 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -11,12 +11,12 @@ ENV WEB_NEW_SRC_URL ../ RUN echo "Installing packages ..." \ # <切换 apt 中国源> - && echo 'deb http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' > /etc/apt/sources.list \ - && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' >> /etc/apt/sources.list \ - && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ - && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ - && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ - && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ + # && echo 'deb http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' > /etc/apt/sources.list \ + # && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' >> /etc/apt/sources.list \ + # && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ + # && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ + # && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ + # && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ # && apt-get update \ && apt-get install -y --no-install-recommends ca-certificates git \ diff --git a/postgis/Dockerfile b/postgis/Dockerfile index e67b377..e33353c 100644 --- a/postgis/Dockerfile +++ b/postgis/Dockerfile @@ -9,12 +9,12 @@ ENV POSTGIS_MAJOR 2.4 RUN echo "Installing packages ..." \ # <切换 apt 中国源> - && echo 'deb http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' > /etc/apt/sources.list \ - && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' >> /etc/apt/sources.list \ - && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ - && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ - && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ - && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ + # && echo 'deb http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' > /etc/apt/sources.list \ + # && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch main contrib non-free' >> /etc/apt/sources.list \ + # && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ + # && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-proposed-updates main contrib non-free' >> /etc/apt/sources.list \ + # && echo 'deb http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ + # && echo 'deb-src http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free' >> /etc/apt/sources.list \ # && apt-get update \ && apt-get install -y --no-install-recommends \ From d5edfd2730f8a21f97ed5b4b088ac56f0543a030 Mon Sep 17 00:00:00 2001 From: CS-Tao <990296951@qq.com> Date: Fri, 14 Sep 2018 01:12:00 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20nginx=20=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx/default.conf | 4 ++-- nginx/docker-entrypoint.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nginx/default.conf b/nginx/default.conf index 03d845e..acab18c 100644 --- a/nginx/default.conf +++ b/nginx/default.conf @@ -21,12 +21,12 @@ server { } location /aqi-static { - alias AQI_STATIC_FOLDER; + alias /usr/share/nginx/html/static; } location /web { proxy_set_header Host $host:$server_port; - alias /usr/share/nginx/html/aqi-visualization; + alias AQI_STATIC_FOLDER; } # redirect server error pages to the static page /50x.html diff --git a/nginx/docker-entrypoint.sh b/nginx/docker-entrypoint.sh index a94e7ed..344e630 100644 --- a/nginx/docker-entrypoint.sh +++ b/nginx/docker-entrypoint.sh @@ -7,7 +7,7 @@ else echo "Directory '/var/aqi/logs/nginx' has already existed." fi -sed -i "s?AQI_STATIC_FOLDER?/usr/share/nginx/html/static/${WEB_FOLDER}?" /etc/nginx/conf.d/default.conf \ +sed -i "s?AQI_STATIC_FOLDER?/usr/share/nginx/html/aqi-visualization/${WEB_FOLDER}?" /etc/nginx/conf.d/default.conf \ /usr/local/bin/django_check.sh /usr/local/bin/start_nginx.sh From 31499e8996373121109fc7bb2bf6e8b9c90b3d20 Mon Sep 17 00:00:00 2001 From: CS-Tao <990296951@qq.com> Date: Fri, 14 Sep 2018 01:53:57 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=20pg=20=E7=9A=84?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E7=94=A8=E6=88=B7=E4=B8=BA=E8=B6=85=E7=BA=A7?= =?UTF-8?q?=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- postgis/create_role.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/postgis/create_role.sh b/postgis/create_role.sh index 482f140..55559fc 100644 --- a/postgis/create_role.sh +++ b/postgis/create_role.sh @@ -8,6 +8,7 @@ psql <<- EOSQL ALTER USER ${POSTGRES_USER_FOR_DB} WITH PASSWORD '${POSTGRES_PASSWD_FOR_USER}'; ALTER USER postgres WITH PASSWORD '${POSTGRES_PASSWORD}'; ALTER USER ${POSTGRES_USER_FOR_DB} WITH VALID UNTIL 'infinity'; + ALTER USER ${POSTGRES_USER_FOR_DB} WITH SUPERUSER; EOSQL From 8fbe1d2f288e84f5c544cfde1780902bc3d2fc4b Mon Sep 17 00:00:00 2001 From: CS-Tao <990296951@qq.com> Date: Fri, 14 Sep 2018 02:09:56 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=A1=A8=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- django/docker-uwsgi-entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django/docker-uwsgi-entrypoint.sh b/django/docker-uwsgi-entrypoint.sh index 0eea249..a271eb4 100644 --- a/django/docker-uwsgi-entrypoint.sh +++ b/django/docker-uwsgi-entrypoint.sh @@ -35,7 +35,7 @@ EOF rm -rf /opt/aqidjango/static/* -# python manage.py migrate +python manage.py migrate python manage.py collectstatic From 0ccc64daa0649155632a7b5c00587e406315fcfd Mon Sep 17 00:00:00 2001 From: CS-Tao <990296951@qq.com> Date: Fri, 14 Sep 2018 12:13:20 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E7=BD=91=E9=A1=B5?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx/Dockerfile | 9 +++++---- nginx/default.conf | 2 +- nginx/docker-entrypoint.sh | 3 ++- nginx/update_website | 6 +++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/nginx/Dockerfile b/nginx/Dockerfile index 9e48002..bc4b200 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -5,8 +5,9 @@ ENV TZ UTC ENV LANG C.UTF-8 ENV WEB_REPO_URL https://github.com/CS-Tao/AQI-Visualization.git ENV WEB_REPO_BRANCH gh-pages -ENV WEB_FOLDER ./ -ENV WEB_OLD_SRC_URL http://localhost:2002 +ENV WEB_FOLDER web +ENV MAIN_WEB_FOLDER ./ +ENV WEB_OLD_SRC_URL http://localhost:2101 ENV WEB_NEW_SRC_URL ../ RUN echo "Installing packages ..." \ @@ -22,8 +23,8 @@ RUN echo "Installing packages ..." \ && apt-get install -y --no-install-recommends ca-certificates git \ && mkdir -p /usr/share/nginx/html/ \ && cd /usr/share/nginx/html/ \ - && git clone ${WEB_REPO_URL} -b ${WEB_REPO_BRANCH} aqi-visualization \ - && cd aqi-visualization/${WEB_FOLDER} \ + && git clone ${WEB_REPO_URL} -b ${WEB_REPO_BRANCH} ${WEB_FOLDER} \ + && cd ${WEB_FOLDER}/${MAIN_WEB_FOLDER} \ && sed -i "s?baseURL:\"${WEB_OLD_SRC_URL}\"?baseURL:\"${WEB_NEW_SRC_URL}\"?" web.js \ && ls -a -l \ && apt-get purge -y --auto-remove ca-certificates git \ diff --git a/nginx/default.conf b/nginx/default.conf index acab18c..23f344b 100644 --- a/nginx/default.conf +++ b/nginx/default.conf @@ -9,7 +9,7 @@ server { charset utf-8; - root /usr/share/nginx/html/aqi-visualization; + root MIAN_WEB_FOLDER; access_log /var/aqi/logs/nginx/aqi.access.log; error_log /var/aqi/logs/nginx/aqi.error.log; diff --git a/nginx/docker-entrypoint.sh b/nginx/docker-entrypoint.sh index 344e630..ba5f15e 100644 --- a/nginx/docker-entrypoint.sh +++ b/nginx/docker-entrypoint.sh @@ -7,7 +7,8 @@ else echo "Directory '/var/aqi/logs/nginx' has already existed." fi -sed -i "s?AQI_STATIC_FOLDER?/usr/share/nginx/html/aqi-visualization/${WEB_FOLDER}?" /etc/nginx/conf.d/default.conf \ +sed -i "s?AQI_STATIC_FOLDER?/usr/share/nginx/html/${WEB_FOLDER}/${MAIN_WEB_FOLDER}?" /etc/nginx/conf.d/default.conf \ +sed -i "s?MIAN_WEB_FOLDER?/usr/share/nginx/html/${WEB_FOLDER}?" /etc/nginx/conf.d/default.conf \ /usr/local/bin/django_check.sh /usr/local/bin/start_nginx.sh diff --git a/nginx/update_website b/nginx/update_website index 58e308d..566ec1f 100644 --- a/nginx/update_website +++ b/nginx/update_website @@ -4,9 +4,9 @@ set -e apt-get update apt-get install -y --no-install-recommends ca-certificates git cd /usr/share/nginx/html/ -rm -rf aqi-visualization/ -git clone ${WEB_REPO_URL} -b ${WEB_REPO_BRANCH} aqi-visualization -cd aqi-visualization/${WEB_FOLDER} +rm -rf ${WEB_FOLDER} +git clone ${WEB_REPO_URL} -b ${WEB_REPO_BRANCH} ${WEB_FOLDER} +cd ${WEB_FOLDER}/${MAIN_WEB_FOLDER} sed -i "s?baseURL:\"${WEB_OLD_SRC_URL}\"?baseURL:\"${WEB_NEW_SRC_URL}\"?" web.js ls -a -l apt-get purge -y --auto-remove ca-certificates git From 1250e5940881c63284547b08c829de0b012872be Mon Sep 17 00:00:00 2001 From: CS-Tao <990296951@qq.com> Date: Fri, 14 Sep 2018 12:49:37 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx/docker-entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nginx/docker-entrypoint.sh b/nginx/docker-entrypoint.sh index ba5f15e..b0399b8 100644 --- a/nginx/docker-entrypoint.sh +++ b/nginx/docker-entrypoint.sh @@ -7,8 +7,8 @@ else echo "Directory '/var/aqi/logs/nginx' has already existed." fi -sed -i "s?AQI_STATIC_FOLDER?/usr/share/nginx/html/${WEB_FOLDER}/${MAIN_WEB_FOLDER}?" /etc/nginx/conf.d/default.conf \ -sed -i "s?MIAN_WEB_FOLDER?/usr/share/nginx/html/${WEB_FOLDER}?" /etc/nginx/conf.d/default.conf \ +sed -i "s?AQI_STATIC_FOLDER?/usr/share/nginx/html/${WEB_FOLDER}/${MAIN_WEB_FOLDER}?" /etc/nginx/conf.d/default.conf +sed -i "s?MIAN_WEB_FOLDER?/usr/share/nginx/html/${WEB_FOLDER}?" /etc/nginx/conf.d/default.conf /usr/local/bin/django_check.sh /usr/local/bin/start_nginx.sh From 8a942cf81e3eab98e71d0f62afc088287099fdcf Mon Sep 17 00:00:00 2001 From: CS-Tao <990296951@qq.com> Date: Fri, 14 Sep 2018 13:09:28 +0800 Subject: [PATCH 12/14] =?UTF-8?q?Django=20=E5=AE=B9=E5=99=A8=E7=9D=A1?= =?UTF-8?q?=E7=9C=A0=205s=20=E4=BB=A5=E7=AD=89=E5=BE=85=20Postgis=20?= =?UTF-8?q?=E5=AE=B9=E5=99=A8=E5=AE=8C=E5=85=A8=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- django/docker-uwsgi-entrypoint.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/django/docker-uwsgi-entrypoint.sh b/django/docker-uwsgi-entrypoint.sh index a271eb4..6275d3c 100644 --- a/django/docker-uwsgi-entrypoint.sh +++ b/django/docker-uwsgi-entrypoint.sh @@ -35,10 +35,12 @@ EOF rm -rf /opt/aqidjango/static/* -python manage.py migrate - python manage.py collectstatic +sleep 5 + +python manage.py migrate + # python manage.py runserver 0.0.0.0:8080 exec "$@"; From fa0c5493098a937e2c7a80761f43d6ab187d8977 Mon Sep 17 00:00:00 2001 From: CS-Tao <990296951@qq.com> Date: Sat, 15 Sep 2018 16:27:49 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=E6=98=BE=E7=A4=BA=20Django=20=E7=9A=84?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- django/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/django/Dockerfile b/django/Dockerfile index ca12785..6ca94cc 100644 --- a/django/Dockerfile +++ b/django/Dockerfile @@ -20,6 +20,7 @@ RUN echo "Installing packages ..." \ && cd /opt \ && git clone ${DJANGO_REPO_URL} -b ${DJANGO_REPO_BRANCH} AQI-Background \ && cd AQI-Background \ + && git log -n1 \ && ls -a -l \ # <切换 pip 中国源> # && mkdir -p ~/.pip/ \ From 0b571a6fa77769370a9ed509fb7464fb45610898 Mon Sep 17 00:00:00 2001 From: CS-Tao <990296951@qq.com> Date: Sat, 15 Sep 2018 19:10:48 +0800 Subject: [PATCH 14/14] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- django/docker-uwsgi-entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/django/docker-uwsgi-entrypoint.sh b/django/docker-uwsgi-entrypoint.sh index 6275d3c..1338037 100644 --- a/django/docker-uwsgi-entrypoint.sh +++ b/django/docker-uwsgi-entrypoint.sh @@ -39,6 +39,7 @@ python manage.py collectstatic sleep 5 +python manage.py makemigrations python manage.py migrate # python manage.py runserver 0.0.0.0:8080