diff --git a/.github/workflows/deploy-k8s.yml b/.github/workflows/deploy-k8s.yml index 62f350ced0..8a97ffe378 100644 --- a/.github/workflows/deploy-k8s.yml +++ b/.github/workflows/deploy-k8s.yml @@ -12,6 +12,7 @@ env: aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: ${{ secrets.AWS_REGION }} aws-url: ${{ secrets.AWS_URL }} + pull_req_id: ${{github.event.pull_request.number}} DATE: $(date -d '-1 day' '+%Y-%m-%d'|sed 's/-//g') CI_PACKAGE_BRANCH: ${{github.event.pull_request.head.ref || 'develop' }} CI_PROJECT: ${{github.event.pull_request.head.repo.name || 'processmaker' }} @@ -19,70 +20,82 @@ env: DEPLOY: ${{ secrets.DEPLOY }} GH_USER: ${{ secrets.GH_USER }} GH_EMAIL: ${{ secrets.GH_EMAIL }} + GITHUB_COMMENT: ${{ secrets.GH_COMMENT }} + DOM_EKS: ${{ secrets.DOM_EKS }} concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: - imageEKS: - name: build-docker-image-EKS - if: contains(github.event.pull_request.body, 'ci:build-k8s') - runs-on: ubuntu-22.04 - steps: - #- uses: actions/checkout@v3 - - name: Clone repo K8S - run: | - git clone --depth 1 -b cicd "https://$DEPLOY@github.com/ProcessMaker/pm4-k8s-distribution.git" pm4-k8s-distribution - - name: Generate image EKS - run: | - cd pm4-k8s-distribution - bash ./images/build.local.sh $CI_PACKAGE_BRANCH ${{env.IMAGE_TAG}} - - name: List Images - run: | - docker images - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ env.aws-access-key-id }} - aws-secret-access-key: ${{ env.aws-secret-access-key }} - aws-region: ${{ env.aws-region }} - - name: Login to ECR - run: | - aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/processmaker - - name: Push OpenSource Image to ECR - run: | - cd pm4-k8s-distribution - docker tag local/processmaker:${{env.IMAGE_TAG}} public.ecr.aws/processmaker/processmaker:${{env.IMAGE_TAG}} - docker push public.ecr.aws/processmaker/processmaker:${{env.IMAGE_TAG}} - - name: Push Enterprise Image to ECR - run: | - cd pm4-k8s-distribution - docker tag local/enterprise:${{env.IMAGE_TAG}} public.ecr.aws/processmaker/enterprise:${{env.IMAGE_TAG}} - docker push public.ecr.aws/processmaker/enterprise:${{env.IMAGE_TAG}} + #imageEKS: + # name: build-docker-image-EKS + # if: contains(github.event.pull_request.body, 'ci:build-k8s') + # runs-on: ubuntu-22.04 + # steps: + # #- uses: actions/checkout@v3 + # - name: Clone repo K8S + # run: | + # git clone --depth 1 -b cicd "https://$DEPLOY@github.com/ProcessMaker/pm4-k8s-distribution.git" pm4-k8s-distribution + # - name: Generate image EKS + # run: | + # cd pm4-k8s-distribution + # bash ./images/build.local.sh $CI_PACKAGE_BRANCH ${{env.IMAGE_TAG}} + # - name: List Images + # run: | + # docker images + # - name: Configure AWS Credentials + # uses: aws-actions/configure-aws-credentials@v1 + # with: + # aws-access-key-id: ${{ env.aws-access-key-id }} + # aws-secret-access-key: ${{ env.aws-secret-access-key }} + # aws-region: ${{ env.aws-region }} + # - name: Login to ECR + # run: | + # aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/processmaker + # - name: Push OpenSource Image to ECR + # run: | + # cd pm4-k8s-distribution + # docker tag local/processmaker:${{env.IMAGE_TAG}} public.ecr.aws/processmaker/processmaker:${{env.IMAGE_TAG}} + # docker push public.ecr.aws/processmaker/processmaker:${{env.IMAGE_TAG}} + # - name: Push Enterprise Image to ECR + # run: | + # cd pm4-k8s-distribution + # docker tag local/enterprise:${{env.IMAGE_TAG}} public.ecr.aws/processmaker/enterprise:${{env.IMAGE_TAG}} + # docker push public.ecr.aws/processmaker/enterprise:${{env.IMAGE_TAG}} deployEKS: name: build-deploy-EKS if: contains(github.event.pull_request.body, 'ci:build-k8s') - needs: imageEKS + #needs: imageEKS runs-on: ubuntu-22.04 steps: - name: Clone private repository run: | git clone --depth 1 -b main "https://$DEPLOY@github.com/ProcessMaker/argocd.git" argocd cd argocd - - run: git config --global user.email "$GH_EMAIL" - - run: git config --global user.name "$GH_USER" + - run: git config --global user.email $GH_EMAIL + - run: git config --global user.name $GH_USER - name: Add instance EKS run: | cd argocd deploy=$(echo -n ${{env.IMAGE_TAG}} | md5sum | head -c 10) - cp template-argocd.yaml ci/ci-$deploy.yaml - cp template-db.yaml ./ci/job_database.yaml - sed -i "s/{{instance}}/ci-$deploy/" ./ci/ci-$deploy.yaml - sed -i "s/{{image}}/${{env.IMAGE_TAG}}/" ./ci/ci-$deploy.yaml - sed -i "s/{{instance}}/ci-$deploy/" ./ci/job_database.yaml - git status - git add . - git commit -m "Deploy CICD : ci-$deploy" - git push origin main + if ! echo $(ls ci/) | grep $deploy; then + echo "Creating Deploy :: $deploy" + cp template-argocd.yaml ci/ci-$deploy.yaml + cp template-db.yaml ./ci/job_database.yaml + sed -i "s/{{instance}}/ci-$deploy/" ./ci/ci-$deploy.yaml + sed -i "s/{{image}}/${{env.IMAGE_TAG}}/" ./ci/ci-$deploy.yaml + sed -i "s/{{instance}}/ci-$deploy/" ./ci/job_database.yaml + git status + git add . + git commit -m "Deploy CICD : ci-$deploy" + git push origin main + else + echo "Exist Deploy :: https://ci-$deploy$DOM_EKS" + fi + echo "INSTANCE_URL=https://ci-$deploy$DOM_EKS" >> "$GITHUB_ENV" + - name: Comment Instance + run: | + echo "Instance URL: '${INSTANCE_URL}'" + bash argocd/gh_comment.sh "$CI_PROJECT" "$pull_req_id" deleteEKS: name: Delete Instance if: github.event.action == 'closed'