Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

重新打包镜像,将环境的配置全部转为容器内来操作完成 #21

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 5 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,13 @@
FROM centos:7
# 设置编码
ENV LANG en_US.UTF-8
# 同步时间
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
FROM registry.cn-hangzhou.aliyuncs.com/sourcegarden/python:centos7-3.6

# 1. 安装基本依赖
RUN yum update -y && yum install epel-release -y && yum update -y && yum install wget unzip epel-release nginx xz gcc automake zlib-devel openssl-devel supervisor groupinstall development libxslt-devel libxml2-devel libcurl-devel git -y
#WORKDIR /var/www/

# 2. 准备python
RUN wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz
RUN xz -d Python-3.6.6.tar.xz && tar xvf Python-3.6.6.tar && cd Python-3.6.6 && ./configure && make && make install

# 3. 安装pip依赖
RUN pip3 install --upgrade pip
RUN pip3 install -U git+https://github.com/ss1917/ops_sdk.git

# 4. 复制代码
RUN mkdir -p /var/www/
ADD . /var/www/codo-admin/

# 5. 安装pip依赖
RUN pip3 install -r /var/www/codo-admin/doc/requirements.txt

# 6. 日志
VOLUME /var/log/
RUN pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -r /var/www/codo-admin/requirements.txt

# 7. 准备文件
COPY doc/nginx_ops.conf /etc/nginx/conf.d/default.conf
COPY doc/supervisor_ops.conf /etc/supervisord.conf
COPY docker/nginx_default.conf /etc/nginx/nginx.conf
COPY docker/nginx_ops.conf /etc/nginx/conf.d/codo-admin.conf
COPY docker/supervisor_ops.conf /etc/supervisord.conf

EXPOSE 80
CMD ["/usr/bin/supervisord"]
8 changes: 0 additions & 8 deletions docker-compose.yml

This file was deleted.

64 changes: 64 additions & 0 deletions docker/nginx_default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

include /etc/nginx/mime.types;
default_type application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }

}
8 changes: 4 additions & 4 deletions doc/nginx_ops.conf → docker/nginx_ops.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
upstream codo-admin{
upstream codo-admin-nginx{
server 127.0.0.1:9800;
server 127.0.0.1:9801;
server 127.0.0.1:9802;
Expand All @@ -9,14 +9,14 @@ server
{
listen 80;
server_name mg.opendevops.cn;
access_log /var/log/nginx/codo-admin_access.log;
error_log /var/log/nginx/codo-admin_error.log;
access_log /var/log/nginx/codo-admin-access.log;
error_log /var/log/nginx/codo-admin-error.log;
location / {
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_set_header  Cookie $http_cookie;
proxy_pass http://codo-admin;
proxy_pass http://codo-admin-nginx;
}
}
51 changes: 51 additions & 0 deletions docker/prestart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/sh
cd /var/www/codo-admin/

#管理后端-admin
echo -e "\033[32m [INFO]: 开始修改各项目的配置文件 \033[0m"
sed -i "s#cookie_secret = .*#cookie_secret = '${cookie_secret}'#g" settings.py
sed -i "s#token_secret = .*#token_secret = '${token_secret}'#g" settings.py
sed -i "s#secret_key = .*#secret_key = '${secret_key}'#g" settings.py
DEFAULT_DB_DBNAME='codo_admin'
sed -i "s#DEFAULT_DB_DBHOST = .*#DEFAULT_DB_DBHOST = os.getenv('DEFAULT_DB_DBHOST', '${DEFAULT_DB_DBHOST}')#g" settings.py
sed -i "s#DEFAULT_DB_DBPORT = .*#DEFAULT_DB_DBPORT = os.getenv('DEFAULT_DB_DBPORT', '${DEFAULT_DB_DBPORT}')#g" settings.py
sed -i "s#DEFAULT_DB_DBUSER = .*#DEFAULT_DB_DBUSER = os.getenv('DEFAULT_DB_DBUSER', '${DEFAULT_DB_DBUSER}')#g" settings.py
sed -i "s#DEFAULT_DB_DBPWD = .*#DEFAULT_DB_DBPWD = os.getenv('DEFAULT_DB_DBPWD', '${DEFAULT_DB_DBPWD}')#g" settings.py
sed -i "s#DEFAULT_DB_DBNAME = .*#DEFAULT_DB_DBNAME = os.getenv('DEFAULT_DB_DBNAME', '${DEFAULT_DB_DBNAME}')#g" settings.py
sed -i "s#READONLY_DB_DBHOST = .*#READONLY_DB_DBHOST = os.getenv('READONLY_DB_DBHOST', '${READONLY_DB_DBHOST}')#g" settings.py
sed -i "s#READONLY_DB_DBPORT = .*#READONLY_DB_DBPORT = os.getenv('READONLY_DB_DBPORT', '${READONLY_DB_DBPORT}')#g" settings.py
sed -i "s#READONLY_DB_DBUSER = .*#READONLY_DB_DBUSER = os.getenv('READONLY_DB_DBUSER', '${READONLY_DB_DBUSER}')#g" settings.py
sed -i "s#READONLY_DB_DBPWD = .*#READONLY_DB_DBPWD = os.getenv('READONLY_DB_DBPWD', '${READONLY_DB_DBPWD}')#g" settings.py
sed -i "s#READONLY_DB_DBNAME = .*#READONLY_DB_DBNAME = os.getenv('READONLY_DB_DBNAME', '${DEFAULT_DB_DBNAME}')#g" settings.py
sed -i "s#DEFAULT_REDIS_HOST = .*#DEFAULT_REDIS_HOST = os.getenv('DEFAULT_REDIS_HOST', '${DEFAULT_REDIS_HOST}')#g" settings.py
sed -i "s#DEFAULT_REDIS_PORT = .*#DEFAULT_REDIS_PORT = os.getenv('DEFAULT_REDIS_PORT', '${DEFAULT_REDIS_PORT}')#g" settings.py
sed -i "s#DEFAULT_REDIS_PASSWORD = .*#DEFAULT_REDIS_PASSWORD = os.getenv('DEFAULT_REDIS_PASSWORD', '${DEFAULT_REDIS_PASSWORD}')#g" settings.py
sleep 30

try_num=0

while [[ $try_num -le 100 ]];
do
if $(curl -s ${DEFAULT_DB_DBHOST}:${DEFAULT_DB_DBPORT} > /dev/null);then
python3 db_sync.py
sleep 3
check_admin_user_num=`mycli -h${DEFAULT_DB_DBHOST} -u${DEFAULT_DB_DBUSER} -p${MYSQL_PASSWORD} codo_admin -e "select username from mg_users where username='admin';" | wc -l`
if [ ${check_admin_user_num} -eq 1 ]; then
mycli -h${DEFAULT_DB_DBHOST} -u${DEFAULT_DB_DBUSER} -p${MYSQL_PASSWORD} codo_admin < sql/codo_admin_beta0.3.sql;
else
echo "初始化用户已存在" ;
fi

if [ $? -eq 0 ]; then
echo -e "\033[32m [INFO]: 导入codo-admin用户权限数据完成. \033[0m";
else
echo -e "\033[31m [ERROR]: 导入codo-admin用户权限数据完成失败 \033[0m" && exit -6;
fi

exit 0
else
echo 'wait mysql start to do db_sync.py'
fi
let try_num+=1
sleep 3
done
14 changes: 13 additions & 1 deletion doc/supervisor_ops.conf → docker/supervisor_ops.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@
nodaemon=true

[group:do_admin,]
programs=mg,sub_log
programs=mg-prestart,mg,sub_log

[program:mg-prestart]
command=sh docker/prestart.sh
directory=/var/www/codo-admin
user=root
autostart = true
autorestart=false
redirect_stderr=true
stdout_logfile=/var/log/supervisor/mg-prestart.log
loglevel=info
logfile_maxbytes=10MB
logfile_backups=1

[program:mg]
command=python3 startup.py --service=mg --port=98%(process_num)02d
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions doc/codo_admin_beta0.3.sql → sql/codo_admin_beta0.3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
-- Dumping data for table `mg_app_settings`
--

use codo_admin;

LOCK TABLES `mg_app_settings` WRITE;
/*!40000 ALTER TABLE `mg_app_settings` DISABLE KEYS */;
/*!40000 ALTER TABLE `mg_app_settings` ENABLE KEYS */;
Expand Down