Skip to content

Commit e983f9f

Browse files
committed
feat: 테스트 환경변수 추가 및 CI/CD 구축
1 parent 1fc54f4 commit e983f9f

File tree

5 files changed

+117
-2
lines changed

5 files changed

+117
-2
lines changed

.github/workflows/deploy.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Github Repository 파일 불러오기
13+
uses: actions/checkout@v4
14+
15+
- name: JDK 21버전 설치
16+
uses: actions/setup-java@v4
17+
with:
18+
distribution: temurin
19+
java-version: 21
20+
21+
- name: Gradle 캐싱
22+
uses: actions/cache@v4
23+
with:
24+
path: |
25+
~/.gradle/caches
26+
~/.gradle/wrapper
27+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
28+
restore-keys: |
29+
${{ runner.os }}-gradle-
30+
31+
- name: 운영용 .properties로 교체
32+
run: echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./src/main/resources/application.properties
33+
34+
- name: 테스트 환경변수 주입
35+
run: echo "${{ secrets.APPLICATION_TEST_PROPERTIES }}" > ./src/test/resources/application.properties
36+
37+
- name: 테스트 및 빌드하기
38+
run: ./gradlew clean build
39+
40+
- name: AWS Resource에 접근할 수 있게 AWS credentials 설정
41+
uses: aws-actions/configure-aws-credentials@v4
42+
with:
43+
aws-region: ap-northeast-2
44+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
45+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
46+
47+
- name: ECR에 로그인하기
48+
id: login-ecr
49+
uses: aws-actions/amazon-ecr-login@v2
50+
51+
- name: Docker 이미지 생성
52+
run: docker build --platform linux/amd64 -t music .
53+
54+
- name : Docker tag를 위한 날짜 설정
55+
run: echo "date=$(date +%Y%m%d-%H%M%S)" >> $GITHUB_ENV
56+
57+
- name: Docker 이미지에 Tag 붙이기
58+
run: docker tag music ${{ steps.login-ecr.outputs.registry }}/music:${{env.date}}
59+
60+
- name: ECR에 Docker 이미지 Push하기
61+
run: docker push ${{ steps.login-ecr.outputs.registry }}/music:${{env.date}}
62+
63+
- name: SSH로 EC2에 접속하기
64+
uses: appleboy/[email protected]
65+
with:
66+
host: ${{ secrets.EC2_HOST }}
67+
username: ${{ secrets.EC2_USERNAME }}
68+
key: ${{ secrets.EC2_PRIVATE_KEY }}
69+
script_stop: true
70+
script: |
71+
docker pull ${{ steps.login-ecr.outputs.registry }}/music:${{env.date}}
72+
docker stop music || true
73+
docker rm music || true
74+
docker run -d --name music -p 8080:8080 ${{ steps.login-ecr.outputs.registry }}/music:${{env.date}}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ out/
3636
### VS Code ###
3737
.vscode/
3838

39-
.env
39+
.env
40+
src/main/resources/application-prod.properties
41+
src/test/resources/application-prod.properties

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM eclipse-temurin:21-jdk-alpine
2+
COPY ./build/libs/*SNAPSHOT.jar /project.jar
3+
ENTRYPOINT ["java", "-jar", "/project.jar"]

src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ spring.security.oauth2.client.provider.kakao.user-name-attribute=id
3333

3434

3535
spring.jwt.secret=${JWT_KEY}
36-
spring.secretBase64=${SECRET_BASE64}
36+
spring.secretBase64=${SECRET_BASE64}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
spring.config.import=optional:file:.env[.properties]
2+
spring.application.name=team5
3+
4+
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
5+
spring.datasource.url=jdbc:mysql://localhost:3306/killing_point_test?useSSL=false&useUnicode=true&serverTimezone=Asia/Seoul&allowPublicKeyRetrieval=true
6+
spring.datasource.username=root
7+
spring.datasource.password=${SQL_PW}
8+
9+
spring.jpa.hibernate.ddl-auto=create-drop
10+
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
11+
spring.jpa.show-sql=true
12+
13+
#oauth2 : google
14+
spring.security.oauth2.client.registration.google.client-name=google
15+
spring.security.oauth2.client.registration.google.client-id=${GOOGLE_ID}
16+
spring.security.oauth2.client.registration.google.client-secret=${GOOGLE_SECRET}
17+
spring.security.oauth2.client.registration.google.redirect-uri=http://10.0.2.2:8080/login/oauth2/code/google
18+
spring.security.oauth2.client.registration.google.authorization-grant-type=authorization_code
19+
spring.security.oauth2.client.registration.google.scope=profile,email
20+
21+
#oauth2 : kakao
22+
spring.security.oauth2.client.registration.kakao.client-name=kakao
23+
spring.security.oauth2.client.registration.kakao.client-id=${KAKAO_ID}
24+
spring.security.oauth2.client.registration.kakao.client-secret=${KAKAO_SECRET}
25+
spring.security.oauth2.client.registration.kakao.client-authentication-method=client_secret_post
26+
spring.security.oauth2.client.registration.kakao.authorization-grant-type=authorization_code
27+
spring.security.oauth2.client.registration.kakao.redirect-uri=http://10.0.2.2:8080/login/oauth2/code/kakao
28+
spring.security.oauth2.client.registration.kakao.scope=profile_nickname,account_email
29+
spring.security.oauth2.client.provider.kakao.authorization-uri=https://kauth.kakao.com/oauth/authorize
30+
spring.security.oauth2.client.provider.kakao.token-uri=https://kauth.kakao.com/oauth/token
31+
spring.security.oauth2.client.provider.kakao.user-info-uri=https://kapi.kakao.com/v2/user/me
32+
spring.security.oauth2.client.provider.kakao.user-name-attribute=id
33+
34+
35+
spring.jwt.secret=${JWT_KEY}
36+
spring.secretBase64=${SECRET_BASE64}

0 commit comments

Comments
 (0)