t1
Some checks failed
Gitea Actions Demo / build-and-deploy (push) Failing after 3s

This commit is contained in:
changsongdong
2025-11-04 21:07:58 +08:00
parent c74ad94102
commit 5617024619
3 changed files with 52 additions and 2 deletions

View File

@ -15,5 +15,19 @@ jobs:
run: git clone ${{ gitea.server_url }}/${{ gitea.repository }} .
- name: List files
run: ls -la
- name: docker command
run: docker ps -a
- name: Stop running containers
run: |
docker compose down || true
- name: Remove old image
run: |
IMAGE_NAME=$(basename "$PWD")
echo "Removing old image: $IMAGE_NAME"
docker images | grep "$IMAGE_NAME" && docker rmi -f $(docker images "$IMAGE_NAME" -q) || echo "No old image found."
- name: Build new image
run: |
docker build -t $(basename "$PWD"):latest .
- name: Start containers
run: |
docker compose up -d
- name: Show container status
run: docker ps

22
Dockerfile Normal file
View File

@ -0,0 +1,22 @@
# 使用官方轻量级 Python 基础镜像
FROM python:3.10-slim
# 设置工作目录(容器内路径)
WORKDIR /app
# 将项目文件复制到容器中
COPY . /app
# (可选)如果你有 requirements.txt则先复制并安装依赖
RUN if [ -f requirements.txt ]; then \
pip install --no-cache-dir -r requirements.txt; \
fi
# 暴露服务端口(例如 Flask / FastAPI 可监听 8000
EXPOSE 8000
# 设置环境变量(防止 Python 缓存文件)
ENV PYTHONUNBUFFERED=1
# 启动命令
CMD ["python", "main.py"]

View File

@ -0,0 +1,14 @@
version: "3.8"
services:
app:
build: .
container_name: python_app
restart: always
ports:
- "8000:8000"
environment:
- PYTHONUNBUFFERED=1
volumes:
- .:/app
command: python main.py