From 1d45d1b1de01c1aa91dc3a2b4549c26a5ee5bbe9 Mon Sep 17 00:00:00 2001 From: Sumin Hwang <163857590+tnals0924@users.noreply.github.com> Date: Tue, 20 May 2025 13:39:56 +0900 Subject: [PATCH] =?UTF-8?q?deploy(#97):=20=EA=B0=9C=EB=B0=9C=EB=B2=84?= =?UTF-8?q?=EC=A0=84=20=EC=84=9C=EB=B2=84=20=EB=B0=B0=ED=8F=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-cd_dev.yml | 68 ++++++++++++++++++ .../workflows/{ci-cd.yml => ci-cd_prod.yml} | 2 +- Dockerfile-dev | 10 +++ src/main/resources/application-dev.yml | 70 +++++++++++++++++++ 4 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci-cd_dev.yml rename .github/workflows/{ci-cd.yml => ci-cd_prod.yml} (97%) create mode 100644 Dockerfile-dev create mode 100644 src/main/resources/application-dev.yml diff --git a/.github/workflows/ci-cd_dev.yml b/.github/workflows/ci-cd_dev.yml new file mode 100644 index 0000000..5b32541 --- /dev/null +++ b/.github/workflows/ci-cd_dev.yml @@ -0,0 +1,68 @@ +name: Development Server CI/CD with Gradle and Docker + +on: + push: + branches: [ "develop" ] + pull_request: + branches: [ "develop" ] + +jobs: + build-docker-image: + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Create Firebase Config Directory + run: | + mkdir -p src/main/resources/firebase + echo "${{ secrets.FIREBASE_SERVICE_KEY }}" | base64 --decode > src/main/resources/firebase/firebaseServiceKey.json + shell: bash + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 + + - name: Build with Gradle Wrapper + run: ./gradlew clean build -x test + + # Docker 관련 작업들은 push 시에만 실행되도록 설정 + - name: docker image build + if: github.event_name == 'push' + run: docker build -f Dockerfile-dev -t ${{ secrets.DOCKER_USERNAME }}/billilge-dev:latest . + + # DockerHub 로그인 + - name: docker login + if: github.event_name == 'push' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + # Docker Hub 이미지 푸시 + - name: docker Hub push + if: github.event_name == 'push' + run: docker push ${{ secrets.DOCKER_USERNAME }}/billilge-dev:latest + + run-docker-image-on-ec2: + needs: build-docker-image + #push 했을 때만 배포가 진행되도록 + if: github.event_name == 'push' + runs-on: self-hosted + steps: + - name: docker pull + run: sudo docker pull ${{ secrets.DOCKER_USERNAME }}/billilge-dev:latest + + - name: docker stop container + run: sudo docker stop springboot || true + + - name: docker run new container + run: sudo docker run --env-file /home/ubuntu/billilge.env --name springboot --rm -d -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/billilge-dev:latest + + - name: delete old docker image + run: sudo docker image prune -f \ No newline at end of file diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd_prod.yml similarity index 97% rename from .github/workflows/ci-cd.yml rename to .github/workflows/ci-cd_prod.yml index 41854b3..ee3bae9 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd_prod.yml @@ -1,4 +1,4 @@ -name: CI/CD with Gradle and Docker +name: Production Server CI/CD with Gradle and Docker on: push: diff --git a/Dockerfile-dev b/Dockerfile-dev new file mode 100644 index 0000000..3721652 --- /dev/null +++ b/Dockerfile-dev @@ -0,0 +1,10 @@ +# Dockerfile + +# jdk17 Image Start +FROM openjdk:17 + +# jar 파일 복제 +COPY build/libs/*.jar app.jar + +# 실행 명령어 +ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul", "-Dspring.profiles.active=dev", "-jar", "app.jar"] \ No newline at end of file diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000..dbdc010 --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,70 @@ +spring: + application: + name: backend + + datasource: + url: jdbc:mysql://${DEV_DB_URL}?useSSL=false&serverTimezone=Asia/Seoul&characterEncoding=UTF-8&allowPublicKeyRetrieval=true + driver-class-name: com.mysql.cj.jdbc.Driver + username: ${DEV_DB_USERNAME} + password: ${DEV_DB_PASSWORD} + + security: + oauth2: + client: + registration: + # 구글 로그인 추가 + google: + client-id: ${DEV_OAUTH2_GOOGLE_CLIENT_ID} + client-secret: ${DEV_OAUTH2_GOOGLE_CLIENT_SECRET} + scope: + - email + - profile + jpa: + properties: + hibernate: + format_sql: true + dialect: org.hibernate.dialect.MySQLDialect + dialect.storage_engine: innodb + show-sql: true + hibernate: + ddl-auto: update + + servlet: + multipart: + max-file-size: 5MB + max-request-size: 10MB + resolve-lazily: true + + +jwt: + secret_key: ${DEV_JWT_SECRET_KEY} + issuer: ${DEV_JWT_ISSUER} + +login: + admin-password: ${DEV_LOGIN_ADMIN_PASSWORD} + redirect: + url: ${DEV_LOGIN_REDIRECT_URL} + +cors: + allowed-origins: ${DEV_CORS_ALLOWED_ORIGINS} + +exam-period: + start-date: ${DEV_EXAM_PERIOD_START_DATE} + end-date: ${DEV_EXAM_PERIOD_END_DATE} + +cloud: + aws: + s3: + bucket: ${DEV_S3_BUCKET} + base-url: ${DEV_S3_BASE_URL} + credentials: + access-key: ${DEV_S3_ACCESS_KEY} + secret-key: ${DEV_S3_SECRET_KEY} + region: + static: us-west-2 + stack: + auto: false + +swagger: + server: + base-url: ${DEV_SWAGGER_SERVER_BASE_URL} \ No newline at end of file