From f9919f7da2a6497a29558e3f37aceed63d01ea6d Mon Sep 17 00:00:00 2001 From: yudonggeun Date: Wed, 11 Dec 2024 16:41:27 +0900 Subject: [PATCH] =?UTF-8?q?chore=20:=20workflow=20=EC=9C=84=EC=B9=98=20?= =?UTF-8?q?=EB=B0=8F=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit chore : frontend ci workflow 추가 fix : 최신 배포인 경우에만 build 실행 chore : 통합 ci workflow 제거 fix : user ci 수정 컨테이너 이미지 갱신시 user 서비스만 갱신되도록 변경 fix : server ci 수정 CI 작업 이후 배포 이미지 버전 명시 오류 수정 chore : ci workflow 분리 - auth microservice를 위한 배포 잡을 분리합니다. - 특정 버전으로 롤백할 수 있도록 지원합니다. - 자동으로 실행되지 않고 수동으로 실행합니다. chore : ci workflow 분리 - user microservice를 위한 배포 잡을 분리합니다. - 특정 버전으로 롤백할 수 있도록 지원합니다. - 자동으로 실행되지 않고 수동으로 실행합니다. chore : ci workflow 분리 - server microservice를 위한 배포 잡을 분리합니다. - 특정 버전으로 롤백할 수 있도록 지원합니다. - 자동으로 실행되지 않고 수동으로 실행합니다. --- .github/workflows/ci_auth.yml | 82 +++++++++++++++++++++ .github/workflows/ci_front.yml | 70 ++++++++++++++++++ .github/workflows/{ci.yml => ci_server.yml} | 45 ++++++----- .github/workflows/ci_user.yml | 82 +++++++++++++++++++++ 4 files changed, 256 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/ci_auth.yml create mode 100644 .github/workflows/ci_front.yml rename .github/workflows/{ci.yml => ci_server.yml} (57%) create mode 100644 .github/workflows/ci_user.yml diff --git a/.github/workflows/ci_auth.yml b/.github/workflows/ci_auth.yml new file mode 100644 index 00000000..c5af030a --- /dev/null +++ b/.github/workflows/ci_auth.yml @@ -0,0 +1,82 @@ +name: Auth micro service CI + +on: + workflow_dispatch: + inputs: + version: + description: '배포하고자 하는 버전을 입력해주세요. 최신 버전이라면 생략해주세요. (git commit id 앞 8자리)' + default: 'latest' + +jobs: + build: + if: github.event.inputs.version == 'latest' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + name: checkout + run: git checkout ${{ github.event.inputs.version }} + + - name: set up jdk 21 + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '21' + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: make api documents + run: ./gradlew --info auth:openapi3 + + - name: configure openapi3 spec + run: | + yq eval -i '.components.securitySchemes.bearerAuth.type = "http"' ./auth/src/main/resources/static/openapi3.yaml + yq eval -i '.components.securitySchemes.bearerAuth.scheme = "bearer"' ./auth/src/main/resources/static/openapi3.yaml + yq eval -i '.components.securitySchemes.bearerAuth.bearerFormat = "JWT"' ./auth/src/main/resources/static/openapi3.yaml + yq eval -i '.security[0].bearerAuth = []' ./auth/src/main/resources/static/openapi3.yaml + + - name: push image using jib + run: ./gradlew --info auth:jib + + tagging: + needs: + - build + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + + - if: github.event.inputs.version != 'latest' + name: checkout + run: git checkout ${{ github.event.inputs.version }} + + - name: set image tag + run: | + echo "IMAGE_TAG=$(git rev-parse --short=8 HEAD)" >> $GITHUB_ENV + + - name: checkout infra repository + uses: actions/checkout@v4 + with: + repository: kSideProject/kpring-infra + ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} + ref: main + + - name: edit infra repository image tag + run: | + echo 'env(IMAGE_TAG)' + yq eval -i '.service.tag = env(IMAGE_TAG)' ./charts/auth/values.yaml + + - name: commit + uses: leigholiver/commit-with-deploy-key@v1.0.4 + with: + source: . + destination_repo: kSideProject/kpring-infra + deploy_key: ${{ secrets.SSH_PRIVATE_KEY }} + commit_message: 'ci: update auth image version=${{ github.event.inputs.version }}' diff --git a/.github/workflows/ci_front.yml b/.github/workflows/ci_front.yml new file mode 100644 index 00000000..82b7fea1 --- /dev/null +++ b/.github/workflows/ci_front.yml @@ -0,0 +1,70 @@ +name: Frontend Nginx micro service CI + +on: + workflow_dispatch: + inputs: + version: + description: '배포하고자 하는 버전을 입력해주세요. 최신 버전이라면 생략해주세요. (git commit id 앞 8자리)' + default: 'latest' + +jobs: + build: + if: github.event.inputs.version == 'latest' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + name: checkout + run: git checkout ${{ github.event.inputs.version }} + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + # Build Docker image + - name: Build Docker Image + run: | + docker build -t kpring/front_app:$(git rev-parse --short=8 HEAD) . + + # Push Docker image to DockerHub + - name: Push Docker Image to DockerHub + run: | + docker push kpring/front_app:$(git rev-parse --short=8 HEAD) + + tagging: + needs: + - build + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + + - if: github.event.inputs.version != 'latest' + name: checkout + run: git checkout ${{ github.event.inputs.version }} + + - name: set image tag + run: | + echo "IMAGE_TAG=$(git rev-parse --short=8 HEAD)" >> $GITHUB_ENV + + - name: checkout infra repository + uses: actions/checkout@v4 + with: + repository: kSideProject/kpring-infra + ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} + ref: main + + - name: edit infra repository image tag + run: | + echo 'env(IMAGE_TAG)' + yq eval -i '.image.tag = env(IMAGE_TAG)' ./charts/front/values.yaml + + - name: commit + uses: leigholiver/commit-with-deploy-key@v1.0.4 + with: + source: . + destination_repo: kSideProject/kpring-infra + deploy_key: ${{ secrets.SSH_PRIVATE_KEY }} + commit_message: 'ci: update frontend image version=${{ github.event.inputs.version }}' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci_server.yml similarity index 57% rename from .github/workflows/ci.yml rename to .github/workflows/ci_server.yml index e90b7e08..00d2349e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci_server.yml @@ -1,32 +1,39 @@ -name: CI +name: Server micro service CI on: - push: - branches: [ main ] # push 되었을 때, 실행 + workflow_dispatch: + inputs: + version: + description: '배포하고자 하는 버전을 입력해주세요. 최신 버전이라면 생략해주세요. (git commit id 앞 8자리)' + default: 'latest' jobs: build: + if: github.event.inputs.version == 'latest' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + name: checkout + run: git checkout ${{ github.event.inputs.version }} + - name: set up jdk 21 uses: actions/setup-java@v4 with: distribution: 'zulu' java-version: '21' - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Log in to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: make api documents - run: ./gradlew --info openapi3 + run: ./gradlew --info server:openapi3 - name: configure openapi3 spec run: | @@ -34,19 +41,9 @@ jobs: yq eval -i '.components.securitySchemes.bearerAuth.scheme = "bearer"' ./server/src/main/resources/static/openapi3.yaml yq eval -i '.components.securitySchemes.bearerAuth.bearerFormat = "JWT"' ./server/src/main/resources/static/openapi3.yaml yq eval -i '.security[0].bearerAuth = []' ./server/src/main/resources/static/openapi3.yaml - - yq eval -i '.components.securitySchemes.bearerAuth.type = "http"' ./user/src/main/resources/static/openapi3.yaml - yq eval -i '.components.securitySchemes.bearerAuth.scheme = "bearer"' ./user/src/main/resources/static/openapi3.yaml - yq eval -i '.components.securitySchemes.bearerAuth.bearerFormat = "JWT"' ./user/src/main/resources/static/openapi3.yaml - yq eval -i '.security[0].bearerAuth = []' ./user/src/main/resources/static/openapi3.yaml - - yq eval -i '.components.securitySchemes.bearerAuth.type = "http"' ./auth/src/main/resources/static/openapi3.yaml - yq eval -i '.components.securitySchemes.bearerAuth.scheme = "bearer"' ./auth/src/main/resources/static/openapi3.yaml - yq eval -i '.components.securitySchemes.bearerAuth.bearerFormat = "JWT"' ./auth/src/main/resources/static/openapi3.yaml - yq eval -i '.security[0].bearerAuth = []' ./auth/src/main/resources/static/openapi3.yaml - name: push image using jib - run: ./gradlew --info jib + run: ./gradlew --info server:jib tagging: needs: @@ -56,7 +53,11 @@ jobs: - name: checkout uses: actions/checkout@v4 - - name: set tag + - if: github.event.inputs.version != 'latest' + name: checkout + run: git checkout ${{ github.event.inputs.version }} + + - name: set image tag run: | echo "IMAGE_TAG=$(git rev-parse --short=8 HEAD)" >> $GITHUB_ENV @@ -67,12 +68,10 @@ jobs: ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} ref: main - - name: edit infra repository tag + - name: edit infra repository image tag run: | echo 'env(IMAGE_TAG)' yq eval -i '.service.tag = env(IMAGE_TAG)' ./charts/server/values.yaml - yq eval -i '.service.tag = env(IMAGE_TAG)' ./charts/user/values.yaml - yq eval -i '.service.tag = env(IMAGE_TAG)' ./charts/auth/values.yaml - name: commit uses: leigholiver/commit-with-deploy-key@v1.0.4 @@ -80,4 +79,4 @@ jobs: source: . destination_repo: kSideProject/kpring-infra deploy_key: ${{ secrets.SSH_PRIVATE_KEY }} - commit_message: 'ci: update tag to env(IMAGE_TAG)' + commit_message: 'ci: update server image version=${{ github.event.inputs.version }}' diff --git a/.github/workflows/ci_user.yml b/.github/workflows/ci_user.yml new file mode 100644 index 00000000..fb43c188 --- /dev/null +++ b/.github/workflows/ci_user.yml @@ -0,0 +1,82 @@ +name: User micro service CI + +on: + workflow_dispatch: + inputs: + version: + description: '배포하고자 하는 버전을 입력해주세요. 최신 버전이라면 생략해주세요. (git commit id 앞 8자리)' + default: 'latest' + +jobs: + build: + if: github.event.inputs.version == 'latest' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + name: checkout + run: git checkout ${{ github.event.inputs.version }} + + - name: set up jdk 21 + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '21' + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: make api documents + run: ./gradlew --info user:openapi3 + + - name: configure openapi3 spec + run: | + yq eval -i '.components.securitySchemes.bearerAuth.type = "http"' ./user/src/main/resources/static/openapi3.yaml + yq eval -i '.components.securitySchemes.bearerAuth.scheme = "bearer"' ./user/src/main/resources/static/openapi3.yaml + yq eval -i '.components.securitySchemes.bearerAuth.bearerFormat = "JWT"' ./user/src/main/resources/static/openapi3.yaml + yq eval -i '.security[0].bearerAuth = []' ./user/src/main/resources/static/openapi3.yaml + + - name: push image using jib + run: ./gradlew --info user:jib + + tagging: + needs: + - build + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + + - if: github.event.inputs.version != 'latest' + name: checkout + run: git checkout ${{ github.event.inputs.version }} + + - name: set image tag + run: | + echo "IMAGE_TAG=$(git rev-parse --short=8 HEAD)" >> $GITHUB_ENV + + - name: checkout infra repository + uses: actions/checkout@v4 + with: + repository: kSideProject/kpring-infra + ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} + ref: main + + - name: edit infra repository image tag + run: | + echo 'env(IMAGE_TAG)' + yq eval -i '.service.tag = env(IMAGE_TAG)' ./charts/user/values.yaml + + - name: commit + uses: leigholiver/commit-with-deploy-key@v1.0.4 + with: + source: . + destination_repo: kSideProject/kpring-infra + deploy_key: ${{ secrets.SSH_PRIVATE_KEY }} + commit_message: 'ci: update user image version=${{ github.event.inputs.version }}'