From 8b86b0b51218ff11b3ca23c7f3ef5aa54bbeb30d Mon Sep 17 00:00:00 2001 From: dav-sap Date: Tue, 7 Jun 2022 09:21:51 +0300 Subject: [PATCH 1/5] add build image job --- .../workflows/build-app-service-image.yaml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/build-app-service-image.yaml diff --git a/.github/workflows/build-app-service-image.yaml b/.github/workflows/build-app-service-image.yaml new file mode 100644 index 0000000..f7ae654 --- /dev/null +++ b/.github/workflows/build-app-service-image.yaml @@ -0,0 +1,68 @@ +name: Image Build + +on: + workflow_call: + secrets: + NPM_TOKEN: + required: true + AWS_USER_ACCESS_KEY_ID: + required: true + AWS_USER_ACCESS_KEY_SECRET: + required: true + JENKINS_USER: + required: true + JENKINS_TOKEN: + required: true + inputs: + node_v: + type: string + required: false + default: "12.14.1" + service_name: + type: string + required: true +env: + ## Sets environment variable + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + NODE_OPTIONS: "--max-old-space-size=4096" + +jobs: + build_image: + # Containers must run in Linux based operating systems + runs-on: app_backend + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + with: + persist-credentials: false + - name: setup node + uses: actions/setup-node@master + with: + node-version: ${{ inputs.node_v }} + - name: Extract branch name + run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" + id: extract_branch + - name: echo branch + run: | + echo ${{ steps.extract_branch.outputs.branch }} + - name: Build and push image + uses: totango/shared-github-actions/.github/actions/build-image@main + id: image + with: + aws_user_id: ${{secrets.AWS_USER_ACCESS_KEY_ID}} + aws_user_secret: ${{secrets.AWS_USER_ACCESS_KEY_SECRET}} + service_name: ${{ inputs.service_name }} + - name: Deploy new version + if: steps.extract_branch.outputs.branch == 'develop' + uses: leanix/jenkins-action@master + env: + JENKINS_USER: ${{ secrets.JENKINS_USER }} + JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }} + with: + jobBuildUrl: https://jenkins.totango.com/job/kube_deploy_tool/buildWithParameters + parameters: | + Action=deploy + Components=${{ inputs.service_name }} + Environment=test + Custom_Version=${{steps.image.outputs.version}} From 98b74b0822b47d9d803d88c072d5d076b27bac6d Mon Sep 17 00:00:00 2001 From: dav-sap Date: Tue, 7 Jun 2022 09:37:42 +0300 Subject: [PATCH 2/5] try this --- .github/actions/build-image/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/build-image/action.yml b/.github/actions/build-image/action.yml index 6a6b235..e507eea 100644 --- a/.github/actions/build-image/action.yml +++ b/.github/actions/build-image/action.yml @@ -48,7 +48,7 @@ runs: ECR_REPOSITORY: ${{ inputs.service_name }} IMAGE_TAG: ${{ steps.vars.outputs.sha_short }} run: | - docker build -t $ECR_REPOSITORY:$IMAGE_TAG --no-cache --build-arg NPM_TOKEN=${{ inputs.npm_token }} --build-arg BRANCH_NAME=develop . + docker build -t $ECR_REPOSITORY:$IMAGE_TAG --no-cache --build-arg NPM_TOKEN=${{ secrets.NPM_TOKEN }} --build-arg BRANCH_NAME=develop . docker tag $ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG aws dynamodb put-item --table-name versions-mgmt --item "{\"service\": {\"S\": \"${{inputs.service_name}}\"}, \"version\": {\"S\": \"${{ steps.vars.outputs.sha_short }}\"}, \"timestamp\": {\"N\": \"${{ steps.vars.outputs.current_time }}\"}}" --region us-east-1 \ No newline at end of file From fa9c0459369f2a4e06a3564f9c9670587ca82c22 Mon Sep 17 00:00:00 2001 From: dav-sap Date: Tue, 7 Jun 2022 10:37:12 +0300 Subject: [PATCH 3/5] move to input --- .github/actions/build-image/action.yml | 2 +- .github/workflows/build-app-service-image.yaml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/actions/build-image/action.yml b/.github/actions/build-image/action.yml index e507eea..6a6b235 100644 --- a/.github/actions/build-image/action.yml +++ b/.github/actions/build-image/action.yml @@ -48,7 +48,7 @@ runs: ECR_REPOSITORY: ${{ inputs.service_name }} IMAGE_TAG: ${{ steps.vars.outputs.sha_short }} run: | - docker build -t $ECR_REPOSITORY:$IMAGE_TAG --no-cache --build-arg NPM_TOKEN=${{ secrets.NPM_TOKEN }} --build-arg BRANCH_NAME=develop . + docker build -t $ECR_REPOSITORY:$IMAGE_TAG --no-cache --build-arg NPM_TOKEN=${{ inputs.npm_token }} --build-arg BRANCH_NAME=develop . docker tag $ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG aws dynamodb put-item --table-name versions-mgmt --item "{\"service\": {\"S\": \"${{inputs.service_name}}\"}, \"version\": {\"S\": \"${{ steps.vars.outputs.sha_short }}\"}, \"timestamp\": {\"N\": \"${{ steps.vars.outputs.current_time }}\"}}" --region us-east-1 \ No newline at end of file diff --git a/.github/workflows/build-app-service-image.yaml b/.github/workflows/build-app-service-image.yaml index f7ae654..3f5b8e1 100644 --- a/.github/workflows/build-app-service-image.yaml +++ b/.github/workflows/build-app-service-image.yaml @@ -53,6 +53,7 @@ jobs: aws_user_id: ${{secrets.AWS_USER_ACCESS_KEY_ID}} aws_user_secret: ${{secrets.AWS_USER_ACCESS_KEY_SECRET}} service_name: ${{ inputs.service_name }} + npm_token: ${{secrets.NPM_TOKEN}} - name: Deploy new version if: steps.extract_branch.outputs.branch == 'develop' uses: leanix/jenkins-action@master From 3c78144b820167307f1ba0ee990bb5cd15a6fcb9 Mon Sep 17 00:00:00 2001 From: dav-sap Date: Tue, 7 Jun 2022 10:37:53 +0300 Subject: [PATCH 4/5] update --- .github/workflows/build-app-service-image.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-app-service-image.yaml b/.github/workflows/build-app-service-image.yaml index 3f5b8e1..8735c3a 100644 --- a/.github/workflows/build-app-service-image.yaml +++ b/.github/workflows/build-app-service-image.yaml @@ -47,7 +47,7 @@ jobs: run: | echo ${{ steps.extract_branch.outputs.branch }} - name: Build and push image - uses: totango/shared-github-actions/.github/actions/build-image@main + uses: ../actions/build-image/action.yml id: image with: aws_user_id: ${{secrets.AWS_USER_ACCESS_KEY_ID}} From 89f332721b4d9b8636922b150ab89a66b5d89f80 Mon Sep 17 00:00:00 2001 From: dav-sap Date: Tue, 7 Jun 2022 10:39:59 +0300 Subject: [PATCH 5/5] fix location --- .github/workflows/build-app-service-image.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-app-service-image.yaml b/.github/workflows/build-app-service-image.yaml index 8735c3a..3f5b8e1 100644 --- a/.github/workflows/build-app-service-image.yaml +++ b/.github/workflows/build-app-service-image.yaml @@ -47,7 +47,7 @@ jobs: run: | echo ${{ steps.extract_branch.outputs.branch }} - name: Build and push image - uses: ../actions/build-image/action.yml + uses: totango/shared-github-actions/.github/actions/build-image@main id: image with: aws_user_id: ${{secrets.AWS_USER_ACCESS_KEY_ID}}