Files
market_page/.github/workflows/deploy.yml
Workflow config file is invalid. Please check your config file: EOF
jeremygan2021 fd33201793
All checks were successful
Deploy to Server / deploy (push) Successful in 37s
移动端
2026-02-24 16:09:07 +08:00

102 lines
3.7 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# name: Deploy to Server
# on:
# push:
# branches:
# - main
# jobs:
# build-and-deploy:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Build Docker Images
# run: |
# echo "Building Backend Image..."
# docker build -t market-backend:latest ./backend
# echo "Building Frontend Image..."
# # 注意:这里我们传入了服务器的 IP 地址作为 API URL
# # 如果你的后端端口不是 8000请修改这里
# docker build -t market-frontend:latest \
# --build-arg VITE_API_URL=http://47.101.218.42:8000/api \
# ./frontend
# - name: Save Docker Images
# run: |
# echo "Saving images to tarball..."
# docker save market-backend:latest market-frontend:latest | gzip > market-images.tar.gz
# - name: Generate Production Compose File
# run: |
# # 生成生产环境专用的 docker-compose.prod.yml
# # 1. 使用构建好的镜像 (image) 替代构建指令 (build)
# # 2. 移除代码挂载 (volumes),确保使用镜像内的代码
# cat > docker-compose.prod.yml <<EOF
# services:
# backend:
# image: market-backend:latest
# command: sh -c "python manage.py collectstatic --noinput && python manage.py migrate && gunicorn --bind 0.0.0.0:8000 --access-logfile - --error-logfile - config.wsgi:application"
# ports:
# - "8000:8000"
# environment:
# - DB_NAME=\${DB_NAME:-market}
# - DB_USER=\${DB_USER:-market}
# - DB_PASSWORD=\${DB_PASSWORD:-123market}
# - DB_HOST=\${DB_HOST:-6.6.6.66}
# - DB_PORT=\${DB_PORT:-5432}
# # 如果需要持久化媒体文件,请取消下面的注释并在服务器上创建相应目录
# # volumes:
# # - ./media:/app/media
# frontend:
# image: market-frontend:latest
# ports:
# - "15173:15173"
# environment:
# - VITE_API_URL=http://47.101.218.42:8000/api
# depends_on:
# - backend
# EOF
# - name: Ensure target directory exists
# uses: appleboy/ssh-action@v1.0.3
# with:
# host: 47.101.218.42
# username: ecs-user
# password: 123quant-speed
# script: mkdir -p ~/data/dev/market_page
# - name: Copy files to server
# uses: appleboy/scp-action@v0.1.7
# with:
# host: 47.101.218.42
# username: ecs-user
# password: 123quant-speed
# source: "market-images.tar.gz,docker-compose.prod.yml"
# target: "~/data/dev/market_page"
# - name: Deploy on Server
# uses: appleboy/ssh-action@v1.0.3
# with:
# host: 47.101.218.42
# username: ecs-user
# password: 123quant-speed
# script: |
# cd ~/data/dev/market_page
# echo "1. Loading Docker images (this may take a while)..."
# gunzip -c market-images.tar.gz | sudo docker load
# echo "2. Restarting services..."
# # 使用 -f 指定生产环境配置文件
# echo "123quant-speed" | sudo -S docker compose -f docker-compose.prod.yml down
# echo "123quant-speed" | sudo -S docker compose -f docker-compose.prod.yml up -d
# echo "3. Cleaning up..."
# rm market-images.tar.gz
# echo "Deployment successful!"