Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
CS-Tao committed Sep 15, 2018
2 parents 5014d75 + 0b571a6 commit ec3b561
Show file tree
Hide file tree
Showing 19 changed files with 240 additions and 101 deletions.
18 changes: 0 additions & 18 deletions .appveyor/test

This file was deleted.

2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ ENV_POSTGRES_USER=cstao
ENV_POSTGRES_PASSWD=cstao

# 'postgres' 用户的数据库密码
ENV_POSTGRES_PASSWD_ADMIN=0000
ENV_POSTGRES_PASSWD_ADMIN=cstao
95 changes: 95 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <postgis-container-id> import_data [pg_dumped_data-url]
```

- 更新后台服务

```bash
docker exec -i <django-container-id> update_django
```

- 更新网站

```bash
docker exec -i <nginx-container-id> 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 <all>|<local>] [-v|--volume]
```

- 添加 `--rmi type` 参数可以移除镜像,`tpye` 可以为 `all``local``all` 表示移除所有镜像,`local` 表示只移除没有定义标签的镜像
- 添加 `-v``--volume` 参数可以移除所有在 `docker-compose.yml` 中定义的数据卷

## Maintainer

| [<img src="https://avatars2.githubusercontent.com/u/22360632?s=400&u=1e8c0b49ed6ee28a1911f69d29176fd918c54897&v=4" width="100px;"/><br /><sub><b>CS-Tao</b></sub>](https://github.com/CS-Tao) |
| :---: |
26 changes: 0 additions & 26 deletions appveyor.yml

This file was deleted.

24 changes: 20 additions & 4 deletions django/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,42 @@ LABEL maintainer="CS-Tao <[email protected]>" 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 中国源>
&& 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 \
&& git log -n1 \
&& ls -a -l \
# <切换 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 中国源>
&& pip install -r requirements.txt \
&& apt-get purge -y --auto-remove git \
&& rm -rf /var/lib/apt/lists/*

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
Expand Down
1 change: 1 addition & 0 deletions django/gtd_uwsgi.ini → django/aqi_uwsgi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ vacuum = true
enable-threads = true
chmod-socket = 666
logto = /var/aqi/logs/django-uwsgi/aqi_uwsgi.log
py-autoreload = 1
11 changes: 7 additions & 4 deletions django/docker-uwsgi-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,24 @@ 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',
}
}
EOF

rm -rf /opt/aqidjango/static/*

# python manage.py migrate

python manage.py collectstatic

sleep 5

python manage.py makemigrations
python manage.py migrate

# python manage.py runserver 0.0.0.0:8080

exec "$@";
72 changes: 56 additions & 16 deletions django/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)))

Expand All @@ -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',
Expand All @@ -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': [
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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 = (
"*",
)
12 changes: 12 additions & 0 deletions django/update_django
Original file line number Diff line number Diff line change
@@ -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"
Loading

0 comments on commit ec3b561

Please sign in to comment.