Skip to content

Commit f4cb313

Browse files
michel-latermanmergify[bot]
authored andcommitted
Convert Makefile to magefile.go (#4912)
Reimplement Makefile targets in mage. Change buildkite pipeline to use mage. Change Dockerfile* to use mage. (cherry picked from commit db5f46b) # Conflicts: # .buildkite/pipeline.yml # .buildkite/scripts/common.sh # .buildkite/scripts/local_build.sh # .buildkite/scripts/test-release.sh # Dockerfile.build # Dockerfile.fips # Makefile # NOTICE.txt # README.md # dev-tools/cloud/Makefile # dev-tools/cloud/terraform/main.tf # dev-tools/e2e/Dockerfile # dev-tools/e2e/build.sh # dev-tools/e2e/validatecerts.go # dev-tools/go.mod # dev-tools/go.sum # docs/developers-guide.md # docs/docker-images.md # docs/fips.md # testing/e2e/fips_test.go
1 parent 6df11a1 commit f4cb313

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+16065
-12479
lines changed

.buildkite/pipeline.yml

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22

33
env:
44
DOCKER_COMPOSE_VERSION: "1.25.5"
5-
DOCKER_REGISTRY: "docker.elastic.co"
6-
DOCKER_IMAGE: "${DOCKER_REGISTRY}/observability-ci/fleet-server" # needs to rename for rollback
7-
DOCKER_IMAGE_SHA_TAG: "git-${BUILDKITE_COMMIT:0:12}" # needs to rename for rollback, should be "git-${BUILDKITE_COMMIT:0:12}"
8-
DOCKER_IMAGE_LATEST_TAG: "latest" # needs to rename for rollback
9-
DOCKER_IMAGE_GIT_TAG: "${BUILDKITE_BRANCH}" # needs to rename for rollback
10-
GO_AGENT_IMAGE: "golang:${GO_VERSION}"
115
TERRAFORM_VERSION: "1.6.4"
126

137
steps:
@@ -16,19 +10,15 @@ steps:
1610
steps:
1711
- label: ":white_check_mark: Run check-ci"
1812
key: check-ci
19-
command: "make check-ci"
13+
command: ".buildkite/scripts/check_ci.sh"
2014
agents:
21-
image: "${GO_AGENT_IMAGE}"
22-
cpu: "8"
23-
memory: "4G"
15+
provider: "gcp"
2416

2517
- label: ":building_construction: Run local build"
2618
key: make-local
27-
command: "make local"
19+
command: ".buildkite/scripts/local_build.sh"
2820
agents:
29-
image: "${GO_AGENT_IMAGE}"
30-
cpu: "8"
31-
memory: "4G"
21+
provider: "gcp"
3222

3323
- label: ":building_construction: Run local build: MacOS"
3424
key: make-local-macos
@@ -43,6 +33,8 @@ steps:
4333
- label: "Run go benchmark for PR branch"
4434
key: "go-benchmark-pr"
4535
command: ".buildkite/scripts/run_benchmark.sh pr"
36+
env:
37+
BENCHMARK_ARGS: "-count=8 -benchmem"
4638
artifact_paths:
4739
- build/next.out
4840
- build/next.stat
@@ -51,8 +43,11 @@ steps:
5143
machineType: "c2-standard-8"
5244

5345
- label: "Run go benchmark for ${BUILDKITE_PULL_REQUEST_BASE_BRANCH}"
46+
skip: true # FIXME: Temporarily disabled until mage is on main
5447
key: "go-benchmark-base"
5548
command: ".buildkite/scripts/run_benchmark.sh base"
49+
env:
50+
BENCHMARK_ARGS: "-count=8 -benchmem"
5651
artifact_paths:
5752
- build/base.out
5853
- build/base.stat
@@ -61,6 +56,7 @@ steps:
6156
machineType: "c2-standard-8"
6257

6358
- label: "Compare results"
59+
skip: true # FIXME: Temporarily disabled until mage is on main
6460
key: "go-benchmark-compare"
6561
command: ".buildkite/scripts/run_benchmark.sh compare"
6662
artifact_paths:
@@ -87,6 +83,31 @@ steps:
8783
- build/*.xml
8884
- build/coverage*.out
8985

86+
<<<<<<< HEAD
87+
=======
88+
- label: ":smartbear-testexecute: Run unit tests with requirefips build tag"
89+
key: unit-test-fips-tag
90+
command: ".buildkite/scripts/unit_test.sh"
91+
env:
92+
FIPS: "true"
93+
agents:
94+
provider: "gcp"
95+
artifact_paths:
96+
- build/*.xml
97+
- build/coverage*.out
98+
99+
- label: ":smartbear-testexecute: Run fips140=only unit tests"
100+
key: unit-test-fips140-only
101+
command: ".buildkite/scripts/unit_test_fipsonly.sh"
102+
env:
103+
FIPS: "true"
104+
agents:
105+
provider: "gcp"
106+
artifact_paths:
107+
- build/*.xml
108+
- build/coverage*.out
109+
110+
>>>>>>> db5f46b (Convert Makefile to magefile.go (#4912))
90111
- label: ":smartbear-testexecute: Run unit tests: MacOS 13"
91112
key: unit-test-macos-13
92113
command: ".buildkite/scripts/unit_test.sh"
@@ -111,13 +132,25 @@ steps:
111132
- label: "E2E Test"
112133
key: "e2e-test"
113134
command: ".buildkite/scripts/e2e_test.sh"
135+
<<<<<<< HEAD
114136
env:
115137
TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED: "true"
138+
=======
139+
>>>>>>> db5f46b (Convert Makefile to magefile.go (#4912))
116140
agents:
117141
provider: "gcp"
118142
artifact_paths:
119143
- build/*.xml
120144
- build/e2e-coverage.out
145+
<<<<<<< HEAD
146+
=======
147+
plugins:
148+
- test-collector#v1.10.2:
149+
files: "build/test-*.xml"
150+
format: "junit"
151+
branches: "main"
152+
debug: true
153+
>>>>>>> db5f46b (Convert Makefile to magefile.go (#4912))
121154

122155
- label: ":junit: Junit annotate"
123156
plugins:
@@ -154,6 +187,13 @@ steps:
154187

155188
- label: ":gcloud: Cloud e2e Test"
156189
key: "cloud-e2e-test"
190+
env:
191+
DOCKER_REGISTRY: "docker.elastic.co"
192+
DOCKER_IMAGE: "docker.elastic.co/beats-ci/elastic-agent-cloud-fleet"
193+
DOCKER_IMAGE_TAG: "pr-${BUILDKITE_PULL_REQUEST}-${BUILDKITE_COMMIT:0:12}"
194+
SNAPSHOT: "true"
195+
PLATFORMS: "linux/amd64"
196+
TF_VAR_pull_request: "${BUILDKITE_PULL_REQUEST}"
157197
command: ".buildkite/scripts/cloud_e2e_test.sh"
158198
agents:
159199
provider: "gcp"
@@ -169,6 +209,12 @@ steps:
169209
- label: ":docker: Publish docker image"
170210
key: "publish"
171211
command: ".buildkite/scripts/build_push_docker_image.sh"
212+
env:
213+
DOCKER_REGISTRY: "docker.elastic.co"
214+
DOCKER_IMAGE: "docker.elastic.co/observability-ci/fleet-server" # needs to rename for rollback
215+
DOCKER_IMAGE_SHA_TAG: "git-${BUILDKITE_COMMIT:0:12}" # needs to rename for rollback, should be "git-${BUILDKITE_COMMIT:0:12}"
216+
DOCKER_IMAGE_LATEST_TAG: "latest" # needs to rename for rollback
217+
DOCKER_IMAGE_GIT_TAG: "${BUILDKITE_BRANCH}" # needs to rename for rollback
172218
if: "build.env('BUILDKITE_PULL_REQUEST') == 'false' && build.env('BUILDKITE_BRANCH') == 'main'"
173219
agents:
174220
provider: "gcp"

.buildkite/scripts/build_push_docker_image.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ set -euo pipefail
44

55
source .buildkite/scripts/common.sh
66

7+
add_bin_path
8+
9+
with_go
10+
11+
with_mage
12+
713
echo "Building the docker image..."
814
if ! docker pull -q ${DOCKER_IMAGE}:${DOCKER_IMAGE_SHA_TAG} 2> /dev/null; then
915
DOCKER_IMAGE_TAG="${DOCKER_IMAGE_SHA_TAG}"
10-
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG} make build-and-push-docker
16+
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG} mage docker:image docker:push
1117
fi
1218

1319
if [[ "${DOCKER_IMAGE_GIT_TAG}" == "main" ]]; then
14-
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_LATEST_TAG}" make build-and-push-docker
20+
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_LATEST_TAG}" mage docker:image docker:push
1521
elif [[ ${BUILDKITE_PULL_REQUEST} == "false" ]]; then
16-
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_GIT_TAG}" make build-and-push-docker
22+
DOCKER_IMAGE=${DOCKER_IMAGE} DOCKER_IMAGE_TAG="${DOCKER_IMAGE_GIT_TAG}" mage docker:image docker:push
1723
fi

.buildkite/scripts/check_ci.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
source .buildkite/scripts/common.sh
6+
7+
add_bin_path
8+
9+
with_go
10+
11+
with_mage
12+
13+
mage check:ci

.buildkite/scripts/cloud_e2e_test.sh

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,37 @@ with_Terraform
1212

1313
with_docker_compose
1414

15-
USER=fleetserverci make test-cloude2e
15+
with_mage
16+
17+
cleanup() {
18+
r=$?
19+
20+
if [ -f dev-tools/cloud/terraform/.terraform.lock.hcl ] ; then
21+
echo "--- Deployment detected, running cleanup."
22+
mage test:cloudE2EDown
23+
else
24+
echo "--- No deployment detected, skipping cleanup."
25+
fi
26+
exit $r
27+
}
28+
trap cleanup EXIT INT TERM
29+
30+
USER=fleetserverci mage docker:cover docker:customAgentImage docker:push test:cloudE2EUp
31+
FLEET_SERVER_URL=$(terraform output --raw --state=dev-tools/cloud/terraform/terraform.tfstate fleet_url)
32+
echo "Fleet server: \"${FLEET_SERVER_URL}\""
33+
echo "Deployment ID: $(terraform output --raw --state=dev-tools/cloud/terraform/terraform.tfstate deployment_id)"
34+
35+
if [[ "${FLEET_SERVER_URL}" == "" ]]; then
36+
message="FLEET_SERVER_URL is empty, cloud e2e tests cannot be executed"
37+
if [[ "${CI}" == "true" ]]; then
38+
buildkite-agent annotate \
39+
"${message}" \
40+
--context "ctx-cloude2e-test" \
41+
--style "error"
42+
fi
43+
echo "${message}"
44+
exit 0
45+
fi
46+
47+
echo "--- Trigger cloud E2E test"
48+
mage test:cloudE2ERun

.buildkite/scripts/common.sh

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ with_go() {
5151
export PATH="${PATH}:$(go env GOPATH):$(go env GOPATH)/bin"
5252
}
5353

54+
<<<<<<< HEAD
55+
=======
56+
with_msft_go() {
57+
echo "Setting up microsoft/go"
58+
create_workspace
59+
check_platform_architeture
60+
MSFT_DOWNLOAD_URL=https://aka.ms/golang/release/latest/go$(cat .go-version).${platform_type}-${arch_type}.tar.gz
61+
retry 5 $(curl -sL -o - $MSFT_DOWNLOAD_URL | tar -xz -f - -C ${WORKSPACE})
62+
export PATH="${PATH}:${WORKSPACE}/go/bin"
63+
go version
64+
which go
65+
export PATH="${PATH}:$(go env GOPATH)/bin"
66+
}
67+
68+
>>>>>>> db5f46b (Convert Makefile to magefile.go (#4912))
5469
with_docker_compose() {
5570
echo "Setting up the Docker-compose environment..."
5671
create_workspace
@@ -136,17 +151,11 @@ download_mbp_packages_from_gcp_bucket() {
136151
}
137152

138153
with_mage() {
139-
local install_packages=(
140-
"github.com/magefile/mage"
141-
"github.com/elastic/go-licenser"
142-
"golang.org/x/tools/cmd/goimports"
143-
"github.com/jstemmer/go-junit-report"
144-
"gotest.tools/gotestsum"
145-
)
146154
create_workspace
147-
for pkg in "${install_packages[@]}"; do
148-
go install "${pkg}@latest"
149-
done
155+
go install github.com/magefile/mage # uses go.mod implicitly
156+
mage -clean
157+
mage -version
158+
which mage
150159
}
151160

152161
cleanup() {

.buildkite/scripts/dra_release.sh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ set -euo pipefail
44

55
source .buildkite/scripts/common.sh
66

7+
add_bin_path
8+
9+
with_go
10+
11+
with_mage
12+
713
FOLDER_PATH="build/distributions"
814
BASE_DIR="${WORKSPACE}/${FOLDER_PATH}"
915
DRA_OUTPUT="release-manager.out"
@@ -12,7 +18,7 @@ export TYPE=${1}
1218
# DRA_BRANCH can be used for manually testing packaging with PRs
1319
# e.g. define `DRA_BRANCH="main"` under Options/Environment Variables in the Buildkite UI after clicking new Build
1420
export BRANCH="${DRA_BRANCH:="${BUILDKITE_BRANCH:=""}"}"
15-
export VERSION="$(make get-version)"
21+
export VERSION="$(mage getVersion)"
1622

1723
if [[ "${VERSION}" == *"-SNAPSHOT"* || "${VERSION}" == "" ]]; then
1824
echo "The 'version' parameter is required and it cannot contain the suffix '-SNAPSHOT'."
@@ -24,14 +30,7 @@ if [[ "${PROJECT}" == "" ]]; then
2430
exit 1
2531
fi
2632

27-
add_bin_path
28-
2933
download_mbp_packages_from_gcp_bucket "${FOLDER_PATH}" "${TYPE}"
30-
31-
with_go
32-
33-
with_mage
34-
3534
export RM_VERSION="${VERSION}"
3635

3736
if [[ ${TYPE} == "snapshot" ]]; then

.buildkite/scripts/e2e_test.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ with_go
1010

1111
with_docker_compose
1212

13+
with_mage
14+
1315
echo "Starting the E2E tests..."
14-
make test-e2e junit-report
16+
mage test:e2e test:junitReport

.buildkite/scripts/integration_test.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ with_go
1010

1111
with_docker_compose
1212

13+
with_mage
14+
1315
echo "Starting the integration tests..."
14-
make test-int junit-report
16+
mage test:integration test:junitReport

.buildkite/scripts/local_build.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@ source .buildkite/scripts/common.sh
77
add_bin_path
88
with_go
99

10-
make local
10+
<<<<<<< HEAD
11+
make local
12+
=======
13+
with_mage
14+
15+
mage build:local
16+
>>>>>>> db5f46b (Convert Makefile to magefile.go (#4912))

.buildkite/scripts/package.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ with_mage
2727
case "${TYPE}" in
2828
"snapshot")
2929
export SNAPSHOT=true
30-
make release
30+
mage build:release
3131
;;
3232
"staging")
33-
make release
33+
mage build:release
3434
;;
3535
*)
3636
echo "The option is unsupported yet"

0 commit comments

Comments
 (0)