diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..aa1f35d --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,60 @@ +name: Continuous Deployment + +on: + push: + branches: [ "develop" ] + workflow_dispatch: + inputs: + logLevel: + description: 'Log level' + required: true + default: 'warning' + type: choice + options: + - info + - warning + - debug + tags: + description: 'Test scenario tags' + required: false + type: boolean + environment: + description: 'Environment to run tests against' + type: environment + required: false + +permissions: + contents: read + +jobs: + develop-deploy: + runs-on: ubuntu-20.04 + + steps: + # 1. Compare branch 코드 내려 받기 + - name: Checkout PR + uses: actions/checkout@v3 + with: + ref: ${{ github.event.push.base_ref }} + + # 2. Docker 이미지 build 및 push + - name: Docker build and push + run: | + echo "${{ secrets.ENVIRONMENT }}" > .env + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -t jinlee1703/oot-web:latest . + docker push jinlee1703/oot-web:latest + + # 3. SSH ACTION을 통한 Run-Command (Docker 이미지 pull 후 docker-compose를 통한 실행) + - name: Deploy + uses: appleboy/ssh-action@v0.1.5 + with: + host: ${{ secrets.SERVER_HOST }} + port: ${{ secrets.SERVER_SSH_PORT }} + username: ${{ secrets.SERVER_USERNAME }} + password: ${{ secrets.SERVER_PASSWORD }} + script: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker system prune -a -f + docker pull jinlee1703/oot-web:latest + docker-compose up -d \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6358520 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,20 @@ +name: Check Build Possibility + +on: + pull_request: + branches: [ "develop" ] + +jobs: + build-test: + runs-on: ubuntu-20.04 + env: + DISABLE_ESLINT_PLUGIN: true + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3.5.1 + with: + node-version: "21.2.0" + - name: Install dependencies + run: npm install + - name: Try build + run: npm run build \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b80f1f4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +# 가져올 이미지를 정의 +FROM node:20 +# 경로 설정하기 +WORKDIR /app +# package.json 워킹 디렉토리에 복사 (.은 설정한 워킹 디렉토리를 뜻함) +COPY package.json . +# 명령어 실행 (의존성 설치) +RUN npm install +# 현재 디렉토리의 모든 파일을 도커 컨테이너의 워킹 디렉토리에 복사한다. +COPY . . + +# 각각의 명령어들은 한줄 한줄씩 캐싱되어 실행된다. +# package.json의 내용은 자주 바뀌진 않을 거지만 +# 소스 코드는 자주 바뀌는데 +# npm install과 COPY . . 를 동시에 수행하면 +# 소스 코드가 조금 달라질때도 항상 npm install을 수행해서 리소스가 낭비된다. + +# 3000번 포트 노출 +EXPOSE 3000 \ No newline at end of file