Skip to content

Commit 397ae84

Browse files
authored
Merge pull request #43 from TeamMemeSphere/develop
#29 Feat: CICD 구축
2 parents 3ffef13 + 216560b commit 397ae84

File tree

22 files changed

+423
-73
lines changed

22 files changed

+423
-73
lines changed

.github/workflows/deploy.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: CI/CD Pipeline with Docker
2+
3+
on:
4+
push:
5+
branches: [ develop ] # develop 브랜치에 push 발생 시 실행
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
15+
- name: Set up JDK 17
16+
uses: actions/setup-java@v4
17+
with:
18+
distribution: 'temurin'
19+
java-version: '17'
20+
cache: 'gradle'
21+
22+
- name: Create application.yml
23+
run: |
24+
mkdir -p src/main/resources
25+
cat <<EOF > src/main/resources/application.yml
26+
${{ secrets.APPLICATION_YML }}
27+
EOF
28+
shell: bash
29+
30+
- name: Build with Gradle
31+
run: |
32+
chmod +x gradlew
33+
./gradlew bootJar
34+
35+
- name: Login to DockerHub
36+
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
37+
38+
- name: Build and push Docker image
39+
run: |
40+
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ vars.MY_APP }}:latest .
41+
docker push ${{ secrets.DOCKER_USERNAME }}/${{ vars.MY_APP }}:latest
42+
43+
deploy:
44+
needs: build
45+
runs-on: ubuntu-latest
46+
47+
steps:
48+
- name: Deploy to EC2
49+
env:
50+
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
51+
EC2_USERNAME: ${{ secrets.EC2_USERNAME }}
52+
EC2_HOST: ${{ secrets.EC2_HOST }}
53+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
54+
MY_APP: ${{ vars.MY_APP }}
55+
run: |
56+
echo "$EC2_SSH_KEY" > private_key.pem
57+
chmod 600 private_key.pem
58+
59+
ssh -i private_key.pem -o StrictHostKeyChecking=no $EC2_USERNAME@$EC2_HOST "
60+
docker pull $DOCKER_USERNAME/$MY_APP:latest
61+
docker stop $MY_APP || true
62+
docker rm $MY_APP || true
63+
docker run -d -p 8080:8080 --name $MY_APP \
64+
$DOCKER_USERNAME/$MY_APP:latest
65+
"
66+
67+
rm -f private_key.pem

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Build stage
2+
FROM bellsoft/liberica-openjdk-alpine:17 AS builder
3+
4+
WORKDIR /app
5+
6+
COPY gradlew build.gradle settings.gradle /app/
7+
COPY gradle /app/gradle
8+
RUN chmod +x gradlew
9+
RUN ./gradlew dependencies --no-daemon
10+
11+
COPY . .
12+
RUN ./gradlew clean build -x test --no-daemon
13+
14+
# Run stage
15+
FROM bellsoft/liberica-openjdk-alpine:17
16+
17+
WORKDIR /app
18+
19+
# JAR 파일 복사
20+
COPY --from=builder /app/build/libs/*.jar app.jar
21+
22+
# 필요한 리소스 파일 복사
23+
COPY src/main/resources/application.yml /app/config/application.yml
24+
25+
EXPOSE 8080
26+
27+
# Spring Boot가 설정 파일을 읽도록 환경 변수 설정
28+
ENTRYPOINT ["java", "-jar", "app.jar"]
29+
CMD ["--spring.config.location=file:/app/config/application.yml"]

src/main/java/com/memesphere/binance/service/BinanceQueryService.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/main/java/com/memesphere/chat/repository/ChatCustomRepository.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/main/java/com/memesphere/binance/dto/response/BinanceTickerResponse.java renamed to src/main/java/com/memesphere/domain/binance/dto/response/BinanceTickerResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.memesphere.binance.dto.response;
1+
package com.memesphere.domain.binance.dto.response;
22

33
import lombok.Data;
44

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.memesphere.domain.binance.service;
2+
3+
import com.memesphere.domain.binance.dto.response.BinanceTickerResponse;
4+
5+
public interface BinanceQueryService {
6+
BinanceTickerResponse getTickerData(String symbol);
7+
}

src/main/java/com/memesphere/binance/service/BinanceQueryServiceImpl.java renamed to src/main/java/com/memesphere/domain/binance/service/BinanceQueryServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package com.memesphere.binance.service;
1+
package com.memesphere.domain.binance.service;
22

3-
import com.memesphere.binance.dto.response.BinanceTickerResponse;
3+
import com.memesphere.domain.binance.dto.response.BinanceTickerResponse;
44
import lombok.RequiredArgsConstructor;
55
import org.springframework.stereotype.Service;
66
import org.springframework.transaction.annotation.Transactional;

src/main/java/com/memesphere/domain/chartdata/converter/ChartDataConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.memesphere.domain.chartdata.converter;
22

3-
import com.memesphere.binance.dto.response.BinanceTickerResponse;
3+
import com.memesphere.domain.binance.dto.response.BinanceTickerResponse;
44
import com.memesphere.domain.chartdata.entity.ChartData;
55
import com.memesphere.domain.memecoin.entity.MemeCoin;
66

src/main/java/com/memesphere/domain/chartdata/scheduler/ChartDataScheduler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.memesphere.domain.chartdata.scheduler;
22

3-
import com.memesphere.binance.dto.response.BinanceTickerResponse;
4-
import com.memesphere.binance.service.BinanceQueryService;
3+
import com.memesphere.domain.binance.dto.response.BinanceTickerResponse;
4+
import com.memesphere.domain.binance.service.BinanceQueryService;
55
import com.memesphere.domain.chartdata.entity.ChartData;
66
import com.memesphere.global.apipayload.code.status.ErrorStatus;
77
import com.memesphere.global.apipayload.exception.GeneralException;

src/main/java/com/memesphere/domain/memecoin/MemeCoinInitializer.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)