From ff43da0c7b069af0d60da443b11ee1868ba56801 Mon Sep 17 00:00:00 2001 From: ChuYong Date: Sat, 15 Jun 2024 21:01:24 +0900 Subject: [PATCH] chore: add workflow scripts --- .github/workflows/api-gateway.yaml | 56 ++++++++++++++++++++++++++ .github/workflows/jib-build.yaml | 63 ++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 .github/workflows/api-gateway.yaml create mode 100644 .github/workflows/jib-build.yaml diff --git a/.github/workflows/api-gateway.yaml b/.github/workflows/api-gateway.yaml new file mode 100644 index 0000000..07beab4 --- /dev/null +++ b/.github/workflows/api-gateway.yaml @@ -0,0 +1,56 @@ +name: API 게이트웨이 빌드 후 배포하기 +on: + push: + branches: [ 'main' ] + #paths: + # - 'api-gateway/**' # API Gateway 모듈 변경 + +env: + SPRING_PROFILE: prod + IMAGE_NAME: spinachpasta/api-gateway + MODULE_PATH: api-gateway + SERVER_PORT: 8080 + +concurrency: + group: api + +jobs: + prepare-variables: + name: 환경변수 준비하기 + runs-on: ubuntu-latest + outputs: + image-tag: ${{ steps.setup-env.outputs.image-tag }} + module-path: ${{ steps.setup-env.outputs.module-path }} + spring-profile: ${{ steps.setup-env.outputs.spring-profile }} + server-port: ${{ steps.setup-env.outputs.server-port }} + image-name: ${{ steps.setup-env.outputs.image-name }} + steps: + - name: GitHub 에서 레포 받아오기 + uses: actions/checkout@v3 + + - name: 환경변수 출력하기 + id: setup-env + run: | + echo "image-tag=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + echo "module-path=$MODULE_PATH" >> $GITHUB_OUTPUT + echo "spring-profile=$SPRING_PROFILE" >> $GITHUB_OUTPUT + echo "server-port=$SERVER_PORT" >> $GITHUB_OUTPUT + echo "image-name=$IMAGE_NAME" >> $GITHUB_OUTPUT + + call-build-workflow: + if: github.event_name == 'push' + needs: [ prepare-variables ] + name: 이미지 빌드 & 푸쉬 + uses: ./.github/workflows/jib-build.yaml + permissions: + id-token: write + contents: read + with: + spring-profile: ${{ needs.prepare-variables.outputs.spring-profile }} + server-port: ${{ needs.prepare-variables.outputs.server-port }} + image-name: ${{ needs.prepare-variables.outputs.image-name }} + image-tag: ${{ needs.prepare-variables.outputs.image-tag }} + module-path: ${{ needs.prepare-variables.outputs.module-path }} + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/jib-build.yaml b/.github/workflows/jib-build.yaml new file mode 100644 index 0000000..a435cf3 --- /dev/null +++ b/.github/workflows/jib-build.yaml @@ -0,0 +1,63 @@ +name: 이미지 빌드 & 푸쉬 +on: + workflow_call: + inputs: + spring-profile: + required: true + type: string + server-port: + required: true + type: string + image-name: + required: true + type: string + image-tag: + required: true + type: string + module-path: + required: true + type: string + secrets: + DOCKERHUB_USERNAME: + required: true + DOCKERHUB_TOKEN: + required: true + +jobs: + build: + runs-on: [ ubuntu-latest ] + name: 이미지 빌드하기 + + permissions: + id-token: write + contents: read + + steps: + - name: GitHub 에서 레포 받아오기 + uses: actions/checkout@v3 + + - name: 도커허브 로그인 + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: JDK17 준비하기 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Gradle 준비하기 + uses: gradle/gradle-build-action@v2 + + - name: 이미지 빌드하고 푸쉬하기 + id: build-image + env: + SPRING_PROFILES_ACTIVE: ${{ inputs.spring-profile }} + IMAGE_NAME: ${{ inputs.image-name }} + IMAGE_TAG: ${{ inputs.image-tag }} + SERVER_PORT: ${{ inputs.server-port }} + run: | + cd ${{ inputs.module-path }} && \ + chmod +x gradlew && ./gradlew jib