Skip to content

Commit 2a57cef

Browse files
authored
Merge pull request #38 from prgrms-web-devcourse-final-project/chore/33-infra
Chore/33 infra
2 parents d23e414 + dae2670 commit 2a57cef

File tree

7 files changed

+474
-8
lines changed

7 files changed

+474
-8
lines changed

.github/workflows/CI-CD_Pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
SPRING_DATA_REDIS_EMBEDDED=false
8787
8888
# JWT 설정 (application-test.yml에서 참조)
89-
CUSTOM_JWT_SECRET_KEY=test-secret-key-for-testing-purposes-only-minimum-256-bits
89+
CUSTOM_JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}
9090
CUSTOM_JWT_ACCESS_TOKEN_EXPIRATION_SECONDS=3600
9191
EOF
9292

.github/workflows/deploy.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: deploy
2+
on:
3+
push:
4+
paths:
5+
- '.github/workflows/**'
6+
- 'src/**'
7+
- 'build.gradle.kts'
8+
- 'settings.gradle.kts'
9+
- 'Dockerfile'
10+
branches:
11+
- main
12+
jobs:
13+
makeTagAndRelease:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
tag_name: ${{ steps.create_tag.outputs.new_tag }}
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Create Tag
20+
id: create_tag
21+
uses: mathieudutour/[email protected]
22+
with:
23+
github_token: ${{ secrets.GITHUB_TOKEN }}
24+
- name: Create Release
25+
id: create_release
26+
uses: actions/create-release@v1
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
with:
30+
tag_name: ${{ steps.create_tag.outputs.new_tag }}
31+
release_name: Release ${{ steps.create_tag.outputs.new_tag }}
32+
body: ${{ steps.create_tag.outputs.changelog }}
33+
draft: false
34+
prerelease: false
35+
buildImageAndPush:
36+
name: 도커 이미지 빌드와 푸시
37+
needs: makeTagAndRelease
38+
runs-on: ubuntu-latest
39+
env:
40+
DOCKER_IMAGE_NAME: balaw
41+
outputs:
42+
DOCKER_IMAGE_NAME: ${{ env.DOCKER_IMAGE_NAME }}
43+
steps:
44+
- uses: actions/checkout@v4
45+
- name: application-secret.yml 생성
46+
env:
47+
APPLICATION_SECRET: ${{ secrets.APPLICATION_SECRET_YML }}
48+
run: echo "$APPLICATION_SECRET" > src/main/resources/application-secret.yml
49+
- name: Docker Buildx 설치
50+
uses: docker/setup-buildx-action@v2
51+
- name: 레지스트리 로그인
52+
uses: docker/login-action@v2
53+
with:
54+
registry: ghcr.io
55+
username: ${{ github.actor }}
56+
password: ${{ secrets.GITHUB_TOKEN }}
57+
- name: set lower case owner name
58+
run: |
59+
echo "OWNER_LC=${OWNER,,}" >> ${GITHUB_ENV}
60+
env:
61+
OWNER: '${{ github.repository_owner }}'
62+
- name: 빌드 앤 푸시
63+
uses: docker/build-push-action@v3
64+
with:
65+
context: .
66+
push: true
67+
tags: |
68+
ghcr.io/${{ env.OWNER_LC }}/${{ env.DOCKER_IMAGE_NAME }}:${{ needs.makeTagAndRelease.outputs.tag_name }},
69+
ghcr.io/${{ env.OWNER_LC }}/${{ env.DOCKER_IMAGE_NAME }}:latest
70+
71+
deploy:
72+
runs-on: ubuntu-latest
73+
needs: [ buildImageAndPush ]
74+
env:
75+
DOCKER_IMAGE_NAME: ${{ needs.buildImageAndPush.outputs.DOCKER_IMAGE_NAME }}
76+
steps:
77+
- name: AWS SSM Send-Command
78+
uses: peterkimzz/aws-ssm-send-command@master
79+
id: ssm
80+
with:
81+
aws-region: ${{ secrets.AWS_REGION }}
82+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
83+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
84+
instance-ids: "i-0b903187bca01a1c4"
85+
working-directory: /
86+
comment: Deploy
87+
command: |
88+
docker pull ghcr.io/doohyojeong/${{ env.DOCKER_IMAGE_NAME }}:latest
89+
docker stop app1 2>/dev/null
90+
docker rm app1 2>/dev/null
91+
docker run -d --name app1 -p 8080:8080 ghcr.io/doohyojeong/${{ env.DOCKER_IMAGE_NAME }}:latest
92+
docker rmi $(docker images -f "dangling=true" -q)

backend/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# 첫 번째 스테이지: 빌드 스테이지
2+
FROM gradle:jdk-21-and-23-graal-jammy AS builder
3+
4+
# 작업 디렉토리 설정
5+
WORKDIR /app
6+
7+
# 소스 코드와 Gradle 래퍼 복사
8+
COPY build.gradle .
9+
COPY settings.gradle .
10+
11+
# 종속성 설치
12+
RUN gradle dependencies --no-daemon
13+
14+
# 소스 코드 복사
15+
COPY .env .
16+
COPY src src
17+
18+
# 애플리케이션 빌드
19+
RUN gradle build --no-daemon
20+
21+
# 두 번째 스테이지: 실행 스테이지
22+
FROM container-registry.oracle.com/graalvm/jdk:21
23+
24+
# 작업 디렉토리 설정
25+
WORKDIR /app
26+
27+
# 첫 번째 스테이지에서 빌드된 JAR 파일 복사
28+
COPY --from=builder /app/build/libs/*.jar app.jar
29+
COPY --from=builder /app/.env .env
30+
31+
# 실행할 JAR 파일 지정
32+
ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-jar", "app.jar"]

infra/.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
.idea
2-
.terraform
2+
.terraform
3+
.terraform.lock.hcl
4+
terraform.tfstate
5+
terraform.tfstate.backup
6+
.terraform.tfstate.lock.info
7+
secrets.tf

0 commit comments

Comments
 (0)