Skip to content

Commit ce2b20e

Browse files
committed
[FEAT] ci/ci pipeline 생성
1 parent 81e8378 commit ce2b20e

File tree

3 files changed

+78
-2
lines changed

3 files changed

+78
-2
lines changed

.github/workflows/cd.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: CD
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
workflow_dispatch:
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Configure SSH
18+
run: |
19+
mkdir -p ~/.ssh
20+
echo "$EC2_SSH_KEY" > ~/.ssh/id_rsa
21+
chmod 600 ~/.ssh/id_rsa
22+
23+
cat >>~/.ssh/config <<END
24+
Host ec2
25+
HostName $EC2_HOST
26+
User ubuntu
27+
IdentityFile ~/.ssh/id_rsa
28+
StrictHostKeyChecking no
29+
END
30+
env:
31+
EC2_HOST: ${{ secrets.EC2_HOST }}
32+
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
33+
34+
- name: Copy code to EC2
35+
run: |
36+
ssh ec2 "sudo mkdir -p /opt/app && sudo chown ubuntu:ubuntu /opt/app"
37+
scp -r ./ ec2:/opt/app
38+
39+
- name: Create .env file
40+
run: |
41+
ssh ec2 "echo '$ENV_FILE' > /opt/app/.env"
42+
env:
43+
ENV_FILE: ${{ secrets.ENV_FILE }}
44+
45+
- name: Install dependencies
46+
run: ssh ec2 "cd /opt/app && npm install"
47+
48+
- name: Restart systemd service
49+
run: ssh ec2 "sudo systemctl restart app"

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches: [develop]
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Setup Node.js
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version: 20
18+
19+
- name: Install dependencies
20+
run: npm install
21+
22+
- name: Run Linter
23+
run: npm run lint
24+
25+
- name: Run Tests
26+
run: npm test

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
"version": "1.0.0",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1",
87
"start": "node src/index.js",
9-
"dev": "nodemon -e js,json,prisma --exec \"prisma generate && node src/index.js\""
8+
"dev": "nodemon -e js,json,prisma --exec \"prisma generate && node src/index.js\"",
9+
"lint": "eslint .",
10+
"test": "echo \"No tests yet\" && exit 0"
1011
},
1112
"author": "",
1213
"license": "ISC",

0 commit comments

Comments
 (0)