Skip to content

[이주용] Sprint8 #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: 이주용
Choose a base branch
from
Open
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
37 changes: 37 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Build output
build/
!build/libs/

# IDE files
.idea/
*.iml
*.iws

# OS files
.DS_Store
Thumbs.db

# Version control
.git/
.gitignore

# Documentation
README.md
HELP.md

# Other directories
admin/
.github/

# Gradle cache
.gradle/

# Test results
test-results/

# Temporary files
*.tmp
*.log

.env
discodeit.env
106 changes: 106 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Deploy to AWS ECS

on:
push:
branches: [ release ]

jobs:
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
outputs:
image: ${{ steps.build-image.outputs.image }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR (Public)
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
registry-type: public

- name: Build, tag and push image to Amazone ECR
id: build-image
env:
ECR_REPOSITORY_URI: ${{ vars.ECR_REPOSITORY_URI }}
IMAGE_TAG: ${{ github.sha }}
run: |
chmod +x ./gradlew
./gradlew bootJar

# Docker 이미지 빌드 (x86_64 아키텍처)
docker build --platform linux/amd64 \
-t $ECR_REPOSITORY_URI:$IMAGE_TAG \
-t $ECR_REPOSITORY_URI:latest .

# 이미지 푸시
docker push $ECR_REPOSITORY_URI:$IMAGE_TAG
docker push $ECR_REPOSITORY_URI:latest

echo "image=$ECR_REPOSITORY_URI:$IMAGE_TAG" >> $GITHUB_OUTPUT

deploy:
name: Deploy to ECS
runs-on: ubuntu-latest
needs: build-and-push

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials for ECS
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ${{ vars.AWS_REGION }}

- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: discodeit-app
image: ${{ needs.build-and-push.outputs.image }}

- name: Stop existing ECS service
run: |
aws ecs update-service \
--cluster ${{ vars.ECS_CLUSTER }} \
--service ${{ vars.ECS_SERVICE }} \
--desired-count 0

aws ecs wait services-stable \
--cluster ${{ vars.ECS_CLUSTER }} \
--services ${{ vars.ECS_SERVICE }}

- name: Deploy to Amazon ECS
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
cluster: ${{ vars.ECS_CLUSTER }}
service: ${{ vars.ECS_SERVICE }}
wait-for-service-stability: true

- name: Start ECS service
run: |
aws ecs update-service \
--cluster ${{ vars.ECS_CLUSTER }} \
--service ${{ vars.ECS_SERVICE }}\
--desired-count 1
51 changes: 51 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Java CI (Gradle + Codecov)

on:
# main 브랜치 대상으로 만든 PR 에서만 실행
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest

env:
SPRING_PROFILES_ACTIVE: test

steps:
# 1. 소스 체크아웃
- name: Source CheckOut
uses: actions/checkout@v4

# 2. JDK 17 설치 + Gradle 캐시
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
cache: gradle # Gradle 종속성 캐싱 설정

# 3. Gradle wrapper 실행 권한 부여 (Linux/macOS용)
- name: Grant execute permission for gradlew
run: chmod +x gradlew

# 4. GitHub Actions 시크릿 및 변수를 통한 .env 생성
- name: Generate .env file
run: |
echo "AWS_S3_ACCESS_KEY=${{ secrets.AWS_ACCESS_KEY }}" >> .env
echo "AWS_S3_SECRET_KEY=${{ secrets.AWS_SECRET_KEY }}" >> .env
echo "AWS_S3_BUCKET=${{ secrets.AWS_S3_BUCKET }}" >> .env
echo "AWS_S3_REGION=${{ vars.AWS_REGION }}" >> .env
echo "AWS_S3_PRESIGNED_URL_EXPIRATION=600" >> .env

# 5. 단위 테스트 + JaCoCo 커버리지 리포트 생성
- name: Run tests
run: |
./gradlew clean test jacocoTestReport

# 6. Codecov 로 커버리지 업로드
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: build/reports/jacoco/test/jacocoTestReport.xml
fail_ci_if_error: true # 업로드 실패 시 워크플로 실패 처리
20 changes: 19 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,22 @@ bin/
.storage

### Logs ###
logs
logs

# Environment variables
.env
.env.local
.env.*.local
discodeit.env

# Docker
docker-compose.override.yml
docker-compose.yml

### AWS 관련 민감 파일들 ###
*.pem
*.key
aws-credentials.txt
.aws/
credentials
config
8 changes: 0 additions & 8 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# === 1단계: 빌드 전용 이미지 ===
FROM amazoncorretto:17 AS builder

WORKDIR /app

# Gradle Wrapper 및 프로젝트 소스 복사
COPY gradlew gradlew.bat ./
COPY gradle ./gradle
COPY build.gradle settings.gradle ./
COPY src ./src

RUN chmod +x ./gradlew
RUN ./gradlew clean build -x test

# === 2단계: 실행 전용 이미지 ===
FROM amazoncorretto:17

WORKDIR /app

# 실행에 필요한 jar 파일만 복사
ARG PROJECT_NAME=discodeit
ARG PROJECT_VERSION=1.2-M8
COPY --from=builder /app/build/libs/${PROJECT_NAME}-${PROJECT_VERSION}.jar app.jar

# 포트 노출
EXPOSE 80

# 환경변수 설정
ENV JVM_OPTS=""

# 애플리케이션 실행
CMD ["sh", "-c", "java $JVM_OPTS -jar app.jar --spring.profiles.active=prod --server.port=80"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Pure - Discord Clone Application
# Pure - Discord Clone Application [![codecov](https://codecov.io/gh/pureod/3-sprint-mission/branch/sprint8/graph/badge.svg?token=4IDIFWEUFI)](https://codecov.io/gh/pureod/3-sprint-mission)

Spring Boot 기반의 실시간 채팅 애플리케이션입니다. Discord와 유사한 기능들을 제공하는 RESTful API 서버입니다.

Expand Down
3 changes: 0 additions & 3 deletions admin/.gitattributes

This file was deleted.

37 changes: 0 additions & 37 deletions admin/.gitignore

This file was deleted.

38 changes: 0 additions & 38 deletions admin/build.gradle

This file was deleted.

Binary file removed admin/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 0 additions & 7 deletions admin/gradle/wrapper/gradle-wrapper.properties

This file was deleted.

Loading