feat: 添加 Docker 容器化部署和 CI/CD 管道
Some checks failed
continuous-integration/drone/push Build was killed

- 创建 Flask 应用程序,展示容器主机名和学生ID环境变量
- 配置 DockerFile 为 Python 环境并安装依赖
- 设置 Drone CI 管道自动构建并推送 Docker 映像到私有注册表
This commit is contained in:
2025-12-16 12:38:04 +08:00
parent e916f83c0d
commit 40735e9e8d
3 changed files with 48 additions and 0 deletions

27
.drone.yml Normal file
View File

@@ -0,0 +1,27 @@
kind: pipeline
type: docker
name: student-build
steps:
- name: docker-build-push
image: plugins/docker
settings:
registry: harbor.seahi.me
repo: harbor.seahi.me/stu/whoami-for-swarm
tags:
- latest
- build-${DRONE_BUILD_NUMBER}
username:
from_secret: harbor_username
password:
from_secret: harbor_password
insecure: true
# 添加构建时间标签
build_args:
- BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
- VCS_REF=${DRONE_COMMIT_SHA:0:8}
trigger:
branch:
- main

5
Dockerfile Normal file
View File

@@ -0,0 +1,5 @@
FROM python:3.9-alpine
RUN pip install flask
COPY app.py /app.py
CMD ["python", "/app.py"]

16
app.py Normal file
View File

@@ -0,0 +1,16 @@
from flask import Flask
import socket
import os
app = Flask(__name__)
@app.route('/')
def hello():
return f"""
容器主机名: {socket.gethostname()}
学号服务: s{os.getenv('STUDENT_ID', '00')}
"""
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)