Initial commit

This commit is contained in:
王思川 2021-04-12 00:21:07 +08:00
commit 6835dd4ded
8 changed files with 102 additions and 0 deletions

14
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,14 @@
stages:
- deploy
job:
stage: deploy
script:
- docker stop mail_auth
- docker rm mail_auth
- docker build -t mail_auth
- docker run -d -p 11002:11002 --name mail_auth mail_auth
only:
- master
tags:
- mail_auth

6
Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM python:3.8
WORKDIR /usr/src/app/mail_auth
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.mirrors.ustc.edu.cn/simple
COPY . .
CMD ["gunicorn", "app:app", "-c", "./gunicorn.conf.py"]

37
app.py Normal file
View File

@ -0,0 +1,37 @@
from flask import Flask, request
from flask_mail import Mail, Message
from threading import Thread
app = Flask(__name__)
app.config['MAIL_SERVER'] = 'smtp.163.com'
app.config['MAIL_PORT'] = 25
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = 'fecribd@163.com'
app.config['MAIL_PASSWORD'] = 'NSBFBXRGKBKLUMMG'
mail = Mail(app)
def send_async_email(mail_app, msg):
with mail_app.app_context():
mail.send(msg)
@app.route('/send_mail', methods=['POST'])
def send_mail():
title = request.json['title']
sender = request.json['sender']
recipients = request.json['recipients']
msg_body = request.json['msg_body']
msg = Message(title, sender=sender, recipients=recipients)
msg.body = msg_body
thread = Thread(target=send_async_email, args=[app, msg])
thread.start()
if __name__ == '__main__':
app.run()

0
config/__init__.py Normal file
View File

4
config/project_config.py Normal file
View File

@ -0,0 +1,4 @@
PROJECT_SUBNET = ''
PROJECT_SUBNET_IP = ''
PROJECT_PORT = 11002
PROJECT_NAME = 'mail_auth'

31
config_writer.py Normal file
View File

@ -0,0 +1,31 @@
from config.project_config import PROJECT_NAME, PROJECT_SUBNET, PROJECT_PORT
# 重写gitlab配置文件
def write_gitlab_config():
with open('.gitlab-ci.yml') as f:
content = f.read()
content = content.replace('PROJECT_NAME', PROJECT_NAME)
content = content.replace('PROJECT_PORT', str(PROJECT_PORT))
if PROJECT_SUBNET != '':
content = content.replace('PROJECT_SUBNET', PROJECT_SUBNET)
f.close()
with open('.gitlab-ci.yml', 'w') as f:
f.write(content)
f.close()
# 重写docker配置文件
def write_docker_config():
with open('Dockerfile') as f:
content = f.read()
content = content.replace('PROJECT_NAME', PROJECT_NAME)
f.close()
with open('Dockerfile', 'w') as f:
f.write(content)
f.close()
if __name__ == '__main__':
write_gitlab_config()
write_docker_config()

6
gunicorn.conf.py Normal file
View File

@ -0,0 +1,6 @@
# 并行工作进程数
workers = 4
# 监听内网端口10001
bind = '0.0.0.0:10001'
# 工作模式协程
worker_class = 'gevent'

4
requirements.txt Normal file
View File

@ -0,0 +1,4 @@
flask~=1.1.2
gunicorn
gevent
flask_mail