Skip to content

Commit

Permalink
Merge pull request #45 from boostcampwm-2024/back/main
Browse files Browse the repository at this point in the history
[BE] 데모용 Pull Request
  • Loading branch information
uuuo3o authored Nov 7, 2024
2 parents 20da861 + 096161f commit a100a1a
Show file tree
Hide file tree
Showing 48 changed files with 5,306 additions and 8,845 deletions.
34 changes: 0 additions & 34 deletions .github/workflows/CI

This file was deleted.

64 changes: 64 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: CI

on:
push:
branches: [back/main, front/main]
pull_request:
branches: [main, back/main, dev]

jobs:
BE-test-and-build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- 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
run: npm test
working-directory: ./BE
env:
CI: true

- name: Run linter
working-directory: ./BE
run: npm run lint

- name: Build application
working-directory: ./BE
run: npm run build

FE-test-and-build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- 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: ./FE
run: npm ci

- name: Run linter
working-directory: ./FE
run: npm run lint

- name: Build application
working-directory: ./FE
run: npm run build
112 changes: 112 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: deploy

on:
push:
branches: [main, alpha]
pull_request:
branches: [main, alpha]

env:
DOCKER_IMAGE: ${{ vars.DOCKERHUB_USERNAME }}/juga-docker
DOCKER_TAG: ${{ github.sha }}

jobs:
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: Create .env file
run: |
touch ./BE/.env
echo "${{ secrets.ENV }}" > ./BE/.env
- 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: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- 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: Get Github Actions IP
id: ip
uses: haythem/[email protected]

- name: Setting NCP CLI & Credentials
run: |
cd ~
wget https://www.ncloud.com/api/support/download/5/65
unzip 65
mkdir ~/.ncloud
echo -e "[DEFAULT]\nncloud_access_key_id = ${{ secrets.NCP_ACCESS_KEY }}\nncloud_secret_access_key = ${{ secrets.NCP_SECRET_KEY }}\nncloud_api_url = ${{ secrets.NCP_API_URI }}" >> ~/.ncloud/configure
- name: Add Github Action Ip to Security group
run: |
cd ~
ls -la
chmod -R 777 ~/cli_linux
cd ~/cli_linux
./ncloud vserver addAccessControlGroupInboundRule --regionCode KR --vpcNo ${{ secrets.NCP_VPC_ID }} --accessControlGroupNo ${{ secrets.NCP_ACG_ID }} --accessControlGroupRuleList "protocolTypeCode='TCP', ipBlock='${{ steps.ip.outputs.ipv4 }}/32', portRange='${{ secrets.SSH_PORT }}'"
- 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 }}
port: 22
script: |
docker system prune -af
echo "${{ secrets.ENV }}" > .env
docker pull ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }}
docker stop juga-docker || true
docker rm juga-docker || true
docker run -d \
--name juga-docker \
-p 3000:3000 \
--env-file .env \
${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }}
- name: Remove Github Action Ip to Security group
run: |
chmod -R 777 ~/cli_linux
cd ~/cli_linux
./ncloud vserver removeAccessControlGroupInboundRule --regionCode KR --vpcNo ${{ secrets.NCP_VPC_ID }} --accessControlGroupNo ${{ secrets.NCP_ACG_ID }} --accessControlGroupRuleList "protocolTypeCode='TCP', ipBlock='${{ steps.ip.outputs.ipv4 }}/32', portRange='${{ secrets.SSH_PORT }}'"
4 changes: 4 additions & 0 deletions BE/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
Dockerfile
node_modules
dist
16 changes: 11 additions & 5 deletions BE/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ module.exports = {
},
ignorePatterns: ['.eslintrc.js', 'dist'],
rules: {
'@typescript-eslint/lines-between-class-members': ['error', 'always', {
exceptAfterSingleLine: true,
}],
'@typescript-eslint/lines-between-class-members': [
'error',
'always',
{
exceptAfterSingleLine: true,
},
],
'@typescript-eslint/no-throw-literal': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-unsafe-argument': 'error',
'import/prefer-default-export': 'off',
'class-methods-use-this': 'off'
'class-methods-use-this': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
},
};
};
8 changes: 8 additions & 0 deletions BE/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:20
RUN mkdir -p /var/app
WORKDIR /var/app
COPY . .
RUN npm install
RUN npm run build
EXPOSE 3000
CMD [ "node", "dist/main.js" ]
Loading

0 comments on commit a100a1a

Please sign in to comment.