-
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.
- Loading branch information
Showing
3 changed files
with
119 additions
and
10 deletions.
There are no files selected for viewing
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,87 @@ | ||
name: Siso - 밸런스 게임 벡엔드 배포 자동화 워크 플로우(backend-prod) | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
|
||
permissions: | ||
checks: write | ||
|
||
jobs: | ||
detect-changes: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: read | ||
outputs: | ||
backend: ${{ steps.filter.outputs.backend }} # backend 변경 여부를 출력으로 설정 | ||
frontend: ${{ steps.filter.outputs.frontend }} # frontend 변경 여부를 출력으로 설정 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # 모든 Git 히스토리를 가져옴 | ||
- name: Get previous tag | ||
id: previoustag | ||
run: echo "PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ --always)" >> $GITHUB_OUTPUT | ||
# 이전 태그를 찾아서 환경 변수로 저장 | ||
- uses: dorny/paths-filter@v3 | ||
id: filter | ||
with: | ||
base: ${{ steps.previoustag.outputs.PREVIOUS_TAG }} # 이전 태그 기준 | ||
ref: ${{ github.ref }} # 현재 GitHub 참조(커밋, 태그 등) | ||
filters: | | ||
backend: | ||
- 'backend/**' | ||
frontend: | ||
- 'frontend/**' | ||
docker-deploy: | ||
needs: detect-changes | ||
if: ${{ needs.detect-changes.outputs.backend == 'true' }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Docker hub 로그인 | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- name: Docker 이미지 빌드 및 푸시 | ||
run: | | ||
docker build -t ${{ secrets.DOCKER_USERNAME }}/siso-backend:latest ./backend | ||
docker push ${{ secrets.DOCKER_USERNAME }}/siso-backend:latest | ||
ec2-deploy: | ||
needs: docker-deploy | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: EC2에 배포 | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ${{ secrets.EC2_USERNAME }} | ||
key: ${{ secrets.EC2_KEY }} | ||
port: ${{ secrets.SSH_PORT }} | ||
script: | | ||
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
docker pull ${{ secrets.DOCKER_USERNAME }}/siso-backend:latest | ||
docker stop siso-backend || true | ||
docker rm siso-backend || true | ||
docker run -d --env-file /home/ubuntu/env/backend.env -p 8080:80 --name siso-backend ${{ secrets.DOCKER_USERNAME }}/siso-backend:latest | ||
# - name: Docker 이미지 빌드 | ||
# run: | | ||
# docker build -t siso-backend:latest ./backend/dist | ||
# docker tag | ||
|
||
# - name: Deploy to EC2 | ||
# uses: appleboy/ssh-action@master | ||
# with: | ||
# host: ${{ secrets.EC2_HOST }} | ||
# username: ${{ secrets.EC2_USERNAME }} | ||
# key: ${{ secrets.EC2_KEY }} | ||
# port: ${{ secrets.SSH_PORT }} | ||
# script: | |
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,32 @@ | ||
FROM node:18-alpine AS build | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY package*.json ./ | ||
|
||
RUN npm install | ||
|
||
COPY . . | ||
|
||
RUN npm run build | ||
|
||
|
||
FROM node:18-alpine | ||
|
||
WORKDIR /usr/src/app | ||
|
||
ARG NODE_ENV=production | ||
|
||
ENV NODE_ENV=${NODE_ENV} | ||
|
||
COPY --from=build /usr/src/app/dist ./dist | ||
|
||
COPY package*.json ./ | ||
|
||
RUN npm install --only=production | ||
|
||
RUN rm package*.json | ||
|
||
EXPOSE 8080 | ||
|
||
CMD ["node", "dist/main.js"] |
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