-
Notifications
You must be signed in to change notification settings - Fork 3
62 lines (55 loc) · 1.92 KB
/
go.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
on: [push, pull_request]
name: Continuous Integration and Deployment
jobs:
test-nocache:
strategy:
matrix:
go-version: [1.21.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
cache: false
- run: go test ./...
test-cache:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: 1.21.x
- run: go test ./...
deploy:
runs-on: ubuntu-latest
needs: [test-nocache, test-cache] # Ensure deployment occurs only after tests pass
if: github.ref == 'refs/heads/master' # Deploy only for master branch
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GIT_TOKEN }}
- name: Build and push Docker image
run: |
docker build . --tag ghcr.io/tuanha1305/go-sock5-server/app-sock5:${{ github.sha }}
docker push ghcr.io/tuanha1305/go-sock5-server/app-sock5:${{ github.sha }}
- name: Deploy to Production Server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.IP_SERVER_PRO }}
username: ${{ secrets.USER_SSH }}
key: ${{ secrets.SSH_KEY_PRO }}
script: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
docker pull ghcr.io/tuanha1305/go-sock5-server/app-sock5:${{ github.sha }}
docker stop sock5-app || true
docker rm sock5-app || true
docker run -d --name sock5-app -p 8080:8080 ghcr.io/tuanha1305/go-sock5-server/app-sock5:${{ github.sha }}