From a5c33a8a4deaef22f84e42c7d40e0a56b7a67a74 Mon Sep 17 00:00:00 2001 From: Donghyeon Im Date: Thu, 25 Jul 2024 08:29:45 +0900 Subject: [PATCH 01/17] fix: test cicd --- .github/workflows/aws.yaml | 333 ++++++++++++++++++++++++++++--------- 1 file changed, 253 insertions(+), 80 deletions(-) diff --git a/.github/workflows/aws.yaml b/.github/workflows/aws.yaml index ef2bc06..e25c5d9 100644 --- a/.github/workflows/aws.yaml +++ b/.github/workflows/aws.yaml @@ -1,90 +1,263 @@ -name: Build and Push Docker Image to ECR +name: Create and publish a container image, update helm chart 'appVersion' on: push: - branches: - - main - - develop + branches: ["main", "develop", "fix/cicd"] + +############################################# +# +# Branch +# - develop > github packages +# - main > amazon ecr repository +# +############################################# + +# # [origin] start +# jobs: +# build: +# name: Build Docker Image +# runs-on: ubuntu-latest + +# steps: +# - name: Checkout Repository +# uses: actions/checkout@v3 + +# - name: Set up JDK 21 +# uses: actions/setup-java@v2 +# with: +# distribution: 'adopt' +# java-version: '21' + +# - name: Build JAR +# run: ./gradlew build -x test + +# - name: Determine ECR Repository +# id: ecr_repo +# run: | +# REPO_NAME=$(echo ${{ github.repository }} | awk -F '/' '{print $2}' | tr '[:upper:]' '[:lower:]') + +# echo "repo=${REPO_NAME}" >> $GITHUB_OUTPUT + +# if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then +# echo "environment=prod" >> $GITHUB_OUTPUT +# elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then +# echo "environment=stag" >> $GITHUB_OUTPUT +# else +# echo "::error::Unsupported branch: ${{ github.event_name }} on ${{ github.ref }}" +# exit 1 +# fi + +# - name: Configure AWS credentials +# uses: aws-actions/configure-aws-credentials@v2 +# with: +# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} +# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} +# aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + +# - name: Login to Amazon ECR +# id: login-ecr +# uses: aws-actions/amazon-ecr-login@v2 + +# - name: Docker Build and Push +# run: | +# docker build -t ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }}:${{ github.sha }} . +# docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }}:${{ github.sha }} + +# - name: Checkout Private Repository +# uses: actions/checkout@v4 +# with: +# repository: NTF-marketplace/devops +# fetch-depth: 0 +# ref: develop +# token: ${{ secrets.PAT }} + +# - name: Replace image tag in helm values (LOCAL) +# uses: mikefarah/yq@master +# env: +# IMAGE_TAG: ${{ github.sha }} +# with: +# cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }}/values.yaml' + +# - name: Commit helm chart changes +# env: +# IMAGE_TAG: ${{ github.sha }} +# run: | +# cd chart/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }} +# git config --global user.email "hun5879@naver.com" +# git config --global user.name "dongdorrong" + +# git add values.yaml +# git commit --message "ci: update ${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }} image tag to $IMAGE_TAG" + +# - name: Push commit +# uses: ad-m/github-push-action@master +# with: +# github_token: ${{ secrets.PAT }} +# repository: NTF-marketplace/devops +# branch: develop +# # [origin] end + +env: + REGISTRY_DEV: ghcr.io + IMAGE_NAME: ${{ github.repository }} jobs: - build: - name: Build Docker Image + develop: + # https://docs.github.com/ko/actions/publishing-packages/publishing-docker-images#github-packages%EC%97%90-%EC%9D%B4%EB%AF%B8%EC%A7%80-%EA%B2%8C%EC%8B%9C + # if: github.ref == 'refs/heads/develop' + if: github.ref == 'refs/heads/fix/cicd' + name: Build and Push Docker Image to GitHub Container Registry runs-on: ubuntu-latest - + + permissions: + contents: read + packages: write + attestations: write + id-token: write + steps: - - name: Checkout Repository - uses: actions/checkout@v3 + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY_DEV }} + username: ${{ github.actor }} + password: ${{ secrets.PAT }} + + - name: Extract metadata (tags, labels) for Container image + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY_DEV }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + id: push + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true + + - name: Set up JDK 21 + uses: actions/setup-java@v2 + with: + distribution: 'adopt' + java-version: '21' + + # - name: Build JAR + # run: ./gradlew clean build -x test + + # - name: Docker Build and Push to GitHub Container Registry + # run: | + # docker build -t ghcr.io/${{ github.repository }}:${{ github.sha }} . + # echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + # docker push ghcr.io/${{ github.repository }}:${{ github.sha }} + + # - name: Checkout Private Repository + # uses: actions/checkout@v4 + # with: + # repository: NTF-marketplace/devops + # fetch-depth: 0 + # ref: develop + # token: ${{ secrets.PAT }} + + # - name: Replace image tag in helm values (LOCAL) + # uses: mikefarah/yq@master + # env: + # IMAGE_TAG: ${{ github.sha }} + # with: + # cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/my-repo_dev/values.yaml' + + # - name: Commit helm chart changes + # env: + # IMAGE_TAG: ${{ github.sha }} + # run: | + # cd chart/my-repo_dev + # git config --global user.email "hun5879@naver.com" + # git config --global user.name "dongdorrong" + + # git add values.yaml + # git commit --message "ci: update my-repo_dev image tag to $IMAGE_TAG" + + # - name: Push commit + # uses: ad-m/github-push-action@master + # with: + # github_token: ${{ secrets.PAT }} + # repository: NTF-marketplace/devops + # branch: develop + + # main: + # if: github.ref == 'refs/heads/main' + # name: Build and Push Docker Image to ECR + # runs-on: ubuntu-latest + + # steps: + # - name: Checkout Repository + # uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v2 - with: - distribution: 'adopt' - java-version: '17' + # - name: Set up JDK 21 + # uses: actions/setup-java@v2 + # with: + # distribution: 'adopt' + # java-version: '21' - - name: Build JAR - run: ./gradlew build -x test + # - name: Build JAR + # run: ./gradlew clean build -x test - - name: Determine ECR Repository - id: ecr_repo - run: | - REPO_NAME=$(echo ${{ github.repository }} | awk -F '/' '{print $2}' | tr '[:upper:]' '[:lower:]') - - echo "repo=${REPO_NAME}" >> $GITHUB_OUTPUT - - if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then - echo "environment=prod" >> $GITHUB_OUTPUT - elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then - echo "environment=stag" >> $GITHUB_OUTPUT - else - echo "::error::Unsupported branch: ${{ github.event_name }} on ${{ github.ref }}" - exit 1 - fi - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ${{ secrets.AWS_DEFAULT_REGION }} - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v2 - - - name: Docker Build and Push - run: | - docker build -t ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }}:${{ github.sha }} . - docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }}:${{ github.sha }} - - - name: Checkout Private Repository - uses: actions/checkout@v4 - with: - repository: NTF-marketplace/devops - fetch-depth: 0 - ref: develop - token: ${{ secrets.PAT }} - - - name: Replace image tag in helm values (LOCAL) - uses: mikefarah/yq@master - env: - IMAGE_TAG: ${{ github.sha }} - with: - cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }}/values.yaml' - - - name: Commit helm chart changes - env: - IMAGE_TAG: ${{ github.sha }} - run: | - cd chart/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }} - git config --global user.email "hun5879@naver.com" - git config --global user.name "dongdorrong" - - git add values.yaml - git commit --message "ci: update ${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }} image tag to $IMAGE_TAG" - - - name: Push commit - uses: ad-m/github-push-action@master - with: - github_token: ${{ secrets.PAT }} - repository: NTF-marketplace/devops - branch: develop \ No newline at end of file + # - name: Configure AWS credentials + # uses: aws-actions/configure-aws-credentials@v2 + # with: + # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + + # - name: Login to Amazon ECR + # uses: aws-actions/amazon-ecr-login@v2 + + # - name: Docker Build and Push to ECR + # run: | + # docker build -t ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/my-repo_prod:${{ github.sha }} . + # docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/my-repo_prod:${{ github.sha }} + + # - name: Checkout Private Repository + # uses: actions/checkout@v4 + # with: + # repository: NTF-marketplace/devops + # fetch-depth: 0 + # ref: develop + # token: ${{ secrets.PAT }} + + # - name: Replace image tag in helm values (LOCAL) + # uses: mikefarah/yq@master + # env: + # IMAGE_TAG: ${{ github.sha }} + # with: + # cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/my-repo_prod/values.yaml' + + # - name: Commit helm chart changes + # env: + # IMAGE_TAG: ${{ github.sha }} + # run: | + # cd chart/my-repo_prod + # git config --global user.email "hun5879@naver.com" + # git config --global user.name "dongdorrong" + + # git add values.yaml + # git commit --message "ci: update my-repo_prod image tag to $IMAGE_TAG" + + # - name: Push commit + # uses: ad-m/github-push-action@master + # with: + # github_token: ${{ secrets.PAT }} + # repository: NTF-marketplace/devops + # branch: develop \ No newline at end of file From f27f3bdef9057640a4fc6766293517432c2de291 Mon Sep 17 00:00:00 2001 From: Donghyeon Im Date: Thu, 25 Jul 2024 08:31:45 +0900 Subject: [PATCH 02/17] fix: test cicd --- .github/workflows/aws.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/aws.yaml b/.github/workflows/aws.yaml index e25c5d9..753c7e8 100644 --- a/.github/workflows/aws.yaml +++ b/.github/workflows/aws.yaml @@ -124,7 +124,7 @@ jobs: with: registry: ${{ env.REGISTRY_DEV }} username: ${{ github.actor }} - password: ${{ secrets.PAT }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata (tags, labels) for Container image id: meta From ca2fe858512502ff2b621edb6cd5b6255da96b24 Mon Sep 17 00:00:00 2001 From: Donghyeon Im Date: Thu, 25 Jul 2024 08:34:45 +0900 Subject: [PATCH 03/17] fix: test cicd --- .github/workflows/aws.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/aws.yaml b/.github/workflows/aws.yaml index 753c7e8..b8fdadc 100644 --- a/.github/workflows/aws.yaml +++ b/.github/workflows/aws.yaml @@ -132,6 +132,15 @@ jobs: with: images: ${{ env.REGISTRY_DEV }}/${{ env.IMAGE_NAME }} + - name: Set up JDK 21 + uses: actions/setup-java@v2 + with: + distribution: 'adopt' + java-version: '21' + + - name: Build JAR + run: ./gradlew clean build -x test + - name: Build and push Docker image id: push uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 @@ -148,15 +157,6 @@ jobs: subject-digest: ${{ steps.push.outputs.digest }} push-to-registry: true - - name: Set up JDK 21 - uses: actions/setup-java@v2 - with: - distribution: 'adopt' - java-version: '21' - - # - name: Build JAR - # run: ./gradlew clean build -x test - # - name: Docker Build and Push to GitHub Container Registry # run: | # docker build -t ghcr.io/${{ github.repository }}:${{ github.sha }} . From 832d9c3ddba40d7997cbc6c77473948955ae753b Mon Sep 17 00:00:00 2001 From: Donghyeon Im Date: Thu, 25 Jul 2024 08:54:54 +0900 Subject: [PATCH 04/17] fix: test cicd --- .github/workflows/aws.yaml | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/.github/workflows/aws.yaml b/.github/workflows/aws.yaml index b8fdadc..9690ff8 100644 --- a/.github/workflows/aws.yaml +++ b/.github/workflows/aws.yaml @@ -103,7 +103,10 @@ env: jobs: develop: + ### Reference # https://docs.github.com/ko/actions/publishing-packages/publishing-docker-images#github-packages%EC%97%90-%EC%9D%B4%EB%AF%B8%EC%A7%80-%EA%B2%8C%EC%8B%9C + ### + # if: github.ref == 'refs/heads/develop' if: github.ref == 'refs/heads/fix/cicd' name: Build and Push Docker Image to GitHub Container Registry @@ -131,6 +134,7 @@ jobs: uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 with: images: ${{ env.REGISTRY_DEV }}/${{ env.IMAGE_NAME }} + tags: type=sha - name: Set up JDK 21 uses: actions/setup-java@v2 @@ -150,12 +154,23 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - - name: Generate artifact attestation - uses: actions/attest-build-provenance@v1 - with: - subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} - subject-digest: ${{ steps.push.outputs.digest }} - push-to-registry: true + # ### Error + # # [message] Failed to persist attestation + # # Feature not available for the NTF-marketplace organization. + # # To enable this feature, please upgrade the billing plan, or make this repository public. + # # https://docs.github.com/rest/repos/repos#create-an-attestation + # ### + # - name: Generate artifact attestation + # uses: actions/attest-build-provenance@v1 + # with: + # subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + # subject-digest: ${{ steps.push.outputs.digest }} + # push-to-registry: true + + + + + # - name: Docker Build and Push to GitHub Container Registry # run: | From 202fc4c07df33a765e35caddb021acc5d3a553e5 Mon Sep 17 00:00:00 2001 From: Donghyeon Im Date: Thu, 25 Jul 2024 09:11:11 +0900 Subject: [PATCH 05/17] fix: test cicd --- .github/workflows/aws.yaml | 82 ++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 48 deletions(-) diff --git a/.github/workflows/aws.yaml b/.github/workflows/aws.yaml index 9690ff8..a57c552 100644 --- a/.github/workflows/aws.yaml +++ b/.github/workflows/aws.yaml @@ -97,10 +97,6 @@ on: # branch: develop # # [origin] end -env: - REGISTRY_DEV: ghcr.io - IMAGE_NAME: ${{ github.repository }} - jobs: develop: ### Reference @@ -111,7 +107,8 @@ jobs: if: github.ref == 'refs/heads/fix/cicd' name: Build and Push Docker Image to GitHub Container Registry runs-on: ubuntu-latest - + env: + TARGET_ENVIRONMENT: dev permissions: contents: read packages: write @@ -122,7 +119,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Log in to the Container registry + - name: Log in to the GitHub container registry uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 with: registry: ${{ env.REGISTRY_DEV }} @@ -133,7 +130,7 @@ jobs: id: meta uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 with: - images: ${{ env.REGISTRY_DEV }}/${{ env.IMAGE_NAME }} + images: ghcr.io/${{ github.repository }} tags: type=sha - name: Set up JDK 21 @@ -163,53 +160,42 @@ jobs: # - name: Generate artifact attestation # uses: actions/attest-build-provenance@v1 # with: - # subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + # subject-name: ${{ env.REGISTRY }}/${{ github.repository }} # subject-digest: ${{ steps.push.outputs.digest }} # push-to-registry: true + - name: Checkout Private Repository + uses: actions/checkout@v4 + with: + repository: NTF-marketplace/devops + fetch-depth: 0 + ref: develop + token: ${{ secrets.PAT }} + + - name: Replace image tag in helm values.yaml + uses: mikefarah/yq@master + env: + IMAGE_TAG: ${{ steps.meta.outputs.tags }} + with: + cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ github.repository }}_$TARGET_ENVIRONMENT/values.yaml' + - name: Commit helm chart changes + env: + IMAGE_TAG: ${{ steps.meta.outputs.tags }} + run: | + cd chart/${{ github.repository }}_$TARGET_ENVIRONMENT + git config --global user.email "hun5879@naver.com" + git config --global user.name "dongdorrong" + git add values.yaml + git commit --message "ci: update ${{ github.repository }}_$TARGET_ENVIRONMENT image tag to $IMAGE_TAG" - - - # - name: Docker Build and Push to GitHub Container Registry - # run: | - # docker build -t ghcr.io/${{ github.repository }}:${{ github.sha }} . - # echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - # docker push ghcr.io/${{ github.repository }}:${{ github.sha }} - - # - name: Checkout Private Repository - # uses: actions/checkout@v4 - # with: - # repository: NTF-marketplace/devops - # fetch-depth: 0 - # ref: develop - # token: ${{ secrets.PAT }} - - # - name: Replace image tag in helm values (LOCAL) - # uses: mikefarah/yq@master - # env: - # IMAGE_TAG: ${{ github.sha }} - # with: - # cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/my-repo_dev/values.yaml' - - # - name: Commit helm chart changes - # env: - # IMAGE_TAG: ${{ github.sha }} - # run: | - # cd chart/my-repo_dev - # git config --global user.email "hun5879@naver.com" - # git config --global user.name "dongdorrong" - - # git add values.yaml - # git commit --message "ci: update my-repo_dev image tag to $IMAGE_TAG" - - # - name: Push commit - # uses: ad-m/github-push-action@master - # with: - # github_token: ${{ secrets.PAT }} - # repository: NTF-marketplace/devops - # branch: develop + - name: Push commit + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.PAT }} + repository: NTF-marketplace/devops + branch: develop # main: # if: github.ref == 'refs/heads/main' From 3dabeb22642f29f6d0f8043e5bb008648435c109 Mon Sep 17 00:00:00 2001 From: Donghyeon Im Date: Thu, 25 Jul 2024 09:12:51 +0900 Subject: [PATCH 06/17] fix: test cicd --- .github/workflows/aws.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/aws.yaml b/.github/workflows/aws.yaml index a57c552..d2b0985 100644 --- a/.github/workflows/aws.yaml +++ b/.github/workflows/aws.yaml @@ -122,7 +122,7 @@ jobs: - name: Log in to the GitHub container registry uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 with: - registry: ${{ env.REGISTRY_DEV }} + registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} From 6a1f462445ff3bf1a2cc4b6a42b17cc402710f6a Mon Sep 17 00:00:00 2001 From: Donghyeon Im Date: Thu, 25 Jul 2024 09:35:36 +0900 Subject: [PATCH 07/17] fix: test cicd --- .github/workflows/aws.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/aws.yaml b/.github/workflows/aws.yaml index d2b0985..8d79a23 100644 --- a/.github/workflows/aws.yaml +++ b/.github/workflows/aws.yaml @@ -177,18 +177,18 @@ jobs: env: IMAGE_TAG: ${{ steps.meta.outputs.tags }} with: - cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ github.repository }}_$TARGET_ENVIRONMENT/values.yaml' + cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ github.repository }}_${{ env.TARGET_ENVIRONMENT }}/values.yaml' - name: Commit helm chart changes env: IMAGE_TAG: ${{ steps.meta.outputs.tags }} run: | - cd chart/${{ github.repository }}_$TARGET_ENVIRONMENT + cd chart/${{ github.repository }}_${{ env.TARGET_ENVIRONMENT }} git config --global user.email "hun5879@naver.com" git config --global user.name "dongdorrong" git add values.yaml - git commit --message "ci: update ${{ github.repository }}_$TARGET_ENVIRONMENT image tag to $IMAGE_TAG" + git commit --message "ci: update ${{ github.repository }}_${{ env.TARGET_ENVIRONMENT }} image tag to $IMAGE_TAG" - name: Push commit uses: ad-m/github-push-action@master From cadd02d1fd1194feca04f78bf1ba9271a24b54a5 Mon Sep 17 00:00:00 2001 From: Donghyeon Im Date: Thu, 25 Jul 2024 09:44:13 +0900 Subject: [PATCH 08/17] fix: test cicd --- .github/workflows/aws.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/aws.yaml b/.github/workflows/aws.yaml index 8d79a23..08d5676 100644 --- a/.github/workflows/aws.yaml +++ b/.github/workflows/aws.yaml @@ -177,7 +177,7 @@ jobs: env: IMAGE_TAG: ${{ steps.meta.outputs.tags }} with: - cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ github.repository }}_${{ env.TARGET_ENVIRONMENT }}/values.yaml' + cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ github.repository_id }}_${{ env.TARGET_ENVIRONMENT }}/values.yaml' - name: Commit helm chart changes env: @@ -188,7 +188,7 @@ jobs: git config --global user.name "dongdorrong" git add values.yaml - git commit --message "ci: update ${{ github.repository }}_${{ env.TARGET_ENVIRONMENT }} image tag to $IMAGE_TAG" + git commit --message "ci: update ${{ github.repository_id }}_${{ env.TARGET_ENVIRONMENT }} image tag to $IMAGE_TAG" - name: Push commit uses: ad-m/github-push-action@master From 1345453317f12eb0d5bdbd057644931e6e51bbf0 Mon Sep 17 00:00:00 2001 From: Donghyeon Im Date: Thu, 25 Jul 2024 09:48:51 +0900 Subject: [PATCH 09/17] fix: test cicd --- .github/workflows/aws.yaml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/aws.yaml b/.github/workflows/aws.yaml index 08d5676..d3e5d18 100644 --- a/.github/workflows/aws.yaml +++ b/.github/workflows/aws.yaml @@ -177,18 +177,23 @@ jobs: env: IMAGE_TAG: ${{ steps.meta.outputs.tags }} with: - cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ github.repository_id }}_${{ env.TARGET_ENVIRONMENT }}/values.yaml' + cmd: | + REPO_NAME=$(echo ${{ github.repository }} | awk -F '/' '{print $2}' | tr '[:upper:]' '[:lower:]') + + yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{REPO_NAME}}_${{ env.TARGET_ENVIRONMENT }}/values.yaml' - name: Commit helm chart changes env: IMAGE_TAG: ${{ steps.meta.outputs.tags }} run: | + REPO_NAME=$(echo ${{ github.repository }} | awk -F '/' '{print $2}' | tr '[:upper:]' '[:lower:]') + cd chart/${{ github.repository }}_${{ env.TARGET_ENVIRONMENT }} git config --global user.email "hun5879@naver.com" git config --global user.name "dongdorrong" git add values.yaml - git commit --message "ci: update ${{ github.repository_id }}_${{ env.TARGET_ENVIRONMENT }} image tag to $IMAGE_TAG" + git commit --message "ci: update ${{REPO_NAME}}_${{ env.TARGET_ENVIRONMENT }} image tag to $IMAGE_TAG" - name: Push commit uses: ad-m/github-push-action@master From 139029fa5bdbcf817b1b3db4d67363437affae52 Mon Sep 17 00:00:00 2001 From: Donghyeon Im Date: Thu, 25 Jul 2024 09:53:37 +0900 Subject: [PATCH 10/17] fix: test cicd --- .github/workflows/aws.yaml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/aws.yaml b/.github/workflows/aws.yaml index d3e5d18..113c3e1 100644 --- a/.github/workflows/aws.yaml +++ b/.github/workflows/aws.yaml @@ -108,7 +108,8 @@ jobs: name: Build and Push Docker Image to GitHub Container Registry runs-on: ubuntu-latest env: - TARGET_ENVIRONMENT: dev + ENVIRONMENT: dev + REPOSITORY: auth permissions: contents: read packages: write @@ -177,23 +178,18 @@ jobs: env: IMAGE_TAG: ${{ steps.meta.outputs.tags }} with: - cmd: | - REPO_NAME=$(echo ${{ github.repository }} | awk -F '/' '{print $2}' | tr '[:upper:]' '[:lower:]') - - yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{REPO_NAME}}_${{ env.TARGET_ENVIRONMENT }}/values.yaml' + cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }}/values.yaml' - name: Commit helm chart changes env: IMAGE_TAG: ${{ steps.meta.outputs.tags }} run: | - REPO_NAME=$(echo ${{ github.repository }} | awk -F '/' '{print $2}' | tr '[:upper:]' '[:lower:]') - - cd chart/${{ github.repository }}_${{ env.TARGET_ENVIRONMENT }} + cd chart/${{ github.repository }}_${{ env.ENVIRONMENT }} git config --global user.email "hun5879@naver.com" git config --global user.name "dongdorrong" git add values.yaml - git commit --message "ci: update ${{REPO_NAME}}_${{ env.TARGET_ENVIRONMENT }} image tag to $IMAGE_TAG" + git commit --message "ci: update ${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} image tag to $IMAGE_TAG" - name: Push commit uses: ad-m/github-push-action@master From cffd6185bfd67e81907380362d8289e3d872fd1a Mon Sep 17 00:00:00 2001 From: Donghyeon Im Date: Thu, 25 Jul 2024 09:57:21 +0900 Subject: [PATCH 11/17] fix: test cicd --- .github/workflows/aws.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/aws.yaml b/.github/workflows/aws.yaml index 113c3e1..3bf03e7 100644 --- a/.github/workflows/aws.yaml +++ b/.github/workflows/aws.yaml @@ -184,7 +184,7 @@ jobs: env: IMAGE_TAG: ${{ steps.meta.outputs.tags }} run: | - cd chart/${{ github.repository }}_${{ env.ENVIRONMENT }} + cd chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} git config --global user.email "hun5879@naver.com" git config --global user.name "dongdorrong" From c19c68184d21b3b60371992f5cbe6330c88eb258 Mon Sep 17 00:00:00 2001 From: Donghyeon Im Date: Thu, 25 Jul 2024 10:14:19 +0900 Subject: [PATCH 12/17] fix: test cicd --- .github/workflows/aws.yaml | 155 +++++++++++++++++++++---------------- 1 file changed, 88 insertions(+), 67 deletions(-) diff --git a/.github/workflows/aws.yaml b/.github/workflows/aws.yaml index 3bf03e7..04e3134 100644 --- a/.github/workflows/aws.yaml +++ b/.github/workflows/aws.yaml @@ -105,11 +105,11 @@ jobs: # if: github.ref == 'refs/heads/develop' if: github.ref == 'refs/heads/fix/cicd' - name: Build and Push Docker Image to GitHub Container Registry + name: Build and Push Container Image to GitHub Container Registry runs-on: ubuntu-latest env: - ENVIRONMENT: dev REPOSITORY: auth + ENVIRONMENT: dev permissions: contents: read packages: write @@ -176,20 +176,20 @@ jobs: - name: Replace image tag in helm values.yaml uses: mikefarah/yq@master env: - IMAGE_TAG: ${{ steps.meta.outputs.tags }} + IMAGE_VERSION: ${{ steps.meta.outputs.version }} with: - cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }}/values.yaml' + cmd: yq eval -i '.image.tag = env(IMAGE_VERSION)' 'chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }}/values.yaml' - name: Commit helm chart changes env: - IMAGE_TAG: ${{ steps.meta.outputs.tags }} + IMAGE_VERSION: ${{ steps.meta.outputs.version }} run: | cd chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} git config --global user.email "hun5879@naver.com" git config --global user.name "dongdorrong" git add values.yaml - git commit --message "ci: update ${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} image tag to $IMAGE_TAG" + git commit --message "ci: update ${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} image tag to $IMAGE_VERSION" - name: Push commit uses: ad-m/github-push-action@master @@ -199,67 +199,88 @@ jobs: branch: develop # main: - # if: github.ref == 'refs/heads/main' - # name: Build and Push Docker Image to ECR + # # if: github.ref == 'refs/heads/main' + # if: github.ref == 'refs/heads/fix/cicd' + # name: Build and Push Container Image to Amazon ECR # runs-on: ubuntu-latest - + # env: + # REPOSITORY: auth + # ENVIRONMENT: prod + # permissions: + # contents: read + # packages: write + # attestations: write + # id-token: write + # steps: - # - name: Checkout Repository - # uses: actions/checkout@v3 - - # - name: Set up JDK 21 - # uses: actions/setup-java@v2 - # with: - # distribution: 'adopt' - # java-version: '21' + # - name: Checkout repository + # uses: actions/checkout@v4 + + # - name: Configure AWS credentials + # uses: aws-actions/configure-aws-credentials@v4 + # with: + # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + + # - name: Login to Amazon ECR + # id: login-ecr + # uses: aws-actions/amazon-ecr-login@v2 + + # - name: Extract metadata (tags, labels) for Container image + # id: meta + # uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + # with: + # images: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com + # tags: type=sha + + # - name: Set up JDK 21 + # uses: actions/setup-java@v2 + # with: + # distribution: 'adopt' + # java-version: '21' - # - name: Build JAR - # run: ./gradlew clean build -x test - - # - name: Configure AWS credentials - # uses: aws-actions/configure-aws-credentials@v2 - # with: - # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - # aws-region: ${{ secrets.AWS_DEFAULT_REGION }} - - # - name: Login to Amazon ECR - # uses: aws-actions/amazon-ecr-login@v2 - - # - name: Docker Build and Push to ECR - # run: | - # docker build -t ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/my-repo_prod:${{ github.sha }} . - # docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/my-repo_prod:${{ github.sha }} - - # - name: Checkout Private Repository - # uses: actions/checkout@v4 - # with: - # repository: NTF-marketplace/devops - # fetch-depth: 0 - # ref: develop - # token: ${{ secrets.PAT }} - - # - name: Replace image tag in helm values (LOCAL) - # uses: mikefarah/yq@master - # env: - # IMAGE_TAG: ${{ github.sha }} - # with: - # cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/my-repo_prod/values.yaml' - - # - name: Commit helm chart changes - # env: - # IMAGE_TAG: ${{ github.sha }} - # run: | - # cd chart/my-repo_prod - # git config --global user.email "hun5879@naver.com" - # git config --global user.name "dongdorrong" - - # git add values.yaml - # git commit --message "ci: update my-repo_prod image tag to $IMAGE_TAG" - - # - name: Push commit - # uses: ad-m/github-push-action@master - # with: - # github_token: ${{ secrets.PAT }} - # repository: NTF-marketplace/devops - # branch: develop \ No newline at end of file + # - name: Build JAR + # run: ./gradlew clean build -x test + + # - name: Build and push Docker image + # id: push + # uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + # with: + # context: . + # push: true + # tags: ${{ steps.meta.outputs.tags }} + # labels: ${{ steps.meta.outputs.labels }} + + # - name: Checkout Private Repository + # uses: actions/checkout@v4 + # with: + # repository: NTF-marketplace/devops + # fetch-depth: 0 + # ref: develop + # token: ${{ secrets.PAT }} + + # - name: Replace image tag in helm values.yaml + # uses: mikefarah/yq@master + # env: + # IMAGE_TAG: ${{ steps.meta.outputs.tags }} + # with: + # cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }}/values.yaml' + + # - name: Commit helm chart changes + # env: + # IMAGE_TAG: ${{ steps.meta.outputs.tags }} + # run: | + # cd chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} + # git config --global user.email "hun5879@naver.com" + # git config --global user.name "dongdorrong" + + # git add values.yaml + # git commit --message "ci: update ${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} image tag to $IMAGE_TAG" + + # - name: Push commit + # uses: ad-m/github-push-action@master + # with: + # github_token: ${{ secrets.PAT }} + # repository: NTF-marketplace/devops + # branch: develop \ No newline at end of file From 1e41d7e631d70f3531fa1e30f29e185fb36edcd4 Mon Sep 17 00:00:00 2001 From: Donghyeon Im Date: Thu, 25 Jul 2024 10:25:51 +0900 Subject: [PATCH 13/17] fix: test cicd --- .github/workflows/aws.yaml | 240 ++++++++++++------------------------- 1 file changed, 77 insertions(+), 163 deletions(-) diff --git a/.github/workflows/aws.yaml b/.github/workflows/aws.yaml index 04e3134..244a36b 100644 --- a/.github/workflows/aws.yaml +++ b/.github/workflows/aws.yaml @@ -7,104 +7,18 @@ on: ############################################# # # Branch -# - develop > github packages -# - main > amazon ecr repository +# - develop > GitHub packages +# - main > Amazon ECR # ############################################# -# # [origin] start -# jobs: -# build: -# name: Build Docker Image -# runs-on: ubuntu-latest - -# steps: -# - name: Checkout Repository -# uses: actions/checkout@v3 - -# - name: Set up JDK 21 -# uses: actions/setup-java@v2 -# with: -# distribution: 'adopt' -# java-version: '21' - -# - name: Build JAR -# run: ./gradlew build -x test - -# - name: Determine ECR Repository -# id: ecr_repo -# run: | -# REPO_NAME=$(echo ${{ github.repository }} | awk -F '/' '{print $2}' | tr '[:upper:]' '[:lower:]') - -# echo "repo=${REPO_NAME}" >> $GITHUB_OUTPUT - -# if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then -# echo "environment=prod" >> $GITHUB_OUTPUT -# elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then -# echo "environment=stag" >> $GITHUB_OUTPUT -# else -# echo "::error::Unsupported branch: ${{ github.event_name }} on ${{ github.ref }}" -# exit 1 -# fi - -# - name: Configure AWS credentials -# uses: aws-actions/configure-aws-credentials@v2 -# with: -# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} -# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} -# aws-region: ${{ secrets.AWS_DEFAULT_REGION }} - -# - name: Login to Amazon ECR -# id: login-ecr -# uses: aws-actions/amazon-ecr-login@v2 - -# - name: Docker Build and Push -# run: | -# docker build -t ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }}:${{ github.sha }} . -# docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }}:${{ github.sha }} - -# - name: Checkout Private Repository -# uses: actions/checkout@v4 -# with: -# repository: NTF-marketplace/devops -# fetch-depth: 0 -# ref: develop -# token: ${{ secrets.PAT }} - -# - name: Replace image tag in helm values (LOCAL) -# uses: mikefarah/yq@master -# env: -# IMAGE_TAG: ${{ github.sha }} -# with: -# cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }}/values.yaml' - -# - name: Commit helm chart changes -# env: -# IMAGE_TAG: ${{ github.sha }} -# run: | -# cd chart/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }} -# git config --global user.email "hun5879@naver.com" -# git config --global user.name "dongdorrong" - -# git add values.yaml -# git commit --message "ci: update ${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }} image tag to $IMAGE_TAG" - -# - name: Push commit -# uses: ad-m/github-push-action@master -# with: -# github_token: ${{ secrets.PAT }} -# repository: NTF-marketplace/devops -# branch: develop -# # [origin] end - jobs: develop: ### Reference # https://docs.github.com/ko/actions/publishing-packages/publishing-docker-images#github-packages%EC%97%90-%EC%9D%B4%EB%AF%B8%EC%A7%80-%EA%B2%8C%EC%8B%9C ### - # if: github.ref == 'refs/heads/develop' - if: github.ref == 'refs/heads/fix/cicd' + if: github.ref == 'refs/heads/develop' name: Build and Push Container Image to GitHub Container Registry runs-on: ubuntu-latest env: @@ -198,89 +112,89 @@ jobs: repository: NTF-marketplace/devops branch: develop - # main: - # # if: github.ref == 'refs/heads/main' - # if: github.ref == 'refs/heads/fix/cicd' - # name: Build and Push Container Image to Amazon ECR - # runs-on: ubuntu-latest - # env: - # REPOSITORY: auth - # ENVIRONMENT: prod - # permissions: - # contents: read - # packages: write - # attestations: write - # id-token: write + main: + # if: github.ref == 'refs/heads/main' + if: github.ref == 'refs/heads/fix/cicd' + name: Build and Push Container Image to Amazon ECR + runs-on: ubuntu-latest + env: + REPOSITORY: auth + ENVIRONMENT: prod + permissions: + contents: read + packages: write + attestations: write + id-token: write - # steps: - # - name: Checkout repository - # uses: actions/checkout@v4 + steps: + - name: Checkout repository + uses: actions/checkout@v4 - # - name: Configure AWS credentials - # uses: aws-actions/configure-aws-credentials@v4 - # with: - # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - # aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.AWS_DEFAULT_REGION }} - # - name: Login to Amazon ECR - # id: login-ecr - # uses: aws-actions/amazon-ecr-login@v2 + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 - # - name: Extract metadata (tags, labels) for Container image - # id: meta - # uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 - # with: - # images: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com - # tags: type=sha + - name: Extract metadata (tags, labels) for Container image + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com + tags: type=sha - # - name: Set up JDK 21 - # uses: actions/setup-java@v2 - # with: - # distribution: 'adopt' - # java-version: '21' + - name: Set up JDK 21 + uses: actions/setup-java@v2 + with: + distribution: 'adopt' + java-version: '21' - # - name: Build JAR - # run: ./gradlew clean build -x test + - name: Build JAR + run: ./gradlew clean build -x test - # - name: Build and push Docker image - # id: push - # uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 - # with: - # context: . - # push: true - # tags: ${{ steps.meta.outputs.tags }} - # labels: ${{ steps.meta.outputs.labels }} + - name: Build and push Docker image + id: push + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} - # - name: Checkout Private Repository - # uses: actions/checkout@v4 - # with: - # repository: NTF-marketplace/devops - # fetch-depth: 0 - # ref: develop - # token: ${{ secrets.PAT }} + - name: Checkout Private Repository + uses: actions/checkout@v4 + with: + repository: NTF-marketplace/devops + fetch-depth: 0 + ref: develop + token: ${{ secrets.PAT }} - # - name: Replace image tag in helm values.yaml - # uses: mikefarah/yq@master - # env: - # IMAGE_TAG: ${{ steps.meta.outputs.tags }} - # with: - # cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }}/values.yaml' + - name: Replace image tag in helm values.yaml + uses: mikefarah/yq@master + env: + IMAGE_TAG: ${{ steps.meta.outputs.tags }} + with: + cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }}/values.yaml' - # - name: Commit helm chart changes - # env: - # IMAGE_TAG: ${{ steps.meta.outputs.tags }} - # run: | - # cd chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} - # git config --global user.email "hun5879@naver.com" - # git config --global user.name "dongdorrong" + - name: Commit helm chart changes + env: + IMAGE_TAG: ${{ steps.meta.outputs.tags }} + run: | + cd chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} + git config --global user.email "hun5879@naver.com" + git config --global user.name "dongdorrong" - # git add values.yaml - # git commit --message "ci: update ${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} image tag to $IMAGE_TAG" + git add values.yaml + git commit --message "ci: update ${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} image tag to $IMAGE_TAG" - # - name: Push commit - # uses: ad-m/github-push-action@master - # with: - # github_token: ${{ secrets.PAT }} - # repository: NTF-marketplace/devops - # branch: develop \ No newline at end of file + - name: Push commit + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.PAT }} + repository: NTF-marketplace/devops + branch: develop \ No newline at end of file From c6618ba9c48fe9a1ebe7f529a43d08cb230fa7df Mon Sep 17 00:00:00 2001 From: Donghyeon Im Date: Thu, 25 Jul 2024 10:42:56 +0900 Subject: [PATCH 14/17] fix: test cicd --- .github/workflows/aws.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/aws.yaml b/.github/workflows/aws.yaml index 244a36b..01f3fdf 100644 --- a/.github/workflows/aws.yaml +++ b/.github/workflows/aws.yaml @@ -145,7 +145,7 @@ jobs: id: meta uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 with: - images: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com + images: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ github.repository }} tags: type=sha - name: Set up JDK 21 From 15c98bd5e08fd264c39244404c96cff258d8382b Mon Sep 17 00:00:00 2001 From: Donghyeon Im Date: Thu, 25 Jul 2024 10:46:02 +0900 Subject: [PATCH 15/17] fix: test cicd --- .github/workflows/aws.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/aws.yaml b/.github/workflows/aws.yaml index 01f3fdf..217b3bd 100644 --- a/.github/workflows/aws.yaml +++ b/.github/workflows/aws.yaml @@ -145,7 +145,7 @@ jobs: id: meta uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 with: - images: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ github.repository }} + images: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} tags: type=sha - name: Set up JDK 21 From 3ad32f4f22bc858e52a1fa6895c0e0baef1657e7 Mon Sep 17 00:00:00 2001 From: Donghyeon Im Date: Thu, 25 Jul 2024 10:49:54 +0900 Subject: [PATCH 16/17] fix: test cicd --- .github/workflows/aws.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/aws.yaml b/.github/workflows/aws.yaml index 217b3bd..4e673ba 100644 --- a/.github/workflows/aws.yaml +++ b/.github/workflows/aws.yaml @@ -177,20 +177,20 @@ jobs: - name: Replace image tag in helm values.yaml uses: mikefarah/yq@master env: - IMAGE_TAG: ${{ steps.meta.outputs.tags }} + IMAGE_VERSION: ${{ steps.meta.outputs.version }} with: - cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }}/values.yaml' + cmd: yq eval -i '.image.tag = env(IMAGE_VERSION)' 'chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }}/values.yaml' - name: Commit helm chart changes env: - IMAGE_TAG: ${{ steps.meta.outputs.tags }} + IMAGE_VERSION: ${{ steps.meta.outputs.version }} run: | cd chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} git config --global user.email "hun5879@naver.com" git config --global user.name "dongdorrong" git add values.yaml - git commit --message "ci: update ${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} image tag to $IMAGE_TAG" + git commit --message "ci: update ${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} image tag to $IMAGE_VERSION" - name: Push commit uses: ad-m/github-push-action@master From d35f1ab417dbe14680d1c5b9d43383d5cc1c16b4 Mon Sep 17 00:00:00 2001 From: Donghyeon Im Date: Thu, 25 Jul 2024 10:53:37 +0900 Subject: [PATCH 17/17] refactor: organize cicd --- .github/workflows/{aws.yaml => cicd.yaml} | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) rename .github/workflows/{aws.yaml => cicd.yaml} (97%) diff --git a/.github/workflows/aws.yaml b/.github/workflows/cicd.yaml similarity index 97% rename from .github/workflows/aws.yaml rename to .github/workflows/cicd.yaml index 4e673ba..4fb2733 100644 --- a/.github/workflows/aws.yaml +++ b/.github/workflows/cicd.yaml @@ -2,7 +2,7 @@ name: Create and publish a container image, update helm chart 'appVersion' on: push: - branches: ["main", "develop", "fix/cicd"] + branches: ["main", "develop"] ############################################# # @@ -113,8 +113,7 @@ jobs: branch: develop main: - # if: github.ref == 'refs/heads/main' - if: github.ref == 'refs/heads/fix/cicd' + if: github.ref == 'refs/heads/main' name: Build and Push Container Image to Amazon ECR runs-on: ubuntu-latest env: