Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 22 additions & 5 deletions .github/workflows/deploy.yml → .github/workflows/backend-cd.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: deploy
name: backend-cd
on:
push:
paths:
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
- name: set lower case owner name
run: |
echo "OWNER_LC=${OWNER,,}" >> ${GITHUB_ENV}


- name: 빌드 앤 푸시
uses: docker/build-push-action@v3
Expand All @@ -71,12 +71,18 @@ jobs:
tags: |
ghcr.io/${{ env.OWNER_LC }}/${{ env.DOCKER_IMAGE_NAME }}:${{ needs.makeTagAndRelease.outputs.tag_name }},
ghcr.io/${{ env.OWNER_LC }}/${{ env.DOCKER_IMAGE_NAME }}:latest


deploy:
runs-on: ubuntu-latest
needs: [ buildImageAndPush ]
env:
OWNER: ${{ github.repository_owner }}
steps:
- name: set lower case owner name
run: |
echo "OWNER_LC=${OWNER,,}" >> ${GITHUB_ENV}

- name: AWS SSM Send-Command
uses: peterkimzz/aws-ssm-send-command@master
id: ssm
Expand All @@ -88,7 +94,18 @@ jobs:
working-directory: /
comment: Deploy
command: |
# 0. env 변수 확인
echo "OWNER_LC = ${{ env.OWNER_LC }}"

# 1. 최신 이미지 pull
docker pull ghcr.io/${{ env.OWNER_LC }}/catfe-backend:latest

# 2. 기존 컨테이너 종료 및 제거
docker stop catfe-backend 2>/dev/null
docker rm catfe-backend 2>/dev/null
docker run -d --name catfe-backend -p 8080:8080 ghcr.io/${{ env.OWNER_LC }}/catfe-backend:latest

# 3. 새로운 컨테이너 실행
docker run -d --name catfe-backend -p 8080:8080 ghcr.io/${{ env.OWNER_LC }}/catfe-backend:latest

# 4. dangling 이미지 삭제
docker rmi $(docker images -f "dangling=true" -q)
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ out/
db_dev.mv.db
db_dev.trace.db
.env
.env.*

### Terraform ###
/infra/terraform/.terraform
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ WORKDIR /app
COPY build.gradle.kts .
COPY settings.gradle.kts .

# 종속성 설치
RUN gradle dependencies --no-daemon

# 소스코드 복사
COPY src src

# .env 복사
COPY .env .env

# 애플리케이션 빌드
RUN gradle build --no-daemon
RUN gradle build --no-daemon -x test

# 두 번째 스테이지 : 실행 스테이지
FROM container-registry.oracle.com/graalvm/jdk:21
Expand All @@ -26,7 +24,9 @@ WORKDIR /app

# 첫 번째 스테이지에서 빌드된 JAR 파일 복사
COPY --from=builder /app/build/libs/*.jar app.jar
COPY --from=builder /app/.env .env

# 빌드 컨텍스트의 .env(backend-cd 작업에서 빌드된 .env)를 컨테이너 안으로 복사
COPY .env .env

# 실행할 JAR 파일 지정
ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-jar", "app.jar"]