-
Notifications
You must be signed in to change notification settings - Fork 38
[김태희] sprint8 #283
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
The head ref may contain hidden characters: "part2-\uAE40\uD0DC\uD76C-sprint8"
[김태희] sprint8 #283
Changes from all commits
ad3e7ce
1a03ab0
16bedf9
f12dc91
44a7eee
c36a596
1131f9b
1fc6237
0a1516f
c0bf246
4d734ee
18e09d0
61083f9
ba07554
582292e
20ddd8f
86785b1
9da7f76
f074f48
f49dffd
8a7d626
56c570c
a8634b9
7bc43da
8b83239
49e54af
08deed9
cdbb4d5
415cb73
3b19baf
272ba28
3869b81
d25a7c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# IDE & Git | ||
.idea | ||
*.iml | ||
.git | ||
.gitattributes | ||
.github | ||
|
||
# Gradle build cache | ||
.gradle | ||
build | ||
|
||
# 환경 템플릿 | ||
.env.template | ||
|
||
# 문서 | ||
*.md | ||
|
||
# 로그 | ||
*.log |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
name: Build and Deploy to Public ECR and ECS | ||
on: | ||
push: | ||
branches: | ||
- part2-김태희-sprint8 | ||
|
||
env: | ||
AWS_REGION: ${{ vars.AWS_REGION }} | ||
ECR_REPOSITORY_URI: ${{ vars.ECR_REPOSITORY_URI }} | ||
ECS_CLUSTER: ${{ vars.ECS_CLUSTER }} | ||
ECS_SERVICE: ${{ vars.ECS_SERVICE }} | ||
ECS_TASK_DEFINITION: ${{ vars.ECS_TASK_DEFINITION }} | ||
|
||
jobs: | ||
build-and-push: | ||
name: Build and Push Docker Image | ||
runs-on: ubuntu-latest | ||
outputs: | ||
image-tag: ${{ steps.set-image-tag.outputs.image-tag }} | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set image tags | ||
id: set-image-tag | ||
run: | | ||
IMAGE_TAG=$(date +'%Y%m%d%H%M%S')-${GITHUB_SHA::8} | ||
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV | ||
echo "image-tag=$IMAGE_TAG" >> $GITHUB_OUTPUT | ||
Comment on lines
+29
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요즘 github actions 로 ci/cd 하는 케이스가 많아져서, 요 부분은 기억하고 계시면 좋습니다. github actions 이 어떻게 변수를 저장하는가, 에 대해서요 |
||
|
||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v2 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- name: Login to Amazon ECR Public | ||
run: | | ||
aws ecr-public get-login-password --region us-east-1 \ | ||
| docker login --username AWS --password-stdin public.ecr.aws | ||
|
||
- name: Build Docker image | ||
run: | | ||
docker build \ | ||
-t ${{ env.ECR_REPOSITORY_URI }}:latest \ | ||
-t ${{ env.ECR_REPOSITORY_URI }}:${{ env.IMAGE_TAG }} . | ||
|
||
- name: Push Docker image | ||
run: | | ||
docker push ${{ env.ECR_REPOSITORY_URI }}:latest | ||
docker push ${{ env.ECR_REPOSITORY_URI }}:${{ env.IMAGE_TAG }} | ||
|
||
deploy-to-ecs: | ||
name: Deploy to ECS | ||
runs-on: ubuntu-latest | ||
needs: build-and-push | ||
|
||
env: | ||
IMAGE_TAG: ${{ needs.build-and-push.outputs.image-tag }} | ||
|
||
steps: | ||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v2 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- name: Download current ECS task definition | ||
run: | | ||
aws ecs describe-task-definition --task-definition ${{ env.ECS_TASK_DEFINITION }} --query taskDefinition > task-def.json | ||
|
||
- name: Update task definition with new image | ||
id: render-task-def | ||
uses: aws-actions/amazon-ecs-render-task-definition@v1 | ||
with: | ||
task-definition: task-def.json | ||
container-name: discodeit-app | ||
image: ${{ env.ECR_REPOSITORY_URI }}:${{ env.IMAGE_TAG }} | ||
|
||
- name: Scale down ECS service to 0 (stop current tasks) | ||
run: | | ||
aws ecs update-service \ | ||
--cluster ${{ env.ECS_CLUSTER }} \ | ||
--service ${{ env.ECS_SERVICE }} \ | ||
--desired-count 0 | ||
|
||
- name: Deploy to Amazon ECS | ||
uses: aws-actions/amazon-ecs-deploy-task-definition@v2 | ||
with: | ||
task-definition: ${{ steps.render-task-def.outputs.task-definition }} | ||
cluster: ${{ env.ECS_CLUSTER }} | ||
service: ${{ env.ECS_SERVICE }} | ||
wait-for-service-stability: true | ||
|
||
- name: Scale up ECS service to 1 (start tasks) | ||
run: | | ||
aws ecs update-service \ | ||
--cluster ${{ env.ECS_CLUSTER }} \ | ||
--service ${{ env.ECS_SERVICE }} \ | ||
--desired-count 1 | ||
Comment on lines
+83
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 세팅에서는 기존 서비스(서버)가 0개로 줄고 새 서비스(서버)가 1개로 태어나는 사이동안 서버가 꺼지는, 즉 무중단 배포에 실패하는 순간이 발생할 것으로 보입니다. ECS 를 활용한 무중단 배포는 한번 따로 공부를 해두시길 추천드립니다 |
||
|
||
- name: Verify deployment | ||
run: | | ||
echo "Verifying deployment..." | ||
SERVICE_STATUS=$(aws ecs describe-services --cluster ${{ env.ECS_CLUSTER }} --services ${{ env.ECS_SERVICE }} --query "services[0].status" --output text) | ||
if [ "$SERVICE_STATUS" = "ACTIVE" ]; then | ||
echo "Deployment successful! Service is running." | ||
else | ||
echo "Deployment may have issues. Running count: $SERVICE_STATUS" | ||
exit 1 | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: CI Test | ||
|
||
on: | ||
push: | ||
branches: | ||
- part2-김태희-sprint8 | ||
|
||
jobs: | ||
test: | ||
name: Run Tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요것도 아마 v4 가 있을겁니다 |
||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
- name: Grant execute permission for Gradlew | ||
run: chmod +x ./gradlew | ||
|
||
- name: Build and test with Gradle | ||
run: ./gradlew test | ||
|
||
- name: Run tests with coverage | ||
run: ./gradlew test jacocoTestReport | ||
Comment on lines
+27
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분은 불필요하게 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그리고 build.gradle 에 |
||
|
||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
FROM amazoncorretto:17 as builder | ||
WORKDIR /app | ||
|
||
# Gradle 관련 파일 복사 (Wrapper 포함) | ||
COPY gradlew . | ||
COPY gradle gradle | ||
COPY build.gradle . | ||
COPY settings.gradle . | ||
|
||
# Gradle 의존성 사전 다운로드 (캐시 활용) | ||
RUN chmod +x gradlew && ./gradlew dependencies | ||
|
||
# 애플리케이션 소스 코드 복사 및 빌드 (테스트 생략) | ||
COPY src src | ||
RUN ./gradlew build -x test | ||
|
||
FROM amazoncorretto:17 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test 를 돌리는 github action 에선 jdk 17 temurin 을 사용했는데 여기선 amazon corretto 를 사용하고 있네요. 99.999% 확률로 아무 문제 없겠지만 굳이 서로 다른 jdk 를 쓸 필요는 없을 듯 합니다. |
||
|
||
WORKDIR /app | ||
|
||
# 환경 변수 설정 (기본값 포함) | ||
ENV PROJECT_NAME=discodeit | ||
ENV PROJECT_VERSION=1.2-M8 | ||
ENV JVM_OPTS="" | ||
ENV SERVER_PORT=80 | ||
|
||
# 임시 파일 저장소 볼륨 선언 (Spring Boot에서 종종 필요) | ||
VOLUME /tmp | ||
|
||
# 빌드 결과물 복사 | ||
COPY --from=builder /app/build/libs/${PROJECT_NAME}-${PROJECT_VERSION}.jar app.jar | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
RUN chmod +x /entrypoint.sh | ||
|
||
# 80 포트 노출 | ||
EXPOSE 80 | ||
|
||
# 실행 명령 설정 (환경 변수 활용) | ||
ENTRYPOINT ["/entrypoint.sh"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# 2-sprint-mission | ||
2기 스프린트 미션 제출 리포지토리입니다. | ||
|
||
[](https://codecov.io/gh/WaiCat/2-sprint-mission) | ||
|
||
2기 스프린트 미션 제출 리포지토리입니다. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요런건 중요한건 아닙니다만 최신 버전을 쓰는게 좋아요.
checkout@v4
좋은 linter 를 쓰면 사전에 업그레이드 하라고 조언해주는 경우도 있습니다.