更新 .gitea/workflows/build-dev.yaml
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
name: paipai-h5-dev
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
driver-opts: |
|
||||
network=host
|
||||
buildkitd-flags: |
|
||||
--allow-insecure-entitlement security.insecure
|
||||
|
||||
- name: Log in to container registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: code.paipai.life
|
||||
username: ${{ secrets.DEV_DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DEV_DOCKER_PASSWORD }}
|
||||
insecure: true
|
||||
|
||||
- name: Extract metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: code.paipai.life/backend/rn-outside
|
||||
tags: |
|
||||
type=raw,value=latest
|
||||
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
docker build -t code.paipai.life/backend/rn-outside:latest .
|
||||
|
||||
- name: Push Docker image
|
||||
run: |
|
||||
docker push code.paipai.life/backend/rn-outside:latest
|
||||
env:
|
||||
DOCKER_CONTENT_TRUST: 0
|
||||
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-and-push
|
||||
environment: test
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Copy files and deploy via SSH
|
||||
uses: appleboy/scp-action@v0.1.3
|
||||
with:
|
||||
host: ${{ secrets.DEV_SERVER_HOST }}
|
||||
username: ${{ secrets.DEV_SERVER_USERNAME }}
|
||||
password: ${{ secrets.DEV_SERVER_PASSWORD }}
|
||||
port: 22
|
||||
source: "docker-compose-dev.yaml"
|
||||
target: "/home/paipai/data/rn-outside"
|
||||
override: true
|
||||
|
||||
- name: Deploy with Docker Compose
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.DEV_SERVER_HOST }}
|
||||
username: ${{ secrets.DEV_SERVER_USERNAME }}
|
||||
password: ${{ secrets.DEV_SERVER_PASSWORD }}
|
||||
port: 22
|
||||
script: |
|
||||
# 切换到项目目录
|
||||
cd /home/paipai/data/rn-outside
|
||||
|
||||
# 拉取最新镜像
|
||||
docker pull code.paipai.life/backend/rn-outside:latest
|
||||
|
||||
# 使用 docker-compose 部署
|
||||
docker compose -f docker-compose-dev.yaml down
|
||||
docker compose -f docker-compose-dev.yaml up -d
|
||||
|
||||
echo "Deployment completed successfully!"
|
||||
|
||||
cleanup:
|
||||
runs-on: ubuntu-latest
|
||||
needs: deploy
|
||||
if: always()
|
||||
|
||||
steps:
|
||||
- name: Clean up Docker resources on server
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.DEV_SERVER_HOST }}
|
||||
username: ${{ secrets.DEV_SERVER_USERNAME }}
|
||||
password: ${{ secrets.DEV_SERVER_PASSWORD }}
|
||||
port: 22
|
||||
script: |
|
||||
docker image prune -f
|
||||
docker container prune -f
|
||||
docker builder prune -f
|
||||
docker network prune -f
|
||||
echo "Cleanup completed!"
|
||||
|
||||
- name: Clean up GitHub Actions workspace
|
||||
run: |
|
||||
echo "Cleaning up GitHub Actions workspace..."
|
||||
docker system df
|
||||
Reference in New Issue
Block a user