-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci/cd의 yml에서 cd부분을 추가했습니다. ncp의 container registry를 사용하며 이미지가 push가 완료되면 action의 메시지를 통해 pull을 받습니다. 이미지를 받은 후, DockerFile을 실행하게 됩니다.
- Loading branch information
Showing
3 changed files
with
80 additions
and
30 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: BackEnd-CI | ||
|
||
on: | ||
push: | ||
branches: 'feature/BE/*' | ||
pull_request: | ||
branches: 'develop' | ||
types: [labeled, opened, synchronize, reopened] | ||
|
||
jobs: | ||
test: | ||
if: contains(github.event.pull_request.labels.*.name, '💻백엔드') | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: 코드 체크아웃 | ||
uses: actions/checkout@v2 | ||
|
||
- name: node 세팅 | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: '18' | ||
|
||
- name: 의존성 설치 | ||
run: npm ci | ||
working-directory: ./BackEnd | ||
|
||
- name: 테스트 진행 | ||
run: npm test | ||
working-directory: ./BackEnd | ||
|
||
deploy: | ||
needs: test | ||
if: github.ref == 'refs/heads/develop' && github.event_name == 'push' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: docker/setup-buildx-action@v2 | ||
- uses: docker/login-action@v1 | ||
with: | ||
registry: ${{ secrets.NCP_CONTAINER_REGISTRY }} | ||
username: ${{ secrets.NCP_ACCESS_KEY }} | ||
password: ${{ secrets.NCP_SECRET_KEY }} | ||
- uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: ./BackEnd/Dockerfile | ||
push: true | ||
tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/my-app:latest | ||
- name: SSH Tunneling and Deploy | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.BASTION_HOST }} | ||
username: ${{ secrets.BASTION_USER }} | ||
key: ${{ secrets.BASTION_SSH_KEY }} | ||
script: | | ||
ssh -o StrictHostKeyChecking=no -L 9999:${{ secrets.INTERNAL_SERVER_IP }}:22 ${{ secrets.BASTION_USER }}@localhost -i ${{ secrets.BASTION_SSH_PRIVATE_KEY_PATH }} -fN | ||
ssh -o StrictHostKeyChecking=no -p 9999 ${{ secrets.SERVER_USER }}@localhost -i ${{ secrets.SERVER_SSH_PRIVATE_KEY_PATH }} ' | ||
docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/my-app:latest | ||
docker stop my-app || true | ||
docker rm my-app || true | ||
docker run --name my-app -d -p 3000:3000 --env-file /var/env/.env ${{ secrets.NCP_CONTAINER_REGISTRY }}/my-app:latest | ||
' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# 빌드 단계 | ||
FROM node:18 AS builder | ||
WORKDIR /app | ||
COPY BackEnd/package*.json ./ | ||
RUN npm install | ||
COPY BackEnd/ . | ||
RUN npm run build | ||
|
||
# 실행 단계 | ||
FROM node:18 | ||
WORKDIR /app | ||
COPY --from=builder /app/dist ./dist | ||
COPY --from=builder /app/package*.json ./ | ||
RUN npm install --only=production | ||
RUN npm install pm2 -g | ||
EXPOSE 3000 | ||
CMD ["pm2-runtime", "start", "dist/main.js"] |