-
Notifications
You must be signed in to change notification settings - Fork 1
79 lines (66 loc) · 2.07 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
name: deploy
on:
push:
branches: [main, alpha]
pull_request:
branches: [main, alpha]
env:
DOCKER_IMAGE: BE
DOCKER_TAG: ${{ github.sha }}
jobs:
login:
runs-on: ubuntu-latest
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: ./BE/package-lock.json
- name: Install dependencies
working-directory: ./BE
run: npm ci
- name: Run tests
working-directory: ./BE
run: npm test
env:
CI: true
- name: Run linter
working-directory: ./BE
run: npm run lint
- name: Build application
working-directory: ./BE
run: npm run build
- name: Build and Push Docker Image
working-directory: ./BE
env:
NCP_ACCESS_KEY: ${{ secrets.NCP_ACCESS_KEY }}
NCP_SECRET_KEY: ${{ secrets.NCP_SECRET_KEY }}
run: |
docker build -t ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} .
docker tag ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} ${{ env.DOCKER_IMAGE }}:latest
docker push ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }}
docker push ${{ env.DOCKER_IMAGE }}:latest
- name: Deploy to NCP Server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.NCP_SERVER_HOST }}
username: ${{ secrets.NCP_SERVER_USERNAME }}
key: ${{ secrets.NCP_SERVER_SSH_KEY }}
script: |
docker pull ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }}
docker stop my-app || true
docker rm my-app || true
docker run -d \
--name my-app \
-p 8080:8080 \
${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }}