generated from ngyngcphu/react-template
-
Notifications
You must be signed in to change notification settings - Fork 2
68 lines (57 loc) · 1.85 KB
/
staging.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
name: Staging
on:
push:
branches: ['staging']
paths-ignore:
- '*.md'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ticklabvn/ssps-fe
ORG_USERNAME: ${{ github.actor }}
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup env file
run: |
echo VITE_BACKEND_URL=${{ vars.BACKEND_URL }} >> .env
- 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.ORG_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 }}:latest
deploy:
name: Deploy staging
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.VPS_HOST }}
port: ${{ secrets.VPS_PORT }}
username: ${{ secrets.VPS_USERNAME }}
password: ${{ secrets.VPS_PASSWORD }}
script: |
export CR_PAT=${{ secrets.GITHUB_TOKEN }}
echo $CR_PAT | docker login ${{ env.REGISTRY }} -u ${{ env.ORG_USERNAME }} --password-stdin
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
cd ssps-fe
export TOKEN=${{ secrets.CURL_TOKEN }}
curl -s https://[email protected]/ticklabvn/ssps-fe/main/docker-compose.yml -o docker-compose.yml
docker compose stop ssps-fe
docker compose rm -f ssps-fe
docker compose up -d ssps-fe
docker logout ${{ env.REGISTRY }}