init
This commit is contained in:
commit
59d39de81e
3
.env
Normal file
3
.env
Normal file
@ -0,0 +1,3 @@
|
||||
FLASK_PORT=5000
|
||||
FLASK_HOST=0.0.0.0
|
||||
FLASK_ENV=development
|
||||
29
.github/workflows/docker-build.yml
vendored
Normal file
29
.github/workflows/docker-build.yml
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
name: 打包发布docker镜像
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
build-push:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Login to Docker Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: your-registry.com # 替换为自建 Registry 的地址
|
||||
username: ${{ secrets.DOCKER_USER }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile # 指定 Dockerfile 路径
|
||||
tags: your-registry.com/your-image:latest # 镜像标签(包含 Registry 地址)
|
||||
push: true
|
||||
7
Dockerfile
Normal file
7
Dockerfile
Normal file
@ -0,0 +1,7 @@
|
||||
FROM python:3.10-alpine
|
||||
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
CMD ["python", "main.py"]
|
||||
37
main.py
Normal file
37
main.py
Normal file
@ -0,0 +1,37 @@
|
||||
from flask import Flask, jsonify
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# 加载环境变量
|
||||
load_dotenv()
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def home():
|
||||
return jsonify({
|
||||
"message": "欢迎使用 Flask API",
|
||||
"status": "running",
|
||||
"version": "1.0.0"
|
||||
})
|
||||
|
||||
@app.route('/health')
|
||||
def health_check():
|
||||
return jsonify({
|
||||
"status": "healthy",
|
||||
"timestamp": "2024-03-21"
|
||||
})
|
||||
|
||||
@app.route('/info')
|
||||
def info():
|
||||
return jsonify({
|
||||
"hostname": os.uname().nodename,
|
||||
"python_version": os.sys.version,
|
||||
"environment": os.getenv('FLASK_ENV', 'production'),
|
||||
"port": os.getenv('FLASK_PORT', '5000')
|
||||
})
|
||||
|
||||
if __name__ == '__main__':
|
||||
port = int(os.getenv('FLASK_PORT', 5000))
|
||||
host = os.getenv('FLASK_HOST', '0.0.0.0')
|
||||
app.run(host=host, port=port)
|
||||
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
flask==3.0.2
|
||||
gunicorn==21.2.0
|
||||
python-dotenv==1.0.1
|
||||
Loading…
x
Reference in New Issue
Block a user