diff --git a/.github/workflows/ci-cd-prod.yml b/.github/workflows/ci-cd-prod.yml new file mode 100644 index 00000000..e69de29b diff --git a/.github/workflows/dev-cd.yml b/.github/workflows/dev-cd.yml index 1522f947..b90f1aab 100644 --- a/.github/workflows/dev-cd.yml +++ b/.github/workflows/dev-cd.yml @@ -1,44 +1,65 @@ -## github repository actions 페이지에 나타날 이름 -#name: CD to dev using github actions -# -## event trigger -## develop 브랜치에 pull_request가 닫혔을 때 실행 -#on: -# pull_request: -# types: [ closed ] -# branches: [ "develop" ] -# -#permissions: -# contents: read -# -#jobs: -# DEV-CD: -# if: github.event.pull_request.merged == true -# runs-on: ubuntu-latest -# steps: -# - name: Download build artifacts -# uses: actions/download-artifact@v4 -# with: -# name: build-artifacts -# github-token: ${{ secrets.GH_TOKEN }} -# -# ## docker build & push to production -# - name: Docker build & push to prod -# run: | -# docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} -# docker build -t ${{ secrets.DOCKER_REPO }} . -# docker push ${{ secrets.DOCKER_REPO }} -# -# ## deploy to dev -# - name: Deploy to prod -# uses: appleboy/ssh-action@master -# id: deploy -# with: -# host: ${{ secrets.DEV_HOST }} -# username: ${{ secrets.DEV_HOST_USERNAME }} -# key: ${{ secrets.DEV_HOST_KEY }} -# port: ${{ secrets.DEV_HOST_PORT }} -# script: | -# docker rm -f taskflow -# docker image rm ${{ secrets.DOCKER_REPO }} -f -# docker run --name taskflow --network host -d -p 8080:8080 ${{ secrets.DOCKER_REPO }} --restart on-failure +# github repository actions 페이지에 나타날 이름 +name: CD to dev using github actions + +# event trigger +# develop 브랜치에 pull_request가 닫혔을 때 실행 +on: + pull_request: + types: [ closed ] + branches: [ "develop" ] + +permissions: + contents: read + +jobs: + DEV-CD: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: 'Set up jdk' + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' # https://github.com/actions/setup-java + + - run: touch ./Dockerfile + - run: echo "${{ secrets.DEV_DOCKERFILE }}" > ./Dockerfile + + # gradle caching - 빌드 시간 향상 + - name: Gradle Caching + uses: actions/cache@v4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + ## gradle build + - name: Build with Gradle + run: | + chmod +x ./gradlew + ./gradlew build -x test + + ## docker build & push to production + - name: Docker build & push to dev + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -t ${{ secrets.DOCKER_REPO }} . + docker push ${{ secrets.DOCKER_REPO }} + + ## deploy to dev + - name: Deploy to prod + uses: appleboy/ssh-action@master + id: deploy + with: + host: ${{ secrets.DEV_HOST }} + username: ${{ secrets.DEV_HOST_USERNAME }} + key: ${{ secrets.DEV_HOST_KEY }} + port: ${{ secrets.DEV_HOST_PORT }} + script: | + docker rm -f taskflow + docker image rm ${{ secrets.DOCKER_REPO }} -f + docker run --name taskflow --network host -d -p 8080:8080 ${{ secrets.DOCKER_REPO }} --restart on-failure \ No newline at end of file diff --git a/.github/workflows/dev-ci.yml b/.github/workflows/dev-ci.yml index 5034f91b..6d89c9bc 100644 --- a/.github/workflows/dev-ci.yml +++ b/.github/workflows/dev-ci.yml @@ -1,11 +1,11 @@ # github repository actions 페이지에 나타날 이름 -name: CI/CD to dev using github actions +name: CI for dev using github actions # event trigger # develop 브랜치에 pull_request가 열렸을 때 실행 on: pull_request: - types: [opened, synchronize, closed] + types: [opened, synchronize] branches: [ "develop" ] permissions: @@ -23,9 +23,6 @@ jobs: java-version: '17' distribution: 'temurin' # https://github.com/actions/setup-java - - run: touch ./Dockerfile - - run: echo "${{ secrets.DEV_DOCKERFILE }}" > ./Dockerfile - # gradle caching - 빌드 시간 향상 - name: Gradle Caching uses: actions/cache@v4 @@ -42,37 +39,3 @@ jobs: run: | chmod +x ./gradlew ./gradlew build - - - name: Upload build artifacts - uses: actions/upload-artifact@v4 - with: - name: build-artifacts - path: build/libs/*.jar - - DEV-CD: - if: github.event.action == 'closed' && github.event.pull_request.merged == true - runs-on: ubuntu-latest - steps: - - name: Download build artifacts - uses: actions/download-artifact@v4 - with: - name: build-artifacts - github-token: ${{ secrets.GH_TOKEN }} - - - name: Docker build & push to prod - run: | - docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} - docker build -t ${{ secrets.DOCKER_REPO }} . - docker push ${{ secrets.DOCKER_REPO }} - - - name: Deploy to dev - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.DEV_HOST }} - username: ${{ secrets.DEV_HOST_USERNAME }} - key: ${{ secrets.DEV_HOST_KEY }} - port: ${{ secrets.DEV_HOST_PORT }} - script: | - docker rm -f taskflow || true - docker image rm ${{ secrets.DOCKER_REPO }} -f || true - docker run --name taskflow --network host -d -p 8080:8080 ${{ secrets.DOCKER_REPO }} --restart on-failure \ No newline at end of file