diff --git a/.github/workflows/canaries_prune.yml b/.github/workflows/canaries_prune.yml index 220f99d28..9c1f8e7cb 100644 --- a/.github/workflows/canaries_prune.yml +++ b/.github/workflows/canaries_prune.yml @@ -12,6 +12,9 @@ on: - linux - windows required: false + tag: + description: 'Tag to prune' + required: true permissions: id-token: write @@ -22,5 +25,6 @@ jobs: uses: ./.github/workflows/component_canaries_prune.yml with: PLATFORM: ${{ github.event.inputs.platform }} + TAG: ${{ github.event.inputs.tag }} secrets: AWS_VPC_SUBNET: ${{secrets.AWS_VPC_SUBNET}} diff --git a/.github/workflows/component_canaries.yml b/.github/workflows/component_canaries.yml index 000ae73dd..61675e6d9 100644 --- a/.github/workflows/component_canaries.yml +++ b/.github/workflows/component_canaries.yml @@ -28,8 +28,9 @@ permissions: id-token: write jobs: - canaries: + canaries_macos: runs-on: ubuntu-20.04 + if: ${{ inputs.PLATFORM == 'macos' }} steps: - uses: actions/checkout@v2 @@ -59,3 +60,161 @@ jobs: aws_vpc_subnet: ${{ secrets.AWS_VPC_SUBNET }} repo_name: "newrelic/infrastructure-agent" ref: "${{ env.GIT_BRANCH }}" + + canaries_linux: + runs-on: ubuntu-20.04 + if: ${{ inputs.PLATFORM == 'linux' }} + steps: + - uses: actions/checkout@v2 + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + role-to-assume: ${{ env.AWS_ASSUME_ROLE }} + aws-region: us-east-2 + + - name: Set branch name + run: | + # Short name for current branch. For PRs, use target branch (base ref) + GIT_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} + # Is the ref a tag? If so, remove refs/tags/ prefix + GIT_BRANCH=${GIT_BRANCH#refs/tags/} + echo "GIT_BRANCH=$GIT_BRANCH" >> $GITHUB_ENV + + - name: Add to env current and previous versions + run: .github/workflows/scripts/set_version.sh ${{ inputs.TAG }} + + - name: set vars for legibility (state, inventory ...) + run: | + echo "PREVIOUS_TERRAFORM_STATE=canaries-${{ inputs.PLATFORM }}-${{ env.PREVIOUS_NR_VERSION }}" >> $GITHUB_ENV + echo "TERRAFORM_STATE=canaries-${{ inputs.PLATFORM }}-${{ inputs.TAG }}" >> $GITHUB_ENV + echo "INVENTORY_OUTPUT=/srv/runner/inventory/canary-${{ inputs.TAG }}-${{ inputs.PLATFORM }}-inventory.ec2" >> $GITHUB_ENV + + - name: Provision instances ${{ inputs.PLATFORM }} + uses: newrelic/fargate-runner-action@main + with: + aws_region: us-east-2 + container_make_target: "test/provision TERRAFORM_STATE_KEY=${{ env.TERRAFORM_STATE }} PREFIX=canary INVENTORY_OUTPUT=${{ env.INVENTORY_OUTPUT }} TAG_OR_UNIQUE_NAME=${{ inputs.TAG }} PLATFORM=${{ inputs.PLATFORM }} CROWDSTRIKE_CLIENT_ID=${{ secrets.CROWDSTRIKE_CLIENT_ID }} CROWDSTRIKE_CLIENT_SECRET=${{ secrets.CROWDSTRIKE_CLIENT_SECRET }} CROWDSTRIKE_CUSTOMER_ID=${{ secrets.CROWDSTRIKE_CUSTOMER_ID }}" + ecs_cluster_name: caos_infra_agent + task_definition_name: infra-agent + cloud_watch_logs_group_name: /ecs/test-prerelease-infra-agent + cloud_watch_logs_stream_name: ecs/test-prerelease + aws_vpc_subnet: ${{ secrets.AWS_VPC_SUBNET }} + repo_name: "newrelic/infrastructure-agent" + ref: "${{ env.GIT_BRANCH }}" + log_filters: | + \[ALLOW_MSG\].+ + TASK\s\[.*\]\s + PLAY\s\[.*\]\s + PLAY\sRECAP\s + Apply\scomplete! + ok=\d+\s+changed=\d+\s+unreachable=\d+\s+failed=\d+\s+skipped=\d+\s+rescued=\d+\s+ignored=\d+ + + - name: Install Infra Agent + uses: newrelic/fargate-runner-action@main + with: + aws_region: us-east-2 + container_make_target: "terraform-canaries ANSIBLE_INVENTORY=${{ env.INVENTORY_OUTPUT }} PLATFORM=${{ inputs.PLATFORM }} ANSIBLE_FORKS=${{ env.ANSIBLE_FORKS }} VERSION=${{ env.NR_VERSION }} PREVIOUS_VERSION=${{ env.PREVIOUS_NR_VERSION }} CROWDSTRIKE_CLIENT_ID=${{ secrets.CROWDSTRIKE_CLIENT_ID }} CROWDSTRIKE_CLIENT_SECRET=${{ secrets.CROWDSTRIKE_CLIENT_SECRET }} CROWDSTRIKE_CUSTOMER_ID=${{ secrets.CROWDSTRIKE_CUSTOMER_ID }}" + ecs_cluster_name: caos_infra_agent + task_definition_name: infra-agent + cloud_watch_logs_group_name: /ecs/test-prerelease-infra-agent + cloud_watch_logs_stream_name: ecs/test-prerelease + aws_vpc_subnet: ${{ secrets.AWS_VPC_SUBNET }} + repo_name: "newrelic/infrastructure-agent" + ref: "${{ env.GIT_BRANCH }}" + + canaries_windows: + runs-on: ubuntu-20.04 + if: ${{ inputs.PLATFORM == 'windows' }} + steps: + - uses: actions/checkout@v2 + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + role-to-assume: ${{ env.AWS_ASSUME_ROLE }} + aws-region: us-east-2 + + - name: Set branch name + run: | + # Short name for current branch. For PRs, use target branch (base ref) + GIT_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} + # Is the ref a tag? If so, remove refs/tags/ prefix + GIT_BRANCH=${GIT_BRANCH#refs/tags/} + echo "GIT_BRANCH=$GIT_BRANCH" >> $GITHUB_ENV + + - name: Add to env current and previous versions + run: .github/workflows/scripts/set_version.sh ${{ inputs.TAG }} + + - name: set vars for legibility (state, inventory ...) + run: | + echo "TERRAFORM_STATE_PREVIOUS=canaries-${{ inputs.PLATFORM }}-${{ inputs.TAG }}-previous" >> $GITHUB_ENV + echo "TERRAFORM_STATE_CURRENT=canaries-${{ inputs.PLATFORM }}-${{ inputs.TAG }}-current" >> $GITHUB_ENV + echo "INVENTORY_PREVIOUS=/srv/runner/inventory/canary-${{ inputs.TAG }}-${{ inputs.PLATFORM }}-previous-inventory.ec2" >> $GITHUB_ENV + echo "INVENTORY_CURRENT=/srv/runner/inventory/canary-${{ inputs.TAG }}-${{ inputs.PLATFORM }}-current-inventory.ec2" >> $GITHUB_ENV + + - name: Provision instances ${{ inputs.PLATFORM }} previous + uses: newrelic/fargate-runner-action@main + with: + aws_region: us-east-2 + container_make_target: "test/provision TERRAFORM_STATE_KEY=${{ env.TERRAFORM_STATE_PREVIOUS }} PREFIX=canary INVENTORY_OUTPUT=${{ env.INVENTORY_PREVIOUS }} TAG_OR_UNIQUE_NAME=${{ env.PREVIOUS_NR_VERSION }} PLATFORM=${{ inputs.PLATFORM }} CROWDSTRIKE_CLIENT_ID=${{ secrets.CROWDSTRIKE_CLIENT_ID }} CROWDSTRIKE_CLIENT_SECRET=${{ secrets.CROWDSTRIKE_CLIENT_SECRET }} CROWDSTRIKE_CUSTOMER_ID=${{ secrets.CROWDSTRIKE_CUSTOMER_ID }}" + ecs_cluster_name: caos_infra_agent + task_definition_name: infra-agent + cloud_watch_logs_group_name: /ecs/test-prerelease-infra-agent + cloud_watch_logs_stream_name: ecs/test-prerelease + aws_vpc_subnet: ${{ secrets.AWS_VPC_SUBNET }} + repo_name: "newrelic/infrastructure-agent" + ref: "${{ env.GIT_BRANCH }}" + log_filters: | + \[ALLOW_MSG\].+ + TASK\s\[.*\]\s + PLAY\s\[.*\]\s + PLAY\sRECAP\s + Apply\scomplete! + ok=\d+\s+changed=\d+\s+unreachable=\d+\s+failed=\d+\s+skipped=\d+\s+rescued=\d+\s+ignored=\d+ + + - name: Provision instances ${{ inputs.PLATFORM }} current + uses: newrelic/fargate-runner-action@main + with: + aws_region: us-east-2 + container_make_target: "test/provision TERRAFORM_STATE_KEY=${{ env.TERRAFORM_STATE_CURRENT }} PREFIX=canary INVENTORY_OUTPUT=${{ env.INVENTORY_CURRENT }} TAG_OR_UNIQUE_NAME=${{ env.NR_VERSION }} PLATFORM=${{ inputs.PLATFORM }} CROWDSTRIKE_CLIENT_ID=${{ secrets.CROWDSTRIKE_CLIENT_ID }} CROWDSTRIKE_CLIENT_SECRET=${{ secrets.CROWDSTRIKE_CLIENT_SECRET }} CROWDSTRIKE_CUSTOMER_ID=${{ secrets.CROWDSTRIKE_CUSTOMER_ID }}" + ecs_cluster_name: caos_infra_agent + task_definition_name: infra-agent + cloud_watch_logs_group_name: /ecs/test-prerelease-infra-agent + cloud_watch_logs_stream_name: ecs/test-prerelease + aws_vpc_subnet: ${{ secrets.AWS_VPC_SUBNET }} + repo_name: "newrelic/infrastructure-agent" + ref: "${{ env.GIT_BRANCH }}" + log_filters: | + \[ALLOW_MSG\].+ + TASK\s\[.*\]\s + PLAY\s\[.*\]\s + PLAY\sRECAP\s + Apply\scomplete! + ok=\d+\s+changed=\d+\s+unreachable=\d+\s+failed=\d+\s+skipped=\d+\s+rescued=\d+\s+ignored=\d+ + + - name: Install Infra Agent previous + uses: newrelic/fargate-runner-action@main + with: + aws_region: us-east-2 + container_make_target: "terraform-canaries ANSIBLE_INVENTORY=${{ env.INVENTORY_PREVIOUS }} PLATFORM=${{ inputs.PLATFORM }} ANSIBLE_FORKS=${{ env.ANSIBLE_FORKS }} VERSION=${{ env.PREVIOUS_NR_VERSION }} PREVIOUS_VERSION='NOT_USED_VALUE' CROWDSTRIKE_CLIENT_ID=${{ secrets.CROWDSTRIKE_CLIENT_ID }} CROWDSTRIKE_CLIENT_SECRET=${{ secrets.CROWDSTRIKE_CLIENT_SECRET }} CROWDSTRIKE_CUSTOMER_ID=${{ secrets.CROWDSTRIKE_CUSTOMER_ID }}" + ecs_cluster_name: caos_infra_agent + task_definition_name: infra-agent + cloud_watch_logs_group_name: /ecs/test-prerelease-infra-agent + cloud_watch_logs_stream_name: ecs/test-prerelease + aws_vpc_subnet: ${{ secrets.AWS_VPC_SUBNET }} + repo_name: "newrelic/infrastructure-agent" + ref: "${{ env.GIT_BRANCH }}" + + - name: Install Infra Agent current + uses: newrelic/fargate-runner-action@main + with: + aws_region: us-east-2 + container_make_target: "terraform-canaries ANSIBLE_INVENTORY=${{ env.INVENTORY_CURRENT }} PLATFORM=${{ inputs.PLATFORM }} ANSIBLE_FORKS=${{ env.ANSIBLE_FORKS }} VERSION=${{ env.NR_VERSION }} PREVIOUS_VERSION='NOT_USED_VALUE' CROWDSTRIKE_CLIENT_ID=${{ secrets.CROWDSTRIKE_CLIENT_ID }} CROWDSTRIKE_CLIENT_SECRET=${{ secrets.CROWDSTRIKE_CLIENT_SECRET }} CROWDSTRIKE_CUSTOMER_ID=${{ secrets.CROWDSTRIKE_CUSTOMER_ID }}" + ecs_cluster_name: caos_infra_agent + task_definition_name: infra-agent + cloud_watch_logs_group_name: /ecs/test-prerelease-infra-agent + cloud_watch_logs_stream_name: ecs/test-prerelease + aws_vpc_subnet: ${{ secrets.AWS_VPC_SUBNET }} + repo_name: "newrelic/infrastructure-agent" + ref: "${{ env.GIT_BRANCH }}" diff --git a/.github/workflows/component_canaries_prune.yml b/.github/workflows/component_canaries_prune.yml index 65bea11ff..ef5171a9b 100644 --- a/.github/workflows/component_canaries_prune.yml +++ b/.github/workflows/component_canaries_prune.yml @@ -7,6 +7,9 @@ on: required: true inputs: + TAG: + required: true + type: string PLATFORM: required: true type: string @@ -19,8 +22,9 @@ permissions: id-token: write jobs: - canaries-prune: - if: ${{ always() }} + + canaries-prune-linux: + if: ${{ inputs.PLATFORM == 'linux' || inputs.PLATFORM == '' }} runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 @@ -39,11 +43,80 @@ jobs: GIT_BRANCH=${GIT_BRANCH#refs/tags/} echo "GIT_BRANCH=$GIT_BRANCH" >> $GITHUB_ENV - - name: Prune old canaries + - name: set vars for legibility (state, inventory ...) + run: | + echo "TERRAFORM_STATE=canaries-linux-${{ inputs.TAG }}" >> $GITHUB_ENV + + - name: Clean previous canaries instances Linux + uses: newrelic/fargate-runner-action@main + with: + aws_region: us-east-2 + container_make_target: "test/provision/clean TERRAFORM_STATE_KEY=${{ env.TERRAFORM_STATE }} PREFIX=canary INVENTORY_OUTPUT=NOT_USED TAG_OR_UNIQUE_NAME=${{ inputs.TAG }} PLATFORM=linux CROWDSTRIKE_CLIENT_ID=${{ secrets.CROWDSTRIKE_CLIENT_ID }} CROWDSTRIKE_CLIENT_SECRET=${{ secrets.CROWDSTRIKE_CLIENT_SECRET }} CROWDSTRIKE_CUSTOMER_ID=${{ secrets.CROWDSTRIKE_CUSTOMER_ID }}" + ecs_cluster_name: caos_infra_agent + task_definition_name: infra-agent + cloud_watch_logs_group_name: /ecs/test-prerelease-infra-agent + cloud_watch_logs_stream_name: ecs/test-prerelease + aws_vpc_subnet: ${{ secrets.AWS_VPC_SUBNET }} + repo_name: "newrelic/infrastructure-agent" + ref: "${{ env.GIT_BRANCH }}" + log_filters: | + \[ALLOW_MSG\].+ + TASK\s\[.*\]\s + PLAY\s\[.*\]\s + PLAY\sRECAP\s + Apply\scomplete! + ok=\d+\s+changed=\d+\s+unreachable=\d+\s+failed=\d+\s+skipped=\d+\s+rescued=\d+\s+ignored=\d+ + + canaries-prune-windows: + if: ${{ inputs.PLATFORM == 'windows' || inputs.PLATFORM == '' }} + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + role-to-assume: ${{ env.AWS_ASSUME_ROLE }} + aws-region: us-east-2 + + - name: Set branch name + run: | + # Short name for current branch. For PRs, use target branch (base ref) + GIT_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} + # Is the ref a tag? If so, remove refs/tags/ prefix + GIT_BRANCH=${GIT_BRANCH#refs/tags/} + echo "GIT_BRANCH=$GIT_BRANCH" >> $GITHUB_ENV + + - name: set vars for legibility (state, inventory ...) + run: | + echo "PREVIOUS_TERRAFORM_STATE=canaries-windows-${{ inputs.TAG }}-previous" >> $GITHUB_ENV + echo "TERRAFORM_STATE=canaries-windows-${{ inputs.TAG }}-current" >> $GITHUB_ENV + + - name: Clean previous canaries instances Windows (previous) + uses: newrelic/fargate-runner-action@main + with: + aws_region: us-east-2 + container_make_target: "test/provision/clean TERRAFORM_STATE_KEY=${{ env.PREVIOUS_TERRAFORM_STATE }} PREFIX=canary INVENTORY_OUTPUT=NOT_USED TAG_OR_UNIQUE_NAME=${{ inputs.TAG }} PLATFORM=windows CROWDSTRIKE_CLIENT_ID=${{ secrets.CROWDSTRIKE_CLIENT_ID }} CROWDSTRIKE_CLIENT_SECRET=${{ secrets.CROWDSTRIKE_CLIENT_SECRET }} CROWDSTRIKE_CUSTOMER_ID=${{ secrets.CROWDSTRIKE_CUSTOMER_ID }}" + ecs_cluster_name: caos_infra_agent + task_definition_name: infra-agent + cloud_watch_logs_group_name: /ecs/test-prerelease-infra-agent + cloud_watch_logs_stream_name: ecs/test-prerelease + aws_vpc_subnet: ${{ secrets.AWS_VPC_SUBNET }} + repo_name: "newrelic/infrastructure-agent" + ref: "${{ env.GIT_BRANCH }}" + log_filters: | + \[ALLOW_MSG\].+ + TASK\s\[.*\]\s + PLAY\s\[.*\]\s + PLAY\sRECAP\s + Apply\scomplete! + ok=\d+\s+changed=\d+\s+unreachable=\d+\s+failed=\d+\s+skipped=\d+\s+rescued=\d+\s+ignored=\d+ + + - name: Clean previous canaries instances Windows (current) uses: newrelic/fargate-runner-action@main with: aws_region: us-east-2 - container_make_target: "canaries-prune-auto PLATFORM=${{ inputs.PLATFORM }}" + container_make_target: "test/provision/clean TERRAFORM_STATE_KEY=${{ env.TERRAFORM_STATE }} PREFIX=canary INVENTORY_OUTPUT=NOT_USED TAG_OR_UNIQUE_NAME=${{ inputs.TAG }} PLATFORM=windows CROWDSTRIKE_CLIENT_ID=${{ secrets.CROWDSTRIKE_CLIENT_ID }} CROWDSTRIKE_CLIENT_SECRET=${{ secrets.CROWDSTRIKE_CLIENT_SECRET }} CROWDSTRIKE_CUSTOMER_ID=${{ secrets.CROWDSTRIKE_CUSTOMER_ID }}" ecs_cluster_name: caos_infra_agent task_definition_name: infra-agent cloud_watch_logs_group_name: /ecs/test-prerelease-infra-agent @@ -51,3 +124,10 @@ jobs: aws_vpc_subnet: ${{ secrets.AWS_VPC_SUBNET }} repo_name: "newrelic/infrastructure-agent" ref: "${{ env.GIT_BRANCH }}" + log_filters: | + \[ALLOW_MSG\].+ + TASK\s\[.*\]\s + PLAY\s\[.*\]\s + PLAY\sRECAP\s + Apply\scomplete! + ok=\d+\s+changed=\d+\s+unreachable=\d+\s+failed=\d+\s+skipped=\d+\s+rescued=\d+\s+ignored=\d+ diff --git a/.github/workflows/component_prerelease_testing.yml b/.github/workflows/component_prerelease_testing.yml index 65ba05cb1..761f59f8d 100644 --- a/.github/workflows/component_prerelease_testing.yml +++ b/.github/workflows/component_prerelease_testing.yml @@ -59,7 +59,7 @@ jobs: uses: newrelic/fargate-runner-action@main with: aws_region: us-east-2 - container_make_target: "test/provision PREFIX=pkg-tests INVENTORY_OUTPUT=/srv/runner/inventory/${{ inputs.TAG_OR_UNIQUE_NAME }}-inventory.ec2 TAG_OR_UNIQUE_NAME=${{ inputs.TAG_OR_UNIQUE_NAME }} PLATFORM=${{ inputs.PLATFORM }} CROWDSTRIKE_CLIENT_ID=${{ secrets.CROWDSTRIKE_CLIENT_ID }} CROWDSTRIKE_CLIENT_SECRET=${{ secrets.CROWDSTRIKE_CLIENT_SECRET }} CROWDSTRIKE_CUSTOMER_ID=${{ secrets.CROWDSTRIKE_CUSTOMER_ID }}" + container_make_target: "test/provision TERRAFORM_STATE_KEY=${{ inputs.TAG_OR_UNIQUE_NAME }} PREFIX=pkg-tests INVENTORY_OUTPUT=/srv/runner/inventory/${{ inputs.TAG_OR_UNIQUE_NAME }}-inventory.ec2 TAG_OR_UNIQUE_NAME=${{ inputs.TAG_OR_UNIQUE_NAME }} PLATFORM=${{ inputs.PLATFORM }} CROWDSTRIKE_CLIENT_ID=${{ secrets.CROWDSTRIKE_CLIENT_ID }} CROWDSTRIKE_CLIENT_SECRET=${{ secrets.CROWDSTRIKE_CLIENT_SECRET }} CROWDSTRIKE_CUSTOMER_ID=${{ secrets.CROWDSTRIKE_CUSTOMER_ID }}" ecs_cluster_name: caos_infra_agent task_definition_name: infra-agent cloud_watch_logs_group_name: /ecs/test-prerelease-infra-agent @@ -208,7 +208,7 @@ jobs: uses: newrelic/fargate-runner-action@main with: aws_region: us-east-2 - container_make_target: "test/provision/clean TAG_OR_UNIQUE_NAME=${{ inputs.TAG_OR_UNIQUE_NAME }}" + container_make_target: "test/provision/clean TERRAFORM_STATE_KEY=${{ inputs.TAG_OR_UNIQUE_NAME }} TAG_OR_UNIQUE_NAME=${{ inputs.TAG_OR_UNIQUE_NAME }}" ecs_cluster_name: caos_infra_agent task_definition_name: infra-agent cloud_watch_logs_group_name: /ecs/test-prerelease-infra-agent @@ -249,7 +249,7 @@ jobs: uses: newrelic/fargate-runner-action@main with: aws_region: us-east-2 - container_make_target: "test/provision/clean TAG_OR_UNIQUE_NAME=${{ inputs.TAG_OR_UNIQUE_NAME }}" + container_make_target: "test/provision/clean TERRAFORM_STATE_KEY=${{ inputs.TAG_OR_UNIQUE_NAME }} TAG_OR_UNIQUE_NAME=${{ inputs.TAG_OR_UNIQUE_NAME }}" ecs_cluster_name: caos_infra_agent task_definition_name: infra-agent cloud_watch_logs_group_name: /ecs/test-prerelease-infra-agent diff --git a/.github/workflows/prerelease_canaries.yml b/.github/workflows/prerelease_canaries.yml index e0dc42a2d..1dcca4342 100644 --- a/.github/workflows/prerelease_canaries.yml +++ b/.github/workflows/prerelease_canaries.yml @@ -72,19 +72,32 @@ jobs: CROWDSTRIKE_CLIENT_SECRET: ${{secrets.CROWDSTRIKE_CLIENT_SECRET}} CROWDSTRIKE_CUSTOMER_ID: ${{secrets.CROWDSTRIKE_CUSTOMER_ID}} + get_previous_tag: + runs-on: ubuntu-20.04 + # Map a step output to a job output + outputs: + previous_tag: ${{ steps.previous_tag_step.outputs.PREVIOUS_TAG }} + steps: + - id: previous_tag_step + run: .github/workflows/scripts/previous_version.sh ${{ inputs.TAG }} >> "$GITHUB_OUTPUT" + prune-previous-canaries-linux: + needs: get_previous_tag if: ${{ github.event.inputs.prune == 'true' && github.event.inputs.linux == 'true' }} uses: ./.github/workflows/component_canaries_prune.yml with: PLATFORM: "linux" + TAG: ${{ needs.get_previous_tag.outputs.previous_tag }} secrets: AWS_VPC_SUBNET: ${{secrets.AWS_VPC_SUBNET}} prune-previous-canaries-windows: + needs: get_previous_tag if: ${{ github.event.inputs.prune == 'true' && github.event.inputs.windows == 'true' }} uses: ./.github/workflows/component_canaries_prune.yml with: PLATFORM: "windows" + TAG: ${{ needs.get_previous_tag.outputs.previous_tag }} secrets: AWS_VPC_SUBNET: ${{secrets.AWS_VPC_SUBNET}} @@ -94,4 +107,4 @@ jobs: with: TAG: ${{ github.event.inputs.tag }} secrets: - AWS_VPC_SUBNET: ${{secrets.AWS_VPC_SUBNET}} \ No newline at end of file + AWS_VPC_SUBNET: ${{secrets.AWS_VPC_SUBNET}} diff --git a/.github/workflows/scripts/previous_version.sh b/.github/workflows/scripts/previous_version.sh new file mode 100755 index 000000000..3f53307ab --- /dev/null +++ b/.github/workflows/scripts/previous_version.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -e + +# this script accetps a tag as input and it will search and output for the previous one +# for GHA +# if no tag is passed as parameter, the latest one will be used + +# fetch the history (including tags) from within a shallow clone like CI-GHA +# supress error when the repository is a complete one. +git fetch --prune --unshallow 2> /dev/null || true + +TAG=$1 +if [ -z $TAG ];then + TAG=$( git tag | grep -E "^[0-9]+\.[0-9]+\.[0-9]$" | sort | tail -n 1 ) +fi + +# print previous tag +PREVIOUS_TAG=$( git tag | grep -E "^[0-9]+\.[0-9]+\.[0-9]$" | sort | grep -B 1 $TAG | head -n 1 ) + +echo "PREVIOUS_TAG=$PREVIOUS_TAG" diff --git a/.github/workflows/scripts/set_version.sh b/.github/workflows/scripts/set_version.sh new file mode 100755 index 000000000..ef511e1a5 --- /dev/null +++ b/.github/workflows/scripts/set_version.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -e + +# this script acceps a tag as input and it will search for the previous one and set both as env vars +# for GHA +# if no tag is passed as parameter, the latest one will be used + +# fetch the history (including tags) from within a shallow clone like CI-GHA +# supress error when the repository is a complete one. +git fetch --prune --unshallow 2> /dev/null || true + +TAG=$1 +if [ -z $TAG ];then + TAG=$( git tag | grep -E "^[0-9]+\.[0-9]+\.[0-9]$" | sort | tail -n 1 ) +fi + +PREVIOUS_TAG=$( git tag | grep -E "^[0-9]+\.[0-9]+\.[0-9]$" | sort | grep -B 1 $TAG | head -n 1 ) + +# Set the variables for later use in the GHA pipeline +{ + echo "NR_VERSION=${TAG}" + echo "PREVIOUS_NR_VERSION=${PREVIOUS_TAG}" +} >> "$GITHUB_ENV" diff --git a/Makefile b/Makefile index 87e3250d4..aab90b6f0 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,9 @@ include $(INCLUDE_TEST_DIR)/test.mk # provisioning include $(INCLUDE_TEST_DIR)/provision/Makefile +# canaries +include $(INCLUDE_TEST_DIR)/canaries/Makefile + # tools include $(INCLUDE_TOOLS_DIR)/tools.mk diff --git a/test/canaries/Makefile b/test/canaries/Makefile new file mode 100644 index 000000000..c0b637464 --- /dev/null +++ b/test/canaries/Makefile @@ -0,0 +1,30 @@ +# Include Ansible dependencies common installation strategy +include $(CURDIR)/test/ansible/Ansible.common + +ANSIBLE_FOLDER := $(CURDIR)/test/canaries +ANSIBLE_FORKS ?= 20 + +.DEFAULT_GOAL := canaries + +.PHONY: terraform-canaries +terraform-canaries: ansible/dependencies +ifndef ANSIBLE_INVENTORY + $(error ANSIBLE_INVENTORY is not set) +endif + +ifndef PREVIOUS_VERSION + $(error PREVIOUS_VERSION is not set) +endif + +ifndef VERSION + $(error VERSION is not set) +endif + +ifndef NR_LICENSE_KEY_CANARIES + $(error NR_LICENSE_KEY_CANARIES is not set) +endif + ansible-playbook -f $(ANSIBLE_FORKS) -i $(ANSIBLE_INVENTORY) "$(ANSIBLE_FOLDER)/deploy_canaries.yml" -e "current_version=$(VERSION) previous_version=$(PREVIOUS_VERSION) nr_license_key=$(NR_LICENSE_KEY_CANARIES) docker_username=$(DOCKER_USERNAME) docker_password=$(DOCKER_PASSWORD)" + + +.PHONY: clean +clean: ansible/clean diff --git a/test/canaries/deploy_canaries.yml b/test/canaries/deploy_canaries.yml new file mode 100644 index 000000000..a849d60f6 --- /dev/null +++ b/test/canaries/deploy_canaries.yml @@ -0,0 +1,58 @@ +--- +# Linux +- name: canaries + hosts: testing_hosts_linux + become: true + gather_facts: yes + + tasks: + - name: 🐤Canaries + vars: + enable_process_metrics: true + nria_log_level: "smart" + nria_log_forward: true + nria_log_rotation_mb: 500 + nria_log_rotation_max_files: 5 + nria_log_rotation_compressed: true + forward_docker_logs: true + + block: + + - name: install latest agent on host + include_role: + name: caos.ansible_roles.infra_agent + vars: + target_version: "{{ current_version }}" + + - name: install latest agent in container + include_role: + name: caos.ansible_roles.infra_agent + vars: + is_containerized: true + target_version: "{{ current_version }}" + display_name: "{{ inventory_hostname }}-current" + + - name: install previous agent in container + include_role: + name: caos.ansible_roles.infra_agent + vars: + is_containerized: true + target_version: "{{ previous_version }}" + display_name: "{{ inventory_hostname }}-previous" + +# Windows +- name: installation-agent-no-clean + hosts: testing_hosts_windows + gather_facts: yes + + tasks: + - name: Installation tests suite + + block: + + - name: install agent + include_role: + name: caos.ansible_roles.infra_agent + vars: + target_version: "{{ current_version }}" +... diff --git a/test/canaries/requirements.yml b/test/canaries/requirements.yml new file mode 100644 index 000000000..db3e14dfa --- /dev/null +++ b/test/canaries/requirements.yml @@ -0,0 +1,6 @@ +collections: + - name: git+https://github.com/newrelic-experimental/caos-ansible-roles.git#/caos.ansible_roles/ + type: git + +roles: + - name: geerlingguy.pip diff --git a/test/provision/Makefile b/test/provision/Makefile index 4cc62b962..473b20044 100644 --- a/test/provision/Makefile +++ b/test/provision/Makefile @@ -8,11 +8,16 @@ ANSIBLE_FOLDER := $(CURDIR)/test/provision/terraform .PHONY: terraform/backend terraform/backend: +ifndef TERRAFORM_STATE_KEY + $(error TERRAFORM_STATE_KEY is undefined) +endif + sed "s/TERRAFORM_STATE_KEY/${TERRAFORM_STATE_KEY}/g" "$(TERRAFORM_DIR)/terraform.backend.tf.dist" > "$(TERRAFORM_DIR)/terraform.backend.tf" ifndef TAG_OR_UNIQUE_NAME $(error TAG_OR_UNIQUE_NAME is undefined) endif - sed "s/TAG_OR_UNIQUE_NAME/${TAG_OR_UNIQUE_NAME}/g" "$(TERRAFORM_DIR)/terraform.backend.tf.dist" > "$(TERRAFORM_DIR)/terraform.backend.tf" - sed "s/TAG_OR_UNIQUE_NAME/${TAG_OR_UNIQUE_NAME}/g" "$(TERRAFORM_DIR)/caos-linux.auto.tfvars.dist" > "$(TERRAFORM_DIR)/caos.auto.tfvars" + cp "$(TERRAFORM_DIR)/caos.auto.tfvars.dist" "$(TERRAFORM_DIR)/caos.auto.tfvars" + sed -i -e "s/PREFIX/$(PREFIX)/g" "$(TERRAFORM_DIR)/caos.auto.tfvars" + sed -i -e "s/TAG_OR_UNIQUE_NAME/$(TAG_OR_UNIQUE_NAME)/g" "$(TERRAFORM_DIR)/caos.auto.tfvars" .PHONY: test/provision test/provision: terraform/backend @@ -43,10 +48,10 @@ endif .PHONY: test/provision/clean test/provision/clean: terraform/backend ansible/clean terraform -chdir=$(TERRAFORM_DIR) init -reconfigure && \ + TF_VAR_nr_license_key="$(NR_LICENSE_KEY)" \ TF_VAR_platform="$(PLATFORM)" \ TF_VAR_windows_password="$(ANSIBLE_PASSWORD_WINDOWS)" \ TF_VAR_inventory_output="$(INVENTORY_OUTPUT)" \ - TF_VAR_nr_license_key="$(NR_LICENSE_KEY)" \ terraform -chdir=$(TERRAFORM_DIR) destroy -auto-approve && \ rm "$(TERRAFORM_DIR)/terraform.backend.tf" "$(TERRAFORM_DIR)/caos.auto.tfvars" $(MAKE) ansible/clean ANSIBLE_FOLDER=$(ANSIBLE_FOLDER) diff --git a/test/provision/README.md b/test/provision/README.md index e79647fdb..f20459c9b 100644 --- a/test/provision/README.md +++ b/test/provision/README.md @@ -4,7 +4,7 @@ The purpose of this tool is to easily deploy EC2 instances and run an Ansible playbook to prepare them for further tests. Deployment parameters like the EC2 AMIs and the Ansible playbook can be customized -in the Terraform file [./terraform/caos-linux.auto.tfvars.dist](./terraform/caos-linux.auto.tfvars.dist). Note +in the Terraform file [./terraform/caos.auto.tfvars.dist](./terraform/caos-linux.auto.tfvars.dist). Note that already has some defaults of our environment. Run provisioning: diff --git a/test/provision/terraform/caos-linux.auto.tfvars.dist b/test/provision/terraform/caos.auto.tfvars.dist similarity index 100% rename from test/provision/terraform/caos-linux.auto.tfvars.dist rename to test/provision/terraform/caos.auto.tfvars.dist diff --git a/test/provision/terraform/terraform.backend.tf.dist b/test/provision/terraform/terraform.backend.tf.dist index d6cc1ada1..26ca295f4 100644 --- a/test/provision/terraform/terraform.backend.tf.dist +++ b/test/provision/terraform/terraform.backend.tf.dist @@ -4,7 +4,7 @@ terraform { backend "s3" { bucket = "automation-pipeline-terraform-state" - key = "infra-agent-pipeline/TAG_OR_UNIQUE_NAME" + key = "infra-agent-pipeline/TERRAFORM_STATE_KEY" region = "us-east-2" } }