Skip to content

Commit

Permalink
Remove hardcoded module definitions in CI
Browse files Browse the repository at this point in the history
For reasons described in [^1], we hard coded `aws` or `kubernetes` for
the env var `MODULE`, when no file changes were detected under
`modules/` per project.

This commit reverts this and brings back the default behavior which is
not to set the MODULE env var when nothing has changed.

Turns out that module tests also require the right GOX_FLAGS.
This PR sets the GOX_FLAGS mirroring the Jenkins setup[^2].

[^1]: elastic/ingest-dev#2993
[^2]: https://github.com/elastic/beats/blob/0371883dffd6fba0c01e164aeee8b412f1681bff/Jenkinsfile#L642
  • Loading branch information
dliappis committed May 10, 2024
1 parent 760208b commit f8a5d80
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 24 deletions.
31 changes: 31 additions & 0 deletions .buildkite/hooks/pre-command
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@ set -euo pipefail

source .buildkite/env-scripts/util.sh

isUnix() {
# return 0 if it's Linux or macOS and 1 if anything else (e.g. Windows)
local OS=$(uname -o | tr '[:upper:]' '[:lower:]')
if [[ $OS == *"linux"* || $OS == *"darwin"* ]]; then
return 0
else
return 1
fi
}

isArm() {
# return 0 if it's arm architecture (32 or 64bit), 1 otherwise
local MACHINE=$(uname -m | tr '[:upper:]' '[:lower:]')
if [[ $MACHINE == *"arm"* || $MACHINE == *"aarch"* ]]; then
return 0
else
return 1
fi
}

if isUnix && isArm; then
export GOX_FLAGS="-arch arm"
elif isUnix; then
export GOX_FLAGS="-arch amd64"
else
# windows etc.
export GOX_FLAGS="-arch amd64"
fi

echo "~~~ Setting env var GOX_FLAGS to [$GOX_FLAGS]"

# Secrets must be redacted
# https://buildkite.com/docs/pipelines/managing-log-output#redacted-environment-variables
AWS_SERVICE_ACCOUNT_SECRET_PATH="kv/ci-shared/platform-ingest/aws_account_auth"
Expand Down
3 changes: 1 addition & 2 deletions .buildkite/metricbeat/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ steps:
# defines the MODULE env var based on what's changed in a PR
source .buildkite/scripts/changesets.sh
defineModuleFromTheChangeSet metricbeat
echo "~~~ Will run tests with env var MODULE=$$MODULE"
# TODO move this section to base image / pre-command hook
echo "~~~ Installing kind"
Expand Down Expand Up @@ -86,7 +85,7 @@ steps:
# defines the MODULE env var based on what's changed in a PR
source .buildkite/scripts/changesets.sh
defineModuleFromTheChangeSet metricbeat
echo "~~~ Running tests with env var MODULE=$$MODULE"
echo "~~~ Running tests"
# TODO move this section to base image / pre-command hook
echo "~~~ Installing kind"
Expand Down
13 changes: 5 additions & 8 deletions .buildkite/scripts/changesets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,10 @@ defineModuleFromTheChangeSet() {
fi
done

if [[ -z "$changed_modules" ]]; then # TODO: remove this conditional when issue https://github.com/elastic/ingest-dev/issues/2993 gets resolved
if [[ "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-metricbeat" ]]; then
export MODULE="aws"
else
export MODULE="kubernetes"
fi
else
export MODULE="${changed_modules}" # TODO: once https://github.com/elastic/ingest-dev/issues/2993 gets resolved, this should be the only thing we export
# export MODULE="" leads to an infinite loop https://github.com/elastic/ingest-dev/issues/2993
if [[ ! -z $changed_modules ]]; then
export MODULE="${changed_modules}"
echo "~~~ Set env var MODULE to [$MODULE]"
echo "~~~ Resuming commands"
fi
}
1 change: 0 additions & 1 deletion .buildkite/x-pack/pipeline.xpack.auditbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ steps:
# defines the MODULE env var based on what's changed in a PR
source .buildkite/scripts/changesets.sh
defineModuleFromTheChangeSet x-pack/auditbeat
echo "~~~ Will run tests with env var MODULE=$$MODULE"
cd x-pack/auditbeat
mage update build test
retry:
Expand Down
3 changes: 0 additions & 3 deletions .buildkite/x-pack/pipeline.xpack.dockerlogbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@ steps:
# defines the MODULE env var based on what's changed in a PR
source .buildkite/scripts/changesets.sh
defineModuleFromTheChangeSet x-pack/dockerlogbeat
echo "~~~ Running tests with env var MODULE=$$MODULE"
cd x-pack/dockerlogbeat
mage goIntegTest
env:
MODULE: $MODULE
retry:
automatic:
- limit: 3
Expand Down
5 changes: 1 addition & 4 deletions .buildkite/x-pack/pipeline.xpack.filebeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ steps:
# defines the MODULE env var based on what's changed in a PR
source .buildkite/scripts/changesets.sh
defineModuleFromTheChangeSet x-pack/filebeat
echo "~~~ Will run tests with env var MODULE=$$MODULE"
cd x-pack/filebeat && mage goIntegTest
retry:
automatic:
Expand All @@ -74,7 +73,6 @@ steps:
# defines the MODULE env var based on what's changed in a PR
source .buildkite/scripts/changesets.sh
defineModuleFromTheChangeSet x-pack/filebeat
echo "~~~ Running tests with env var MODULE=$$MODULE"
cd x-pack/filebeat && mage pythonIntegTest
retry:
automatic:
Expand Down Expand Up @@ -268,7 +266,7 @@ steps:
# defines the MODULE env var based on what's changed in a PR
source .buildkite/scripts/changesets.sh
defineModuleFromTheChangeSet x-pack/filebeat
echo "~~~ Running tests with env var MODULE=$$MODULE"
echo "~~~ Running tests"
.buildkite/scripts/cloud_tests.sh
env:
Expand Down Expand Up @@ -297,7 +295,6 @@ steps:
# defines the MODULE env var based on what's changed in a PR
source .buildkite/scripts/changesets.sh
defineModuleFromTheChangeSet x-pack/filebeat
echo "~~~ Running tests with env var MODULE=$$MODULE"
.buildkite/scripts/cloud_tests.sh
env:
ASDF_TERRAFORM_VERSION: 1.0.2
Expand Down
6 changes: 2 additions & 4 deletions .buildkite/x-pack/pipeline.xpack.metricbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ steps:
# defines the MODULE env var based on what's changed in a PR
source .buildkite/scripts/changesets.sh
defineModuleFromTheChangeSet x-pack/metricbeat
echo "~~~ Will run tests with env var MODULE=$$MODULE"
cd x-pack/metricbeat && mage goIntegTest
retry:
automatic:
Expand All @@ -74,7 +73,7 @@ steps:
# defines the MODULE env var based on what's changed in a PR
source .buildkite/scripts/changesets.sh
defineModuleFromTheChangeSet x-pack/metricbeat
echo "~~~ Running tests with env var MODULE=$$MODULE"
echo "~~~ Running tests"
cd x-pack/metricbeat && mage pythonIntegTest
retry:
automatic:
Expand Down Expand Up @@ -253,7 +252,7 @@ steps:
# defines the MODULE env var based on what's changed in a PR
source .buildkite/scripts/changesets.sh
defineModuleFromTheChangeSet x-pack/metricbeat
echo "~~~ Running tests with env var MODULE=$$MODULE"
echo "~~~ Running tests"
.buildkite/scripts/cloud_tests.sh
env:
Expand Down Expand Up @@ -284,7 +283,6 @@ steps:
# defines the MODULE env var based on what's changed in a PR
source .buildkite/scripts/changesets.sh
defineModuleFromTheChangeSet x-pack/metricbeat
echo "~~~ Running tests with env var MODULE=$$MODULE"
.buildkite/scripts/cloud_tests.sh
env:
ASDF_TERRAFORM_VERSION: 1.0.2
Expand Down
2 changes: 0 additions & 2 deletions .buildkite/x-pack/pipeline.xpack.winlogbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ steps:
Write-Output "~~~ Will run tests with env var MODULE=$$Env:MODULE"
Set-Location -Path x-pack/winlogbeat
mage build unitTest
env:
MODULE: $MODULE
retry:
automatic:
- limit: 3
Expand Down

0 comments on commit f8a5d80

Please sign in to comment.