-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (100 loc) · 3.64 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: deploy and release
on:
push:
branches: ["main"]
paths-ignore:
- '*.md'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ngyngcphu/chathoy
CD_USERNAME: ngyngcphu
permissions:
contents: write
pull-requests: write
packages: write
jobs:
release:
runs-on: ubuntu-latest
outputs:
build: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: node
package-name: chathoy
pull-request-header: "Bot (:robot:) requested to create a new release on ${{ github.ref_name }}"
build:
name: Build
needs: [release]
runs-on: ubuntu-latest
if: ${{ needs.release.outputs.build == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.CD_USERNAME }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.release.outputs.tag_name }}, ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
copy:
name: Copy file
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Copy html file
uses: appleboy/scp-action@master
with:
host: ${{ secrets.VPS_HOST }}
port: ${{ secrets.VPS_PORT }}
username: ${{ secrets.VPS_USERNAME }}
password: ${{ secrets.VPS_PASSWORD }}
source: "index.html,index.css"
target: "/var/www/chathoy/html"
- name: Copy nginx config
uses: appleboy/scp-action@master
with:
host: ${{ secrets.VPS_HOST }}
port: ${{ secrets.VPS_PORT }}
username: ${{ secrets.VPS_USERNAME }}
password: ${{ secrets.VPS_PASSWORD }}
source: "chathoy-nginx.config"
target: "/etc/nginx/sites-enabled"
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: [copy]
steps:
- name: Deploy backend
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.VPS_HOST }}
port: ${{ secrets.VPS_PORT }}
username: ${{ secrets.VPS_USERNAME }}
password: ${{ secrets.VPS_PASSWORD }}
script: |
export SUDO=${{ secrets.VPS_PASSWORD }}
echo $SUDO | sudo nginx -t
echo $SUDO | sudo service nginx reload
export CR_PAT=${{ secrets.GITHUB_TOKEN }}
echo $CR_PAT | docker login ${{ env.REGISTRY }} -u ${{ env.CD_USERNAME }} --password-stdin
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
mkdir -p ChatHoy-server
cd ChatHoy-server
curl https://raw.githubusercontent.com/ngyngcphu/chathoy/main/docker-compose.yml -o docker-compose.yml
docker compose stop chathoy
docker compose rm -f chathoy
docker compose up -d chathoy
docker logout ${{ env.REGISTRY }}