diff --git a/.github/workflows/ec2-integration-test.yml b/.github/workflows/ec2-integration-test.yml index f3d4db89b7..6f0ba4f1b7 100644 --- a/.github/workflows/ec2-integration-test.yml +++ b/.github/workflows/ec2-integration-test.yml @@ -77,7 +77,7 @@ jobs: if: steps.cache_if_success.outputs.cache-hit != 'true' uses: nick-fields/retry@v2 with: - max_attempts: 3 + max_attempts: 1 timeout_minutes: 60 retry_wait_seconds: 5 command: | @@ -114,7 +114,7 @@ jobs: if: ${{ cancelled() || failure() }} uses: nick-fields/retry@v2 with: - max_attempts: 3 + max_attempts: 1 timeout_minutes: 8 retry_wait_seconds: 5 command: cd ${{ inputs.test_dir }} && terraform destroy --auto-approve \ No newline at end of file diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index ade0a8b3e5..f81c5f880c 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -150,50 +150,50 @@ jobs: # cd test/test/cloudformation # go test -timeout 1h -package_path=s3://${S3_INTEGRATION_BUCKET}/integration-test/binary/${{ github.sha }}/linux/amd64/amazon-cloudwatch-agent.rpm -iam_role=${CF_IAM_ROLE} -key_name=${CF_KEY_NAME} -metric_name=mem_used_percent -# StartLocalStack: -# name: 'StartLocalStack' -# runs-on: ubuntu-latest -# defaults: -# run: -# working-directory: terraform/ec2/localstack -# outputs: -# local_stack_host_name: ${{ steps.localstack.outputs.local_stack_host_name }} -# permissions: -# id-token: write -# contents: read -# steps: -# - uses: actions/checkout@v3 -# with: -# repository: ${{env.CWA_GITHUB_TEST_REPO_NAME}} -# ref: ${{env.CWA_GITHUB_TEST_REPO_BRANCH}} -# -# - name: Configure AWS Credentials -# uses: aws-actions/configure-aws-credentials@v2 -# with: -# role-to-assume: ${{ env.TERRAFORM_AWS_ASSUME_ROLE }} -# aws-region: us-west-2 -# role-duration-seconds: ${{ env.TERRAFORM_AWS_ASSUME_ROLE_DURATION }} -# -# - name: Verify Terraform version -# run: terraform --version -# -# - name: Terraform init -# run: terraform init -# -# - name: Terraform apply -# id: localstack -# run: > -# echo run terraform and execute test code && -# terraform apply --auto-approve -# -var="ssh_key_value=${PRIVATE_KEY}" -# -var="github_test_repo=${{env.CWA_GITHUB_TEST_REPO_URL}}" -# -var="cwa_github_sha=${GITHUB_SHA}" -# -var="s3_bucket=${S3_INTEGRATION_BUCKET}" -# -var="ssh_key_name=${KEY_NAME}" && -# LOCAL_STACK_HOST_NAME=$(terraform output -raw public_dns) && -# echo $LOCAL_STACK_HOST_NAME && -# echo "::set-output name=local_stack_host_name::$LOCAL_STACK_HOST_NAME" && -# aws s3 cp terraform.tfstate s3://${S3_INTEGRATION_BUCKET}/integration-test/local-stack-terraform-state/${GITHUB_SHA}/terraform.tfstate + StartLocalStack: + name: 'StartLocalStack' + runs-on: ubuntu-latest + defaults: + run: + working-directory: terraform/ec2/localstack + outputs: + local_stack_host_name: ${{ steps.localstack.outputs.local_stack_host_name }} + permissions: + id-token: write + contents: read + steps: + - uses: actions/checkout@v3 + with: + repository: ${{env.CWA_GITHUB_TEST_REPO_NAME}} + ref: ${{env.CWA_GITHUB_TEST_REPO_BRANCH}} + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: ${{ env.TERRAFORM_AWS_ASSUME_ROLE }} + aws-region: us-west-2 + role-duration-seconds: ${{ env.TERRAFORM_AWS_ASSUME_ROLE_DURATION }} + + - name: Verify Terraform version + run: terraform --version + + - name: Terraform init + run: terraform init + + - name: Terraform apply + id: localstack + run: > + echo run terraform and execute test code && + terraform apply --auto-approve + -var="ssh_key_value=${PRIVATE_KEY}" + -var="github_test_repo=${{env.CWA_GITHUB_TEST_REPO_URL}}" + -var="cwa_github_sha=${GITHUB_SHA}" + -var="s3_bucket=${S3_INTEGRATION_BUCKET}" + -var="ssh_key_name=${KEY_NAME}" && + LOCAL_STACK_HOST_NAME=$(terraform output -raw public_dns) && + echo $LOCAL_STACK_HOST_NAME && + echo "::set-output name=local_stack_host_name::$LOCAL_STACK_HOST_NAME" && + aws s3 cp terraform.tfstate s3://${S3_INTEGRATION_BUCKET}/integration-test/local-stack-terraform-state/${GITHUB_SHA}/terraform.tfstate # EC2NvidiaGPUIntegrationTest: # needs: [ BuildAndUpload, StartLocalStack, GenerateTestMatrix ] @@ -341,20 +341,20 @@ jobs: # echo "CWA_GITHUB_TEST_REPO_URL: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_URL }}" # echo "CWA_GITHUB_TEST_REPO_BRANCH: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_BRANCH }}" -# EC2LinuxIntegrationTest: -# needs: [ BuildAndUpload, StartLocalStack, GenerateTestMatrix, OutputEnvVariables ] -# name: 'EC2Linux' -# uses: ./.github/workflows/ec2-integration-test.yml -# with: -# github_sha: ${{github.sha}} -# test_dir: terraform/ec2/linux -# job_id: ec2-linux-integration-test -# test_props: ${{needs.GenerateTestMatrix.outputs.ec2_linux_matrix}} -# test_repo_name: ${{ needs.OutputEnvVariables.outputs.CWA_GITHUB_TEST_REPO_NAME }} -# test_repo_url: ${{ needs.OutputEnvVariables.outputs.CWA_GITHUB_TEST_REPO_URL }} -# test_repo_branch: ${{ needs.OutputEnvVariables.outputs.CWA_GITHUB_TEST_REPO_BRANCH }} -# localstack_host: ${{needs.StartLocalStack.outputs.local_stack_host_name}} -# secrets: inherit + EC2LinuxIntegrationTest: + needs: [ BuildAndUpload, StartLocalStack, GenerateTestMatrix, OutputEnvVariables ] + name: 'EC2Linux' + uses: ./.github/workflows/ec2-integration-test.yml + with: + github_sha: ${{github.sha}} + test_dir: terraform/ec2/linux + job_id: ec2-linux-integration-test + test_props: ${{needs.GenerateTestMatrix.outputs.ec2_linux_matrix}} + test_repo_name: ${{ needs.OutputEnvVariables.outputs.CWA_GITHUB_TEST_REPO_NAME }} + test_repo_url: ${{ needs.OutputEnvVariables.outputs.CWA_GITHUB_TEST_REPO_URL }} + test_repo_branch: ${{ needs.OutputEnvVariables.outputs.CWA_GITHUB_TEST_REPO_BRANCH }} + localstack_host: ${{needs.StartLocalStack.outputs.local_stack_host_name}} + secrets: inherit # LinuxOnPremIntegrationTest: # needs: [BuildAndUpload, StartLocalStack, GenerateTestMatrix, OutputEnvVariables] @@ -738,72 +738,72 @@ jobs: # fi # terraform destroy --auto-approve - EKSIntegrationTest: - name: 'EKSIntegrationTest' - runs-on: ubuntu-latest - needs: [ BuildAndUpload, GenerateTestMatrix ] - strategy: - fail-fast: false - matrix: - arrays: ${{ fromJson(needs.GenerateTestMatrix.outputs.eks_daemon_matrix) }} - permissions: - id-token: write - contents: read - steps: - - uses: actions/checkout@v3 - with: - repository: ${{env.CWA_GITHUB_TEST_REPO_NAME}} - ref: ${{env.CWA_GITHUB_TEST_REPO_BRANCH}} - - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - role-to-assume: ${{ env.TERRAFORM_AWS_ASSUME_ROLE }} - aws-region: us-west-2 - role-duration-seconds: ${{ env.TERRAFORM_AWS_ASSUME_ROLE_DURATION }} - - - name: Cache if success - id: eks-ec2-integration-test - uses: actions/cache@v3 - with: - path: go.mod - key: eks-ec2-integration-test-${{ github.sha }}-${{ matrix.arrays.os }}-${{ matrix.arrays.test_dir }} - - - name: Login ECR - id: login-ecr - if: steps.eks-ec2-integration-test.outputs.cache-hit != 'true' - uses: aws-actions/amazon-ecr-login@v1 - - - name: Verify Terraform version - if: steps.eks-ec2-integration-test.outputs.cache-hit != 'true' - run: terraform --version - - - name: Terraform apply - if: steps.eks-ec2-integration-test.outputs.cache-hit != 'true' - uses: nick-fields/retry@v2 - with: - max_attempts: 1 - timeout_minutes: 60 # EKS takes about 20 minutes to spin up a cluster and service on the cluster - retry_wait_seconds: 5 - command: | - if [ "${{ matrix.arrays.terraform_dir }}" != "" ]; then - cd "${{ matrix.arrays.terraform_dir }}" - else - cd terraform/eks/daemon - fi - - terraform init - if terraform apply --auto-approve \ - -var="test_dir=${{ matrix.arrays.test_dir }}"\ - -var="cwagent_image_repo=${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_INTEGRATION_TEST_REPO }}" \ - -var="cwagent_image_tag=${{ github.sha }}" \ - -var="ami_type=${{ matrix.arrays.ami }}" \ - -var="instance_type=${{ matrix.arrays.instanceType }}" \ - -var="k8s_version=${{ matrix.arrays.k8s_version }}"; then - terraform destroy -auto-approve - else - terraform destroy -auto-approve && exit 1 - fi +# EKSIntegrationTest: +# name: 'EKSIntegrationTest' +# runs-on: ubuntu-latest +# needs: [ BuildAndUpload, GenerateTestMatrix ] +# strategy: +# fail-fast: false +# matrix: +# arrays: ${{ fromJson(needs.GenerateTestMatrix.outputs.eks_daemon_matrix) }} +# permissions: +# id-token: write +# contents: read +# steps: +# - uses: actions/checkout@v3 +# with: +# repository: ${{env.CWA_GITHUB_TEST_REPO_NAME}} +# ref: ${{env.CWA_GITHUB_TEST_REPO_BRANCH}} +# +# - name: Configure AWS Credentials +# uses: aws-actions/configure-aws-credentials@v2 +# with: +# role-to-assume: ${{ env.TERRAFORM_AWS_ASSUME_ROLE }} +# aws-region: us-west-2 +# role-duration-seconds: ${{ env.TERRAFORM_AWS_ASSUME_ROLE_DURATION }} +# +# - name: Cache if success +# id: eks-ec2-integration-test +# uses: actions/cache@v3 +# with: +# path: go.mod +# key: eks-ec2-integration-test-${{ github.sha }}-${{ matrix.arrays.os }}-${{ matrix.arrays.test_dir }} +# +# - name: Login ECR +# id: login-ecr +# if: steps.eks-ec2-integration-test.outputs.cache-hit != 'true' +# uses: aws-actions/amazon-ecr-login@v1 +# +# - name: Verify Terraform version +# if: steps.eks-ec2-integration-test.outputs.cache-hit != 'true' +# run: terraform --version +# +# - name: Terraform apply +# if: steps.eks-ec2-integration-test.outputs.cache-hit != 'true' +# uses: nick-fields/retry@v2 +# with: +# max_attempts: 1 +# timeout_minutes: 60 # EKS takes about 20 minutes to spin up a cluster and service on the cluster +# retry_wait_seconds: 5 +# command: | +# if [ "${{ matrix.arrays.terraform_dir }}" != "" ]; then +# cd "${{ matrix.arrays.terraform_dir }}" +# else +# cd terraform/eks/daemon +# fi +# +# terraform init +# if terraform apply --auto-approve \ +# -var="test_dir=${{ matrix.arrays.test_dir }}"\ +# -var="cwagent_image_repo=${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_INTEGRATION_TEST_REPO }}" \ +# -var="cwagent_image_tag=${{ github.sha }}" \ +# -var="ami_type=${{ matrix.arrays.ami }}" \ +# -var="instance_type=${{ matrix.arrays.instanceType }}" \ +# -var="k8s_version=${{ matrix.arrays.k8s_version }}"; then +# terraform destroy -auto-approve +# else +# terraform destroy -auto-approve && exit 1 +# fi # - name: Terraform destroy # if: ${{ cancelled() || failure() }}