diff --git a/.github/workflows/dev-ci.yml b/.github/workflows/ci.yml similarity index 96% rename from .github/workflows/dev-ci.yml rename to .github/workflows/ci.yml index 22dd4a9f..3c0fd3e9 100644 --- a/.github/workflows/dev-ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ name: CI for dev using github actions on: pull_request: types: [opened, synchronize] - branches: [ "develop" ] + branches: [ "develop", "release" ] permissions: contents: read diff --git a/.github/workflows/create-jira-bug-issue.yml b/.github/workflows/create-jira-bug-issue.yml index 7135dbb1..0f569bda 100644 --- a/.github/workflows/create-jira-bug-issue.yml +++ b/.github/workflows/create-jira-bug-issue.yml @@ -74,10 +74,10 @@ jobs: - name: Log created issue run: echo "Jira Issue ${{ steps.issue-parser.outputs.parentKey }}/${{ steps.create.outputs.issue }} was created" - - name: Checkout develop code + - name: Checkout release code uses: actions/checkout@v4 with: - ref: develop + ref: release token: ${{ secrets.PAT_TOKEN }} - name: Create branch with Ticket number diff --git a/.github/workflows/dev-cd.yml b/.github/workflows/dev-cd.yml index ababe2a1..2975ba26 100644 --- a/.github/workflows/dev-cd.yml +++ b/.github/workflows/dev-cd.yml @@ -65,4 +65,4 @@ jobs: docker run --name taskflow -d -p 9090:9090 \ --env-file /home/ubuntu/.env \ ${{ secrets.DOCKER_REPO }} \ - --restart on-failure + --restart on-failure \ No newline at end of file diff --git a/.github/workflows/release-cd.yml b/.github/workflows/release-cd.yml new file mode 100644 index 00000000..3965710f --- /dev/null +++ b/.github/workflows/release-cd.yml @@ -0,0 +1,72 @@ +# github repository actions 페이지에 나타날 이름 +name: CD for Release + +# event trigger +on: + release: + types: [created] + +permissions: + contents: read + +jobs: + Release-CD: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: 'Set up JDK' + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Extract release version + id: version + run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + + - 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 + - name: Docker build & push + run: | + docker login clap.kr-central-2.kcr.dev -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -t ${{ secrets.DOCKER_REPO }}:${{ steps.version.outputs.VERSION }} -t ${{ secrets.DOCKER_REPO }}:latest . + docker push ${{ secrets.DOCKER_REPO }}:${{ steps.version.outputs.VERSION }} + docker push ${{ secrets.DOCKER_REPO }}:latest + + # deploy + - name: Deploy + 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 }}:${{ steps.version.outputs.VERSION }} -f + docker run --name taskflow -d -p 9090:9090 \ + --env-file /home/ubuntu/.env \ + ${{ secrets.DOCKER_REPO }}:${{ steps.version.outputs.VERSION }} \ + --restart on-failure +