-
Notifications
You must be signed in to change notification settings - Fork 3
72 lines (64 loc) · 2.71 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: deploy
on:
push:
branches: [master, dev,main]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: registry.cn-hongkong.aliyuncs.com # 用您的Registry地址替换
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build and push Docker image
uses: docker/[email protected]
with:
push: true
tags: |
registry.cn-hongkong.aliyuncs.com/whitedewgit/airblog:latest
registry.cn-hongkong.aliyuncs.com/whitedewgit/airblog:${{ github.sha }}
- name: Deploy to server on master branch
if: github.ref == 'refs/heads/main'
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
password: ${{ secrets.SERVER_PASSWORD }}
script: |
echo ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} registry.cn-hongkong.aliyuncs.com --password-stdin
docker pull registry.cn-hongkong.aliyuncs.com/whitedewgit/airblog:latest
docker stop airblog || true
docker rm airblog || true
rm -rf /www/server/nginx/proxy_cache_dir/*
docker run -d --name airblog -p 3020:3020 registry.cn-hongkong.aliyuncs.com/whitedewgit/airblog:latest
- name: Deploy to server on dev branch
if: github.ref == 'refs/heads/dev'
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
password: ${{ secrets.SERVER_PASSWORD }}
script: |
echo ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} registry.cn-hongkong.aliyuncs.com --password-stdin
# - name: Send notification email
# if: failure()
# uses: dawidd6/action-send-mail@v3
# with:
# server_address: smtp.example.com
# server_port: 587
# username: ${{ secrets.EMAIL_USERNAME }}
# password: ${{ secrets.EMAIL_PASSWORD }}
# subject: GitHub Actions Workflow Failed
# to: [email protected]
# from: ${{ secrets.EMAIL_USERNAME }}
# content_type: text/html
# body: |
# <h1>Workflow Failed</h1>
# <p>Your GitHub Actions workflow has failed. Please check the logs for more details.</p>