-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [chore] : application 환경별 분리 및 firebase gitignore 추가 * [chore] : firebase_account로 파일명 수정 반영 * [chore] : CD 위한 dockerfile 작성 * [chore] : CI 시 firebase_account.json secret에서 가져오도록 수정 * [chore] : CD를 위한 cd.yml 추가 * [refactor] : 배포 스크립트 내 타임존 설정에 따른 Application 내 중복 코드 제거
- Loading branch information
Showing
6 changed files
with
114 additions
and
16 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,90 @@ | ||
name: CD Backend | ||
|
||
on: | ||
push: | ||
branches: [ "main", "dev" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
# 자바 버전 설정 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
# yml 파일 생성 | ||
- name: Generate application-core.yml | ||
run: | | ||
mkdir -p ./core/src/main/resources | ||
echo "${{ secrets.APPLICATION_CORE }}" | base64 -d > ./core/src/main/resources/application-core.yml | ||
# firebase json 파일 생성 | ||
- name : Generate firebase_account.json | ||
run: | | ||
mkdir -p ./core/src/main/resources/firebase | ||
echo "${{ secrets.FIREBASE_ACCOUNT }}" | base64 -d > ./core/src/main/resources/firebase/firebase_account.json | ||
mkdir -p ./core/src/test/resources/firebase | ||
echo "${{ secrets.FIREBASE_ACCOUNT }}" | base64 -d > ./core/src/test/resources/firebase/firebase_account.json | ||
# gradle 권한 부여 | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x ./gradlew | ||
shell: bash | ||
|
||
# 빌드 시 캐시 적용 | ||
- name: Gradle Caching | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
# 빌드 | ||
- name: Build with Gradle | ||
run: ./gradlew build -x test | ||
|
||
|
||
# 도커 허브 로그인 | ||
- name: Docker Hub Login | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
|
||
# 도커 이미지 빌드 및 푸시 | ||
- name: docker image build and push | ||
run: | | ||
docker build -f Dockerfile -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_APP_NAME }} . | ||
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_APP_NAME }} | ||
# 서버 백그라운드 실행 | ||
- name: pull image and run container | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ${{ secrets.EC2_USERNAME }} | ||
password: ${{ secrets.EC2_PASSWORD }} | ||
port: ${{ secrets.EC2_PORT }} | ||
script: | | ||
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_APP_NAME }} | ||
docker stop ${{ secrets.DOCKERHUB_APP_NAME }} | ||
docker rm ${{ secrets.DOCKERHUB_APP_NAME }} | ||
docker run -d \ | ||
-p 8080:8080 \ | ||
-e TZ=Asia/Seoul \ | ||
--name ${{ secrets.DOCKERHUB_APP_NAME }} \ | ||
${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_APP_NAME }} | ||
docker system prune -f |
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
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
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,4 @@ | ||
FROM openjdk:17-jdk | ||
ARG JAR_FILE=api/build/libs/*.jar | ||
COPY ${JAR_FILE} app.jar | ||
ENTRYPOINT ["java", "-jar", "/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
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