-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Project : CI/CD using docker hub
- Loading branch information
1 parent
d13a962
commit 862e967
Showing
4 changed files
with
43 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,32 @@ | ||
name: CI/CD Pipeline for Spring Boot with Gradle | ||
name: Build and Push Docker Image | ||
|
||
on: | ||
push: | ||
branches: | ||
- main # 또는 배포하려는 브랜치 | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_TOKEN }} | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x ./gradlew | ||
- name: Build Docker Image | ||
run: | | ||
docker build -t a-neuk-server:latest . | ||
- name: Build with Gradle | ||
run: ./gradlew build | ||
- name: Tag Docker Image | ||
run: | | ||
docker tag a-neuk-server:latest minseok128/a-neuk-server:release1 | ||
- name: Upload Artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: spring-boot-app | ||
path: build/libs/*.jar # Gradle의 빌드 아웃풋 경로 | ||
|
||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
steps: | ||
- name: Download Artifacts | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: spring-boot-app | ||
|
||
- name: Deploy to EC2 | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ec2-user | ||
key: ${{ secrets.EC2_KEY }} # SSH 접근을 위한 개인 키 | ||
script: | | ||
/home/ec2-user/Aneuk/A-Neuk-BE-Server/deploy.sh | ||
- name: Push Docker Image to Docker Hub | ||
run: | | ||
docker push minseok128/a-neuk-server:release1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# 1. Java 17의 OpenJDK 이미지 사용 | ||
FROM openjdk:17-jdk-slim | ||
|
||
# 2. 작업 디렉토리 생성 및 설정 | ||
WORKDIR /app | ||
|
||
# 3. build.gradle, gradlew, 그리고 필요한 파일 복사 | ||
COPY build.gradle /app/ | ||
COPY gradlew /app/ | ||
COPY gradle /app/gradle | ||
COPY src /app/src | ||
|
||
# 4. gradlew에 실행 권한 부여 및 Gradle로 프로젝트 빌드 | ||
RUN chmod +x ./gradlew | ||
RUN ./gradlew bootJar | ||
RUN mv build/libs/*.jar build/libs/app.jar | ||
|
||
# 5. 빌드 결과를 어플리케이션으로 설정 | ||
EXPOSE 8080 | ||
ENTRYPOINT ["java", "-jar", "build/libs/app.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ plugins { | |
} | ||
|
||
group = 'com.example' | ||
version = '0.0.1-SNAPSHOT' | ||
version = 'release1' | ||
|
||
java { | ||
toolchain { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters