[fix]修复nignx反向代理后无法获取用户真实ip的bug #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy DRF Application | |
| on: | |
| push: | |
| branches: | |
| - dev | |
| paths-ignore: | |
| - 'readme.md' | |
| jobs: | |
| build_and_deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 检出代码 | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| # 安装 docker-compose | |
| - name: Install Docker Compose | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y docker-compose | |
| # 构建 Docker 镜像 | |
| - name: Build Docker image | |
| run: docker-compose build | |
| # 检查镜像是否能成功启动一个容器 | |
| - name: Run Docker container | |
| run: docker-compose up -d | |
| # 检查容器状态 | |
| - name: Check container status | |
| id: container_status | |
| run: | | |
| CONTAINER_NAME=$(docker-compose ps -q | head -n 1) | |
| if [ -z "$CONTAINER_NAME" ]; then | |
| echo "No containers found, failing the step." | |
| exit 1 | |
| fi | |
| STATUS=$(docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME") | |
| if [ "$STATUS" != "true" ]; then | |
| echo "Container is not running, failing the step." | |
| exit 1 | |
| fi | |
| echo "Container is running successfully." | |
| # 登录 Docker Hub | |
| - name: Docker login | |
| if: success() | |
| run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u "${{ vars.DOCKER_HUB_USERNAME }}" --password-stdin | |
| # 推送镜像到 Docker Hub | |
| - name: Push Docker image to Docker Hub | |
| if: success() | |
| run: docker push immrk/pure-drf-api:latest | |
| # 更新开发环境镜像并重启容器 | |
| - name: Deploy to remote server | |
| if: success() | |
| run: sshpass -p ${{ secrets.HOST_USER_PASSWORD }} ssh -o StrictHostKeyChecking=no ${{ vars.HOST_USER_NAME }}@${{ vars.HOST}} "cd ${{ vars.COMPOSE_FILE_PATH }} && docker-compose pull && docker-compose down && docker-compose up -d" |