From 0c676eff3e4cb4c4312e3af415320a522802dd7d Mon Sep 17 00:00:00 2001 From: Junsu Lee Date: Fri, 22 Mar 2024 14:36:51 +0900 Subject: [PATCH] ci: update for deployment --- .github/workflows/deploy.yaml | 109 ------------------------ .github/workflows/deployment.yaml | 119 +++++++++++++++++++++++++++ .github/workflows/dev-validate.yaml | 48 ----------- .github/workflows/test-coverage.yaml | 66 --------------- q | 6 -- 5 files changed, 119 insertions(+), 229 deletions(-) delete mode 100644 .github/workflows/deploy.yaml create mode 100644 .github/workflows/deployment.yaml delete mode 100644 .github/workflows/dev-validate.yaml delete mode 100644 .github/workflows/test-coverage.yaml delete mode 100644 q diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml deleted file mode 100644 index 0ad38425..00000000 --- a/.github/workflows/deploy.yaml +++ /dev/null @@ -1,109 +0,0 @@ -name: Deployment - -on: - push: - branches: [ main ] - -permissions: - id-token: write - contents: read - -env: - AWS_REGION: ${{ secrets.AWS_REGION }} - AWS_ROLE: ${{ secrets.AWS_ROLE }} - ECR_REGISTRY: ${{ secrets.ECR_REGISTRY }} - ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }} - MANIFEST_PATH: ${{ secrets.MANIFEST_PATH }} - IMAGE_NAME: ${{ secrets.IMAGE_NAME }} - EKS_REPOSITORY_TOKEN: ${{ secrets.EKS_REPOSITORY_TOKEN }} - PROD_PROPERTIES: ${{ secrets.PROD_PROPERTIES }} - TEST_PROPERTIES: ${{ secrets.TEST_PROPERTIES }} - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - name: Clone Repository - uses: actions/checkout@v3 - - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-region: ${{ env.AWS_REGION }} - role-to-assume: ${{ env.AWS_ROLE }} - role-session-name: GithubElasticContainerRegistrySession - - - name: Login to Amazon ECR - uses: aws-actions/amazon-ecr-login@v1 - - - name: Generate Version Code - run: echo "VERSION=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV - - - name: Setup Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'adopt' # https://github.com/actions/setup-java - - - name: Gradle Caching - uses: actions/cache@v3 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- - - - name: Create main-application.yml - run: | - mkdir -p ./src/main/resources - echo "${{ env.PROD_PROPERTIES }}" > ./src/main/resources/application.yml - - - name: Create test-application.yml - run: | - mkdir -p ./src/test/resources - echo "${{ env.TEST_PROPERTIES }}" > ./src/test/resources/application.yml - - - name: Build with Gradle - run: ./gradlew clean build - - - name: Push Image to ECR - uses: docker/build-push-action@v3 - with: - file: Dockerfile - context: . - push: true - platforms: - linux/amd64 - tags: | - ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.VERSION }}, - ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Checkout EKS Repository - uses: actions/checkout@v3 - with: - repository: uoslife/infra-eks - ref: master - token: ${{ env.EKS_REPOSITORY_TOKEN }} - path: infra-eks - - - name: Update Image Tag - run: | - cd infra-eks/${{ env.MANIFEST_PATH }} - kustomize edit set image ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.VERSION }} - - - name: Apply Image Tag - run: | - cd infra-eks/${{ env.MANIFEST_PATH }} - git config --global user.email ${{ github.actor }}@users.noreply.github.com - git config --global user.name ${{ github.actor }} - git add . - git commit -am "ci(${{ env.MANIFEST_PATH }}/${{ env.IMAGE_NAME }}): Update image tag to `${{ env.VERSION }}`" - git push diff --git a/.github/workflows/deployment.yaml b/.github/workflows/deployment.yaml new file mode 100644 index 00000000..f75bdeed --- /dev/null +++ b/.github/workflows/deployment.yaml @@ -0,0 +1,119 @@ +name: Deployment + +run-name: Deploy to ${{ inputs.environment }} by @${{ github.actor }} + +permissions: + id-token: write + contents: read + +on: + workflow_dispatch: + inputs: + environment: + description: '배포 대상 환경' + required: true + default: 'alpha' + type: choice + options: + - alpha + - prod + ref: + description: '배포 대상 브랜치/태그' + required: true + default: 'HEAD' + type: string + +jobs: + deploy: + runs-on: ubuntu-latest + + env: + GIT_REF: ${{ inputs.ref == 'HEAD' && 'refs/heads/main' || format('refs/tags/{0}', inputs.ref) }} + GIT_PROJECT_NAME: meeting + HARBOR_REGISTRY: harbor.uoslife.net + HARBOR_PROJECT: uoslife-${{ inputs.environment }}-v1 + HARBOR_REPOSITORY: meeting-server + HARBOR_USERNAME: ${{ secrets.HARBOR_USERNAME }} + HARBOR_PASSWORD: ${{ secrets.HARBOR_PASSWORD }} + + PROD_PROPERTIES: '${{ secrets.CORE_PROD_PROPERTIES }}' + TEST_PROPERTIES: '${{ secrets.CORE_TEST_PROPERTIES }}' + FIREBASE_KEY: '${{ secrets.FIREBASE_KEY }}' + + steps: + - name: Clone Repository + uses: actions/checkout@v4 + with: + ref: ${{ env.GIT_REF }} + + - name: Generate Version Code + run: | + echo "version=$(date +'%Y%m%d%H%M%S')" >> "$GITHUB_OUTPUT" + echo "VERSION=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV + + - name: Setup Docker Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.HARBOR_REGISTRY }} + username: ${{ env.HARBOR_USERNAME }} + password: ${{ env.HARBOR_PASSWORD }} + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: adopt + + - name: Cache Gradle Dependencies + uses: actions/cache@v4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Build with Gradle + run: ./gradlew clean build --exclude-task test + + - name: Build and Push Docker Image + uses: docker/build-push-action@v5 + with: + file: Dockerfile + context: . + push: true + platforms: linux/amd64 + cache-from: type=gha + cache-to: 'type=gha,mode=max' + tags: > + ${{ env.HARBOR_REGISTRY }}/${{ env.HARBOR_PROJECT }}/${{ env.HARBOR_REPOSITORY }}:${{ env.VERSION }}, + ${{ env.HARBOR_REGISTRY }}/${{ env.HARBOR_PROJECT }}/${{ env.HARBOR_REPOSITORY }}:latest + + - name: Checkout GitOps Repository + uses: actions/checkout@v4 + with: + repository: uoslife/gitops + ref: main + ssh-key: ${{ secrets.GITOPS_SSH_KEY }} + path: gitops + + - name: Setup Kustomize + uses: imranismail/setup-kustomize@v2 + + - name: Update Image Tag + run: | + cd gitops/projects/${{ env.GIT_PROJECT_NAME }}/overlays/${{ inputs.environment }} + kustomize edit set image ${{ env.HARBOR_REPOSITORY }}=${{ env.HARBOR_REGISTRY }}/${{ env.HARBOR_PROJECT }}/${{ env.HARBOR_REPOSITORY }}:${{ env.VERSION }} + + - name: Apply Image Tag + run: | + cd gitops/projects/${{ env.GIT_PROJECT_NAME }}/overlays/${{ inputs.environment }} + git config --global user.email ${{ github.actor }}@users.noreply.github.com + git config --global user.name ${{ github.actor }} + git add . + git commit -am "projects(${{ env.GIT_PROJECT_NAME }}): update version to ${{ env.VERSION }}" + git push diff --git a/.github/workflows/dev-validate.yaml b/.github/workflows/dev-validate.yaml deleted file mode 100644 index 794a7454..00000000 --- a/.github/workflows/dev-validate.yaml +++ /dev/null @@ -1,48 +0,0 @@ -name: dev-Validate - -on: - pull_request: - branches: - - 'dev/season4' - -permissions: - id-token: write - contents: read - -env: - PROD_PROPERTIES: ${{ secrets.CORE_PROD_PROPERTIES }} - TEST_PROPERTIES: ${{ secrets.CORE_TEST_PROPERTIES }} - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - name: Clone Repository - uses: actions/checkout@v3 - - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: "17" - distribution: "adopt" # https://github.com/actions/setup-java - - - name: Gradle Caching - uses: actions/cache@v3 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- - - name: Create main-application.yml - run: | - mkdir -p ./src/main/resources - echo "${{ env.PROD_PROPERTIES }}" > ./src/main/resources/application.yml - - name: Create test-application.yml - run: | - mkdir -p ./src/test/resources - echo "${{ env.TEST_PROPERTIES }}" > ./src/test/resources/application.yml - - name: Build with Gradle - run: ./gradlew clean build diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml deleted file mode 100644 index a2211ff2..00000000 --- a/.github/workflows/test-coverage.yaml +++ /dev/null @@ -1,66 +0,0 @@ -name: Server Meeting Code Coverage - -on: - push: - branches: - - 'main' - pull_request: - branches: - - 'main' - -env: - PROD_PROPERTIES: ${{ secrets.PROD_PROPERTIES }} - TEST_PROPERTIES: ${{ secrets.TEST_PROPERTIES }} - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - -jobs: - code-coverage: - runs-on: ubuntu-latest - - steps: - - name: Clone Repository - uses: actions/checkout@v3 - - ## Set Up JDK 17 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'adopt' # https://github.com/actions/setup-java - - ## gradle caching - - name: Gradle Caching - uses: actions/cache@v3 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- - - ## create application.yml - - name: Create application.yml - run: | - mkdir -p ./src/main/resources - echo "${{ env.PROD_PROPERTIES }}" > ./src/main/resources/application.yml - - ## create test application.yml - - name: Create test-application.yml - run: | - mkdir -p ./src/test/resources - echo "${{ env.TEST_PROPERTIES }}" > ./src/test/resources/application.yml - - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - ## Test with Gradle - - name: Test with Gradle - run: ./gradlew build jacocoTestReport - - ## Report to CodeCov - - name: Report to CodeCov - uses: codecov/codecov-action@v3 - with: - token: ${{ env.CODECOV_TOKEN }} - file: ./build/reports/jacoco/test/jacocoTestReport.xml diff --git a/q b/q deleted file mode 100644 index 18d6655b..00000000 --- a/q +++ /dev/null @@ -1,6 +0,0 @@ - dev/season4 -* feat/matching-algorithm - feat/payment - feat/portone - main - refactor/api