./src/main/resources/application-prod.yml shell: bash - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle env: SPRING_PROFILES_ACTIVE: prod run: ./gradlew clean build --stacktrace shell: bash - name: aws configure uses: aws-actions/configure-aws-credentials@v1 "> ./src/main/resources/application-prod.yml shell: bash - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle env: SPRING_PROFILES_ACTIVE: prod run: ./gradlew clean build --stacktrace shell: bash - name: aws configure uses: aws-actions/configure-aws-credentials@v1 "> ./src/main/resources/application-prod.yml shell: bash - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle env: SPRING_PROFILES_ACTIVE: prod run: ./gradlew clean build --stacktrace shell: bash - name: aws configure uses: aws-actions/configure-aws-credentials@v1 ">

name: CDon: push: branches: [ "main" ]env: PROJECT_NAME: gream-v2 BUCKET_NAME: bc1-gream-s3-01 CODE_DEPLOY_APP_NAME: gream-v2 DEPLOYMENT_GROUP_NAME: gream-developer-v2jobs: build-docker: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set up JDK 17 uses: actions/setup-java@v3 with: java-version: '17' distribution: 'temurin' - name: make application-prod.yml if: contains(github.ref, 'develop') || contains(github.ref, 'main') run: | touch ./src/main/resources/application-prod.yml echo "${{ secrets.YML_PROD }}" > ./src/main/resources/application-prod.yml shell: bash - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle env: SPRING_PROFILES_ACTIVE: prod run: ./gradlew clean build --stacktrace shell: bash - name: aws configure uses: aws-actions/configure-aws-credentials@v1 with: aws-access-key-id: ${{ secrets.AWS_KEY }} aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} aws-region: ap-northeast-2 - name: Login to ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v1 - name: build docker file and setting deploy files env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: gream IMAGE_TAG: ${{ github.sha }} run: | docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG mkdir scripts touch scripts/deploy.sh echo "aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin $ECR_REGISTRY" >> scripts/deploy.sh echo "docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> scripts/deploy.sh echo "docker run -p 8080:8080 -e JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }} -e REDIS_URL=${{ secrets.REDIS_URL }} -e DB_ID=${{ secrets.DB_ID }} -e DB_PASSWORD=${{ secrets.DB_PASSWORD }} -e DB_URL=${{ secrets.DB_URL }} -e PROFILE=prod -d --restart always --name csbroker-api $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> scripts/deploy.sh - name: upload to s3 env: IMAGE_TAG: ${{ github.sha }} run: | zip -r $IMAGE_TAG.zip ./scripts appspec.yml aws s3 cp --region ap-northeast-2 --acl private ./$IMAGE_TAG.zip s3://$BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip - name: start deploy env: IMAGE_TAG: ${{ github.sha }} run: aws deploy create-deployment --application-name $CODE_DEPLOY_APP_NAME --deployment-group-name $DEPLOYMENT_GROUP_NAME --deployment-config-name CodeDeployDefault.OneAtATime --s3-location bucket=$BUCKET_NAME,bundleType=zip,key=$PROJECT_NAME/$IMAGE_TAG.zip

CI

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: <https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle>

name: CI

on:
  pull_request:
    branches: [ "main" ]

env:
  PROJECT_NAME: gream
  BUCKET_NAME: bc1-gream-s3-01
  CODE_DEPLOY_APP_NAME: gream
  DEPLOYMENT_GROUP_NAME: gream-developer

jobs:
  test:
    runs-on: ubuntu-latest
    permissions: write-all
    steps:
      - uses: actions/checkout@v3
      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          java-version: '17'
          distribution: 'temurin'

      - name: Cache Gradle packages
        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: Grant execute permission for gradlew
        run: chmod +x gradlew

      - name: Test with Gradle
        run: ./gradlew --info test

      - name: Publish unit test results
        uses: EnricoMi/publish-unit-test-result-action@v2
        if: ${{ always() }}
        with:
          files: build/test-results/**/*.xml

      - name: Cleanup Gradle Cache
        if: ${{ always() }}
        run: |
          rm -f ~/.gradle/caches/modules-2/modules-2.lock
          rm -f ~/.gradle/caches/modules-2/gc.properties

CD

name: CD

on:
  push:
    branches: [ "main" ]

env:
  PROJECT_NAME: gream-v2
  BUCKET_NAME: bc1-gream-s3-01
  CODE_DEPLOY_APP_NAME: gream-v2
  DEPLOYMENT_GROUP_NAME: gream-developer-v2

jobs:
  build-docker:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          java-version: '17'
          distribution: 'temurin'

      - name: make application-prod.yml
        if: contains(github.ref, 'develop') || contains(github.ref, 'main')
        run: |
          touch ./src/main/resources/application-prod.yml
          echo "${{ secrets.YML_PROD }}" > ./src/main/resources/application-prod.yml
        shell: bash

      - name: Grant execute permission for gradlew
        run: chmod +x gradlew

      - name: Build with Gradle
        env:
          SPRING_PROFILES_ACTIVE: prod
        run: ./gradlew clean build --stacktrace
        shell: bash

      - name: aws configure
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_KEY }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
          aws-region: ap-northeast-2

      - name: Login to ECR
        id: login-ecr
        uses: aws-actions/amazon-ecr-login@v1

      - name: build docker file and setting deploy files
        env:
          ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
          ECR_REPOSITORY: gream
          IMAGE_TAG: ${{ github.sha }}
        run: |
          docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
          docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
          mkdir scripts
          touch scripts/deploy.sh
          echo "aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin $ECR_REGISTRY" >> scripts/deploy.sh
          echo "docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> scripts/deploy.sh
          echo "docker run -p 8080:8080 -e JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }} -e REDIS_URL=${{ secrets.REDIS_URL }} -e DB_ID=${{ secrets.DB_ID }} -e DB_PASSWORD=${{ secrets.DB_PASSWORD }} -e DB_URL=${{ secrets.DB_URL }} -e PROFILE=prod -d --restart always --name csbroker-api $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> scripts/deploy.sh

      - name: upload to s3
        env:
          IMAGE_TAG: ${{ github.sha }}
        run: |
          zip -r $IMAGE_TAG.zip ./scripts appspec.yml
          aws s3 cp --region ap-northeast-2 --acl private ./$IMAGE_TAG.zip s3://$BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip

      - name: start deploy
        env:
          IMAGE_TAG: ${{ github.sha }}
        run: aws deploy create-deployment --application-name $CODE_DEPLOY_APP_NAME --deployment-group-name $DEPLOYMENT_GROUP_NAME --deployment-config-name CodeDeployDefault.OneAtATime --s3-location bucket=$BUCKET_NAME,bundleType=zip,key=$PROJECT_NAME/$IMAGE_TAG.zi