-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (92 loc) · 2.85 KB
/
node.js.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
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
108
109
name: Node.js CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
name: Build and Test Backend
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the code
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full-depth clone for SonarQube analysis
# Step 2: Set up Node.js environment (latest version)
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "22.x"
cache: npm
# Step 3: Install dependencies
- name: Install Dependencies
run: npm ci
# Step 4: Build the source code (if applicable)
- name: Build Source Code
run: npm run build --if-present
# Step 5: Run tests
- name: Run Tests
env:
DB_HOST: ${{ secrets.DB_HOST }}
DB_DIALECT: ${{ secrets.DB_DIALECT }}
DB_USER: ${{ secrets.DB_USER }}
DB_PW: ${{ secrets.DB_PW }}
DB_NAME: ${{ secrets.DB_NAME }}
run: npm test --if-present
lint:
name: Lint Backend
needs: build
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the code
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full-depth clone for SonarQube analysis
# Step 2: Run Snyk Security Scan using Snyk's cloud service
- name: Snyk Security Scan
uses: snyk/actions/node@master
with:
command: test --all-projects
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
# Step 3: SonarQube Scan
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
deliver:
name: Deliver Backend
needs: lint
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the code
- name: Checkout Code
uses: actions/checkout@v4
# Step 2: Log in to Docker Hub
- name: Log in to Docker Hub
run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_HUB_USERNAME }}" --password-stdin
# Step 3: Build Docker image
- name: Build Docker Image
run: docker build -t gregory789/contint-backend-repository:contint-backend-image .
# Step 4: Push Docker image to Docker Hub
- name: Push Docker Image
run: docker push gregory789/contint-backend-repository:contint-backend-image
deploy:
name: Deploy Backend
needs: deliver
runs-on: ubuntu-22.04
steps:
- name: Executing remote SSH commands using SSH key
uses: appleboy/ssh-action@v1.0.3
with:
host: 34.193.142.100
username: ubuntu
key: ${{ secrets.SSH_KEY }}
port: 22
script: sudo /home/ubuntu/deploy.sh