Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/ci-cd #2

Merged
merged 30 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0b6b328
Chore: S3로 deploy하는 github action 작성
cgh96 Jul 23, 2023
8f79beb
Chore: Code Deploy 동작 정의
cgh96 Jul 23, 2023
32aab95
Chore: 쉘 스크립트 수정
cgh96 Jul 23, 2023
7f6b942
Chore: Deploy 코드 수정
cgh96 Jul 23, 2023
08a9329
Chore: deploy action 수정
cgh96 Jul 23, 2023
11e08c5
Chore: deploy 수정
cgh96 Jul 23, 2023
1ddf8c2
Chore: deploy 수정
cgh96 Jul 23, 2023
1011edf
Chore: appspec, Deploy 수정
cgh96 Jul 23, 2023
fb0cbd2
Chore: after-deploy 수정
cgh96 Jul 23, 2023
fb0b73e
Chore: build폴더만 s3에 업로드
cgh96 Jul 23, 2023
47d608e
Chore: next project 전체 업로드
cgh96 Jul 23, 2023
3fa8087
Chore: after-deploy.sh 수정
cgh96 Jul 23, 2023
9547a39
Chore: Husky를 dependency로 이동
cgh96 Jul 23, 2023
b8ea4e4
Chore: husky를 dependency로 이동
cgh96 Jul 23, 2023
2215647
Chore: husky를 devdependencies로 이동
cgh96 Jul 23, 2023
9990c0f
Chore: deploy node_modules 제외
cgh96 Jul 23, 2023
fea97d3
Chore: after-deploy timeout 확장
cgh96 Jul 23, 2023
e11a35d
Chore: ApplicationSTart 추가
cgh96 Jul 23, 2023
ec9b8f6
Chore: npm run start 제거
cgh96 Jul 23, 2023
0faf845
Chore: npm build 제거
cgh96 Jul 23, 2023
4f392b4
Chore: node_modules 추가
cgh96 Jul 23, 2023
c9c0c6f
Chore: pm2 config 파일 추가
cgh96 Jul 24, 2023
fe1cf2a
Chore: install 및 build 추가
cgh96 Jul 24, 2023
12cbe94
Chore: install, build과정 제거
cgh96 Jul 24, 2023
2ea4b73
Chore: 압축 파일에 node_modules제거
cgh96 Jul 24, 2023
b72102a
Chore: npm 스크립트 실행 위치 변경
cgh96 Jul 24, 2023
67f22b5
Chore: shell script 수정
cgh96 Jul 24, 2023
d6ff56b
Chore: 변경사항 자동 적용 되는지 test
cgh96 Jul 24, 2023
3aa1741
Chore: 변경사항 자동 변경 여부 확인
cgh96 Jul 24, 2023
58f33a7
Chore: github action testing 자동화
cgh96 Jul 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
}
},
"ignorePatterns": ["next.config.js", "jest.*.js"],
"ignorePatterns": ["*.setup.js", "*.config.js"],
"extends": [
"next/core-web-vitals",
"plugin:@typescript-eslint/recommended",
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/Deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: deploy to S3

on:
push:
branches:
- main

env:
S3_BUCKET_NAME: chagok-bucket
CODE_DEPLOY_APPLICATION_NAME: chagok-code-deploy
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: chagok

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]

steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

- name: Install dependencies
run: npm ci

# 프로젝트를 빌드한다.
- name: Build next app
run: npm run build

- name: Make zip file
run: zip -qq -r ./chagok.zip . -x "node_modules/*"
# -x "node_modules/*"

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2

# Make zip file 단계에서 압축된 빌드 파일을 S3 버킷에 업로드하는 단계이다.
- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./chagok.zip s3://$S3_BUCKET_NAME/chagok.zip

# S3에 업로드 된 빌드 파일을 이용해 CodeDeploy가 정의된 동작을 하도록 트리거
- name: Code Deploy
run: |
aws deploy create-deployment \
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \
--s3-location bucket=$S3_BUCKET_NAME,bundleType=zip,key=chagok.zip
27 changes: 27 additions & 0 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Node.js CI

on:
push:
branches-ignore:
- main

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
1 change: 0 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run test
npx lint-staged
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.yml
*.sh
21 changes: 21 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 0.0
os: linux

files:
- source: /
destination: /home/ubuntu/chagok
overwrite: yes
permissions:
- object: /home/ubuntu/chagok
owner: ubuntu
group: ubuntu
mode: 755
hooks:
AfterInstall:
- location: scripts/after-install.sh
timeout: 120
runas: root
ApplicationStart:
- location: scripts/app-start.sh
timeout: 300
runas: root
22 changes: 22 additions & 0 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
apps: [
{
name: "project",
script: "npm",
args: "run start",
instances: 2,
autorestart: true,
watch: false,
env: {
PORT: 3000,
NODE_ENV: "development",
},
env_production: {
PORT: 3000,
NODE_ENV: "production",
},
output: "./logs/console.log",
error: "./logs/consoleError.log",
},
],
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
"eslint-plugin-react-hooks": "^5.0.0-canary-7118f5dd7-20230705",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-unused-imports": "^3.0.0",
"husky": "^8.0.0",
"jest": "^29.6.1",
"jest-environment-jsdom": "^29.6.1",
"husky": "^8.0.3",
"lint-staged": "^13.2.3",
"typescript": "^4.9.5"
},
Expand Down
6 changes: 6 additions & 0 deletions scripts/after-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
echo "> after install"

cd /home/ubuntu/chagok
sudo rm -r node_modules
npm install
npm run build
1 change: 1 addition & 0 deletions scripts/app-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo "app start ;)"
3 changes: 2 additions & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react/no-unknown-property */
import { Inter } from "next/font/google";
import Head from "next/head";
import Image from "next/image";
Expand All @@ -15,7 +16,7 @@ export default function Home() {
<link rel="icon" href="/favicon.ico" />
</Head>
<main className={`${styles.main} ${inter.className}`}>
<div className={styles.description}>
<div className={styles.description} css={{ backgroundColor: "blue" }}>
<p>
Get started by editing&nbsp;
<code className={styles.code}>src/pages/index.tsx</code>
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
// "jsxImportSource": "@emotion/react",
"jsxImportSource": "@emotion/react",
"incremental": true,
"baseUrl": "./src"
},
Expand Down