-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (71 loc) · 2.89 KB
/
prod-cicd.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
name: Prod Backend CI CD
on:
push:
branches: [prod]
permissions:
contents: write
packages: write
env:
SSH_HOST: "000.000.000.000"
SSH_USERNAME: "root" # sometimes its ubuntu
SSH_PORT: "22"
# add the password in your github action secret
jobs:
build:
runs-on: ubuntu-latest
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@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
target: prod
push: true
# platforms: linux/arm64/v8 # Specify the target platform for oracle arm, default is linux/amd64
tags: ghcr.io/${{ github.repository }}/np-server:latest
- name: Upload Docker Compose File
uses: appleboy/[email protected]
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
# key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ env.SSH_PORT }}
source: "docker-compose.yml" # take file from ./
target: "/root" # to root folder /root
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy via SSH
uses: appleboy/[email protected]
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
# key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ env.SSH_PORT }}
script: |
echo "run the nginx proxy manager + redis"
docker compose up -d
echo "sleep 2 sec."
sleep 2
echo "start deploying"
docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
docker pull ghcr.io/${{ github.repository }}/np-server:latest
docker stop np-server || true
docker rm np-server || true
echo "remove done, rerun again."
docker run -d --name np-server --restart unless-stopped --network np_network -p 4000:4000 ghcr.io/${{ github.repository }}/np-server:latest
echo "cleanup"
sleep 2
docker image prune --all -f