forked from kookmin-sw/cap-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: main, feature 브랜치-> GitHub actions 연동
- Loading branch information
Showing
3 changed files
with
114 additions
and
22 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Build for feature branch | ||
|
||
on: | ||
push: | ||
branches: | ||
- feature/* | ||
pull_request: | ||
branches: | ||
- feature/* | ||
|
||
permissions: | ||
contents: read | ||
|
||
|
||
jobs: | ||
build_only: | ||
runs-on: ubuntu-latest # ubuntu 최신 버전에서 script를 실행 | ||
|
||
steps: | ||
|
||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: "adopt" | ||
|
||
- name: Make application.properties | ||
run: | | ||
cd ./server/src/main/resources | ||
touch ./application.properties | ||
echo "${{ secrets.PROPERTIES }}" > ./application.properties | ||
shell: bash | ||
|
||
# gradle을 통해 소스를 빌드. | ||
- name: Build with Gradle | ||
run: | | ||
cd server | ||
chmod +x ./gradlew | ||
./gradlew clean build -x test | ||
- name: Docker build | ||
run: | | ||
cd server | ||
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }}:latest . |
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,61 @@ | ||
name: Build And Deploy for main branch | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: "adopt" | ||
|
||
- name: Make application.properties | ||
run: | | ||
cd ./server/src/main/resources | ||
touch ./application.properties | ||
echo "${{ secrets.PROPERTIES }}" > ./application.properties | ||
shell: bash | ||
|
||
- name: Build with Gradle | ||
run: | | ||
cd server | ||
chmod +x ./gradlew | ||
./gradlew clean build -x test | ||
- name: Docker build & push to docker repo | ||
run: | | ||
cd server | ||
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }}:latest . | ||
docker push ${{ secrets.DOCKER_REPO }}:latest | ||
pull-and-deploy: | ||
needs: build-and-push | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Pull & Deploy to server | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.EC2_PUBLIC_IP }} | ||
username: ubuntu | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
envs: GITHUB_SHA | ||
script: | | ||
sudo docker rm -f $(docker ps -qa) | ||
sudo docker pull ${{ secrets.DOCKER_REPO }}:latest | ||
sudo docker image prune -f | ||
sudo docker run -d --name server -p 80:8080 suhwani/capstone |
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,28 +1,12 @@ | ||
# 첫 번째 단계: Gradle 빌드를 수행하는 이미지를 만듭니다. | ||
FROM gradle:8.5.0-jdk17 AS builder | ||
|
||
# 작업 디렉토리를 설정합니다. | ||
WORKDIR /app | ||
|
||
# Gradle 빌드에 필요한 파일을 복사합니다. | ||
COPY build.gradle . | ||
COPY settings.gradle . | ||
COPY src src | ||
|
||
# 프로젝트를 빌드합니다. | ||
RUN gradle build | ||
|
||
# 두 번째 단계: 빌드된 JAR 파일을 사용하여 최종 이미지를 만듭니다. | ||
FROM bellsoft/liberica-openjdk-alpine:17 | ||
|
||
# 작업 디렉토리를 설정합니다. | ||
WORKDIR /app | ||
# Gradle 빌드 명령 실행 | ||
CMD ["./gradlew", "clean", "build"] | ||
|
||
# 이전 단계에서 빌드된 JAR 파일을 복사합니다. | ||
COPY --from=builder /app/build/libs/*.jar app.jar | ||
# 빌드된 JAR 파일 복사 | ||
ARG JAR_FILE=build/libs/*.jar | ||
COPY ${JAR_FILE} app.jar | ||
|
||
# 사용할 포트를 노출합니다. | ||
EXPOSE 8080 | ||
|
||
# 컨테이너가 시작되었을 때 실행할 명령을 지정합니다. | ||
CMD ["java", "-jar", "app.jar"] | ||
ENTRYPOINT ["java","-jar","/app.jar"] |