diff --git a/.github/workflows/Canary.yml b/.github/workflows/business-canary.yml similarity index 52% rename from .github/workflows/Canary.yml rename to .github/workflows/business-canary.yml index b852506..a0b6d31 100644 --- a/.github/workflows/Canary.yml +++ b/.github/workflows/business-canary.yml @@ -1,21 +1,21 @@ name: Docker Image CI env: - MODULES: | - business-service - dedicated-service - membership-service + MODULE: business-service BUILD_ID: ${{ github.sha }} + HELM_VALUE: business-service-chart/values-dev.yaml HELM_BRANCH: dev on: push: - branches: ["main"] + branches: [ "main" ] pull_request: - branches: ["main"] + branches: [ "main" ] jobs: + build: + runs-on: ubuntu-latest steps: @@ -24,33 +24,24 @@ jobs: run: chmod +x ./gradlew - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v4 + uses: aws-actions/configure-aws-credentials@v4 # More information on this action can be found below in the 'AWS Credentials' section with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID}} + aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY}} aws-region: ap-northeast-2 - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v2 - - name: Build, tag, and push docker images to Amazon ECR + - name: Build, tag, and push docker image to Amazon ECR env: REGISTRY: ${{ steps.login-ecr.outputs.registry }} + REPOSITORY: resistance-business IMAGE_TAG: ${{ github.sha }} run: | - for MODULE in $MODULES; do - HELM_VALUE=${MODULE}-chart/values-dev.yaml - ECR_REPOSITORY="resistance-$(echo $MODULE | cut -d '-' -f 1)" - - echo "Building and pushing Docker image for $MODULE" - - envsubst < Dockerfile.template | docker build -t $REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f - --build-arg MODULE=$MODULE . - docker push $REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - - echo "Updating Helm chart for $MODULE" - yq -i '.image.tag = "'$IMAGE_TAG'"' helm-chart/$HELM_VALUE - done + envsubst < Dockerfile.template | docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG -f - . + docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG - name: Checkout Helm Repository uses: actions/checkout@v3 @@ -60,13 +51,19 @@ jobs: ref: main ssh-key: ${{ secrets.HELM_CHARTS_REPO_KEY }} + - name: Change Image tag of the Helm value + uses: mikefarah/yq@v4.34.1 + with: + cmd: yq -i '.image.tag = "${{ env.BUILD_ID }}"' helm-chart/${{ env.HELM_VALUE }} + + - name: Commit and Push HELM changes run: | cd helm-chart git config --local user.email "downfa11@naver.com" git config --local user.name "downfa11" git add . - git commit -m "Commit HELM changes: ${{ github.sha }}" + git commit -m "Commit HELM changes: ${{ env.ECR_REPOSITORY }}:${{ env.BUILD_ID }}" current_branch=$(git branch --show-current) git checkout -b ${{ env.HELM_BRANCH }} && git merge ${current_branch} - git push --force origin ${{ env.HELM_BRANCH }} + git push --force origin ${{ env.HELM_BRANCH }} \ No newline at end of file diff --git a/.github/workflows/dedicated-canary.yml b/.github/workflows/dedicated-canary.yml new file mode 100644 index 0000000..dc52d9d --- /dev/null +++ b/.github/workflows/dedicated-canary.yml @@ -0,0 +1,69 @@ +name: Docker Image CI + +env: + MODULE: dedicated-service + BUILD_ID: ${{ github.sha }} + HELM_VALUE: dedicated-service-chart/values-dev.yaml + HELM_BRANCH: dev + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Grant execute permission for gradlew + run: chmod +x ./gradlew + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 # More information on this action can be found below in the 'AWS Credentials' section + with: + aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID}} + aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY}} + aws-region: ap-northeast-2 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Build, tag, and push docker image to Amazon ECR + env: + REGISTRY: ${{ steps.login-ecr.outputs.registry }} + REPOSITORY: resistance-dedicated + IMAGE_TAG: ${{ github.sha }} + run: | + envsubst < Dockerfile.template | docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG -f - . + docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG + + - name: Checkout Helm Repository + uses: actions/checkout@v3 + with: + repository: downfa11/k8s-Devops + path: helm-chart + ref: main + ssh-key: ${{ secrets.HELM_CHARTS_REPO_KEY }} + + - name: Change Image tag of the Helm value + uses: mikefarah/yq@v4.34.1 + with: + cmd: yq -i '.image.tag = "${{ env.BUILD_ID }}"' helm-chart/${{ env.HELM_VALUE }} + + + - name: Commit and Push HELM changes + run: | + cd helm-chart + git config --local user.email "downfa11@naver.com" + git config --local user.name "downfa11" + git add . + git commit -m "Commit HELM changes: ${{ env.ECR_REPOSITORY }}:${{ env.BUILD_ID }}" + current_branch=$(git branch --show-current) + git checkout -b ${{ env.HELM_BRANCH }} && git merge ${current_branch} + git push --force origin ${{ env.HELM_BRANCH }} \ No newline at end of file diff --git a/.github/workflows/membership-canary.yml b/.github/workflows/membership-canary.yml new file mode 100644 index 0000000..d982c8c --- /dev/null +++ b/.github/workflows/membership-canary.yml @@ -0,0 +1,69 @@ +name: Docker Image CI + +env: + MODULE: membership-service + BUILD_ID: ${{ github.sha }} + HELM_VALUE: membership-service-chart/values-dev.yaml + HELM_BRANCH: dev + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Grant execute permission for gradlew + run: chmod +x ./gradlew + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 # More information on this action can be found below in the 'AWS Credentials' section + with: + aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID}} + aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY}} + aws-region: ap-northeast-2 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Build, tag, and push docker image to Amazon ECR + env: + REGISTRY: ${{ steps.login-ecr.outputs.registry }} + REPOSITORY: resistance-membership + IMAGE_TAG: ${{ github.sha }} + run: | + envsubst < Dockerfile.template | docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG -f - . + docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG + + - name: Checkout Helm Repository + uses: actions/checkout@v3 + with: + repository: downfa11/k8s-Devops + path: helm-chart + ref: main + ssh-key: ${{ secrets.HELM_CHARTS_REPO_KEY }} + + - name: Change Image tag of the Helm value + uses: mikefarah/yq@v4.34.1 + with: + cmd: yq -i '.image.tag = "${{ env.BUILD_ID }}"' helm-chart/${{ env.HELM_VALUE }} + + + - name: Commit and Push HELM changes + run: | + cd helm-chart + git config --local user.email "downfa11@naver.com" + git config --local user.name "downfa11" + git add . + git commit -m "Commit HELM changes: ${{ env.ECR_REPOSITORY }}:${{ env.BUILD_ID }}" + current_branch=$(git branch --show-current) + git checkout -b ${{ env.HELM_BRANCH }} && git merge ${current_branch} + git push --force origin ${{ env.HELM_BRANCH }} \ No newline at end of file