-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (89 loc) · 3.02 KB
/
ci-cd.yml
File metadata and controls
107 lines (89 loc) · 3.02 KB
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
name: Lint, Format, Build, Push & Deploy
on:
push:
branches: [main]
pull_request:
branches: ['main']
jobs:
ci-check:
name: Lint, Format, Build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24
- name: Install dependencies
run: npm ci --include=optional
- name: Run Lint
run: npm run lint
- name: Format Check
run: npm run format
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: ci-check
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.PACKAGE_NAME }}:${{ secrets.PACKAGE_VERSION }}
build-args: |
NEXT_PUBLIC_BASE_URL=${{ secrets.NEXT_PUBLIC_BASE_URL }}
NEXT_PUBLIC_BASE_API=${{ secrets.NEXT_PUBLIC_BASE_API }}
NEXT_PUBLIC_CHATBOT_API_URL=${{ secrets.NEXT_PUBLIC_CHATBOT_API_URL }}
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=${{ secrets.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY }}
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: build-and-push
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Copy Compose File
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_PRIVATE_KEY }}
source: 'compose.yaml'
target: '/home/${{ secrets.VPS_USER }}/${{ secrets.PACKAGE_NAME }}'
- name: Copy Caddy File
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_PRIVATE_KEY }}
source: 'Caddyfile'
target: '/home/${{ secrets.VPS_USER }}/${{ secrets.PACKAGE_NAME }}'
- name: Deploy via SSH
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_PRIVATE_KEY }}
script: |
cd ~/${{ secrets.PACKAGE_NAME }}
sudo docker compose pull
sudo docker compose down --remove-orphans
sudo docker compose up -d
sudo docker image prune -f