From 52f432b3e8000216e4cb50b57c47ddeb9c323133 Mon Sep 17 00:00:00 2001 From: Jiyun Date: Sun, 4 Jan 2026 09:44:57 +0900 Subject: [PATCH] =?UTF-8?q?#150=20Feat:=20=EA=B3=B5=ED=86=B5=20CI/CD=20pip?= =?UTF-8?q?eline=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd.yml | 19 +++++++++ .github/workflows/ci.yml | 18 +++++++++ .github/workflows/deploy.yml | 78 ------------------------------------ 3 files changed, 37 insertions(+), 78 deletions(-) create mode 100644 .github/workflows/cd.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..e384c23 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,19 @@ +name: Spring Boot & Gradle CD + +on: + push: + branches: [ "main" ] + +jobs: + cd: + uses: kjiyun/CI-CD-pipeline-standard/.github/workflows/java-gradle-cd.yml@master + with: + java-version: "17" + distribution: "temurin" + image-name: memesphere-app + secrets: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + HOST_ID: ${{ secrets.EC2_HOST }} + USERNAME: ${{ secrets.EC2_USERNAME }} + PRIVATE_KEY: ${{ secrets.EC2_SSH_KEY }} \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..26b35ce --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +name: Spring Boot & Gradle CI + +on: + pull_request: + branches: [ "main" ] + +jobs: + ci: + uses: kjiyun/CI-CD-pipeline-standard/.github/workflows/java-gradle-ci.yml@master + with: + java-version: "17" + distribution: "temurin" + build-command: "false" + test-command: "false" + upload-artifacts: true + write-application-yml: true + secrets: + APPLICATION: ${{ secrets.APPLICATION_YML }} \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index c81c569..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,78 +0,0 @@ -name: CI/CD Pipeline with Docker - -on: - push: - branches: [ develop ] # develop 브랜치에 push 발생 시 실행 - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '17' - cache: 'gradle' - - - name: Create application.yml - run: | - mkdir -p src/main/resources - cat < src/main/resources/application.yml - ${{ secrets.APPLICATION_YML }} - EOF - shell: bash - - - name: Build with Gradle - run: | - chmod +x gradlew - ./gradlew bootJar - - - name: Login to DockerHub - run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin - - - name: Build and push Docker image - run: | - docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ vars.MY_APP }}:latest . - docker push ${{ secrets.DOCKER_USERNAME }}/${{ vars.MY_APP }}:latest - - deploy: - needs: build - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Deploy to EC2 - env: - EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }} - EC2_USERNAME: ${{ secrets.EC2_USERNAME }} - EC2_HOST: ${{ secrets.EC2_HOST }} - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - MY_APP: ${{ vars.MY_APP }} - run: | - echo "$EC2_SSH_KEY" > private_key.pem - chmod 600 private_key.pem - - mkdir -p ~/.ssh - ssh-keyscan -H $EC2_HOST >> ~/.ssh/known_hosts - chmod 600 ~/.ssh/known_hosts - - # EC2로 docker-compose.yml 복사 - scp -i private_key.pem docker-compose.yml $EC2_USERNAME@$EC2_HOST:/home/$EC2_USERNAME/docker-compose.yml - - ssh -i private_key.pem -o StrictHostKeyChecking=no $EC2_USERNAME@$EC2_HOST " - docker pull $DOCKER_USERNAME/$MY_APP:latest - - docker-compose down || true - - docker-compose up -d --remove-orphans - docker image prune -f - " - - rm -f private_key.pem