Merge branch 'main' of http://47.109.137.67:9091/frontend/paip.ai-web
Some checks failed
paipai-h5-dev / build-and-push (push) Failing after 9s
paipai-h5-dev / deploy (push) Has been skipped
paipai-h5-dev / cleanup (push) Failing after 2s

This commit is contained in:
2025-12-05 12:35:35 +08:00
8 changed files with 360 additions and 0 deletions

View File

@@ -0,0 +1,109 @@
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/frontend/rn-h5
tags: |
type=raw,value=latest
- name: Build Docker image
run: |
docker build -f Dockerfile-dev -t code.paipai.life/frontend/rn-h5:latest .
- name: Push Docker image
run: |
docker push code.paipai.life/frontend/rn-h5: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-h5"
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-h5
docker pull code.paipai.life/frontend/rn-h5:latest
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

View File

@@ -0,0 +1,111 @@
name: rn-h5-prod
on:
push:
tags: ['v*']
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: 626064810415.dkr.ecr.us-west-1.amazonaws.com
username: ${{ secrets.PROD_DOCKER_USERNAME }}
password: ${{ secrets.PROD_DOCKER_PASSWORD }}
- name: Extract tag name
id: tag
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Build Docker image
run: |
docker build -t 626064810415.dkr.ecr.us-west-1.amazonaws.com/raveai/rn-h5:${{ steps.tag.outputs.TAG }} .
- name: Push Docker image
run: |
docker push 626064810415.dkr.ecr.us-west-1.amazonaws.com/raveai/rn-h5:${{ steps.tag.outputs.TAG }}
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: Extract tag name
id: tag
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Copy files and deploy via SSH
uses: appleboy/scp-action@v0.1.3
with:
host: ${{ secrets.PROD_SERVER_HOST }}
username: ${{ secrets.PROD_SERVER_USERNAME }}
key: ${{ secrets.PROD_SERVER_KEY }}
port: 22
source: "docker-compose.yaml"
target: "/home/ubuntu/docker-compose/rn-h5"
override: true
- name: Deploy with Docker Compose
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.PROD_SERVER_HOST }}
username: ${{ secrets.PROD_SERVER_USERNAME }}
key: ${{ secrets.PROD_SERVER_KEY }}
port: 22
script: |
# 切换到项目目录
cd /home/ubuntu/docker-compose/rn-h5
aws ecr get-login-password --region us-west-1 | docker login --username AWS --password-stdin 626064810415.dkr.ecr.us-west-1.amazonaws.com
# 拉取指定tag的镜像
docker pull 626064810415.dkr.ecr.us-west-1.amazonaws.com/raveai/rn-h5:${{ steps.tag.outputs.TAG }}
TAG=${{ steps.tag.outputs.TAG }} docker compose down
TAG=${{ steps.tag.outputs.TAG }} docker compose up -d
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.PROD_SERVER_HOST }}
username: ${{ secrets.PROD_SERVER_USERNAME }}
key: ${{ secrets.PROD_SERVER_KEY }}
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

16
Dockerfile Normal file
View File

@@ -0,0 +1,16 @@
FROM node:20-alpine AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build:h5
FROM nginx:stable-alpine AS production
COPY --from=build /app/dist/build/h5 /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

16
Dockerfile-dev Normal file
View File

@@ -0,0 +1,16 @@
FROM node:20-alpine AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build:h5
FROM nginx:stable-alpine AS production
COPY --from=build /app/dist/build/h5 /usr/share/nginx/html
COPY nginx.dev.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

13
docker-compose-dev.yaml Normal file
View File

@@ -0,0 +1,13 @@
services:
web:
image: code.paipai.life/frontend/rn-h5
container_name: rn-h5
networks:
- app-net
ports:
- "8300:80"
restart: unless-stopped
networks:
app-net:
external: true

13
docker-compose.yaml Normal file
View File

@@ -0,0 +1,13 @@
services:
web:
image: 626064810415.dkr.ecr.us-west-1.amazonaws.com/raveai/rn-h5:${TAG}
container_name: rn-h5
networks:
- rn-network
ports:
- "8300:80"
restart: unless-stopped
networks:
rn-network:
external: true

41
nginx.conf Normal file
View File

@@ -0,0 +1,41 @@
server {
listen 80;
server_name h5.paipai.life;
root /usr/share/nginx/html;
index index.html;
# 设置客户端请求体超时时间
client_body_timeout 300s;
# API 代理配置 - 对应 proxy.ts 中的配置
location /api/v1/ {
proxy_pass https://rn-master:8088/api/v1/; # 根据实际后端服务地址调整
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# 代理超时设置
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
# 代理缓冲区设置
proxy_buffering off;
proxy_request_buffering off;
}
# 单页应用路由配置
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
# 静态资源缓存配置
location /static {
expires 7d;
add_header Cache-Control "public, no-transform";
}
}

41
nginx.dev.conf Normal file
View File

@@ -0,0 +1,41 @@
server {
listen 80;
server_name h5.dev.paipai.life;
root /usr/share/nginx/html;
index index.html;
# 设置客户端请求体超时时间
client_body_timeout 300s;
# API 代理配置 - 对应 proxy.ts 中的配置
location /api/v1/ {
proxy_pass https://rn-master:8088/api/v1/; # 根据实际后端服务地址调整
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# 代理超时设置
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
# 代理缓冲区设置
proxy_buffering off;
proxy_request_buffering off;
}
# 单页应用路由配置
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
# 静态资源缓存配置
location /static {
expires 7d;
add_header Cache-Control "public, no-transform";
}
}