Skip to content

Commit f1bf64d

Browse files
Replace Makefile with magefile.go
Re-implement all used targets in Makefile in mage. Move most utility scripts into magefile. Change buildkite to use mage.
1 parent 9202e6b commit f1bf64d

34 files changed

+13286
-17271
lines changed

.buildkite/pipeline.yml

Lines changed: 13 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:
@@ -31,19 +25,15 @@ steps:
3125
steps:
3226
- label: ":white_check_mark: Run check-ci"
3327
key: check-ci
34-
command: "make check-ci"
28+
command: ".buildkite/scripts/check_ci.sh"
3529
agents:
36-
image: "${GO_AGENT_IMAGE}"
37-
cpu: "8"
38-
memory: "4G"
30+
provider: "gcp"
3931

4032
- label: ":building_construction: Run local build"
4133
key: make-local
42-
command: "make local"
34+
command: ".buildkite/scripts/local_build.sh"
4335
agents:
44-
image: "${GO_AGENT_IMAGE}"
45-
cpu: "8"
46-
memory: "4G"
36+
provider: "gcp"
4737

4838
- label: ":building_construction: Run local build: MacOS"
4939
key: make-local-macos
@@ -58,6 +48,8 @@ steps:
5848
- label: "Run go benchmark for PR branch"
5949
key: "go-benchmark-pr"
6050
command: ".buildkite/scripts/run_benchmark.sh pr"
51+
env:
52+
BENCHMARK_ARGS: "-count=8 -benchmem"
6153
artifact_paths:
6254
- build/next.out
6355
- build/next.stat
@@ -68,6 +60,8 @@ steps:
6860
- label: "Run go benchmark for ${BUILDKITE_PULL_REQUEST_BASE_BRANCH}"
6961
key: "go-benchmark-base"
7062
command: ".buildkite/scripts/run_benchmark.sh base"
63+
env:
64+
BENCHMARK_ARGS: "-count=8 -benchmem"
7165
artifact_paths:
7266
- build/base.out
7367
- build/base.stat
@@ -231,6 +225,11 @@ steps:
231225
- label: ":docker: Publish docker image"
232226
key: "publish"
233227
command: ".buildkite/scripts/build_push_docker_image.sh"
228+
env:
229+
DOCKER_IMAGE: "docker.elastic.co/observability-ci/fleet-server" # needs to rename for rollback
230+
DOCKER_IMAGE_SHA_TAG: "git-${BUILDKITE_COMMIT:0:12}" # needs to rename for rollback, should be "git-${BUILDKITE_COMMIT:0:12}"
231+
DOCKER_IMAGE_LATEST_TAG: "latest" # needs to rename for rollback
232+
DOCKER_IMAGE_GIT_TAG: "${BUILDKITE_BRANCH}" # needs to rename for rollback
234233
if: "build.env('BUILDKITE_PULL_REQUEST') == 'false' && build.env('BUILDKITE_BRANCH') == 'main'"
235234
agents:
236235
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ with_Terraform
1212

1313
with_docker_compose
1414

15+
with_mage
16+
1517
USER=fleetserverci make test-cloude2e

.buildkite/scripts/common.sh

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ with_msft_go() {
5555
echo "Setting up microsoft/go"
5656
create_workspace
5757
check_platform_architeture
58-
MSFT_DOWNLOAD_URL=https://aka.ms/golang/release/latest/go$(cat .go-version)-1.${platform_type}-${arch_type}.tar.gz
58+
MSFT_DOWNLOAD_URL=https://aka.ms/golang/release/latest/go$(cat .go-version).${platform_type}-${arch_type}.tar.gz
5959
retry 5 $(curl -sL -o - $MSFT_DOWNLOAD_URL | tar -xz -f - -C ${WORKSPACE})
6060
export PATH="${PATH}:${WORKSPACE}/go/bin"
6161
go version
@@ -155,17 +155,9 @@ download_mbp_packages_from_gcp_bucket() {
155155
}
156156

157157
with_mage() {
158-
local install_packages=(
159-
"github.com/magefile/mage"
160-
"github.com/elastic/go-licenser"
161-
"golang.org/x/tools/cmd/goimports"
162-
"github.com/jstemmer/go-junit-report"
163-
"gotest.tools/gotestsum"
164-
)
165158
create_workspace
166-
for pkg in "${install_packages[@]}"; do
167-
go install "${pkg}@latest"
168-
done
159+
go install github.com/magefile/mage@latest
160+
mage -clean
169161
}
170162

171163
cleanup() {

.buildkite/scripts/dra_release.sh

Lines changed: 8 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,18 +30,12 @@ if [[ "${PROJECT}" == "" ]]; then
2430
exit 1
2531
fi
2632

27-
add_bin_path
28-
2933
google_cloud_auth
3034

3135
download_mbp_packages_from_gcp_bucket "${FOLDER_PATH}" "${TYPE}"
32-
33-
with_go
34-
35-
with_mage
36-
3736
export RM_VERSION="${VERSION}"
3837

38+
3939
if [[ ${TYPE} == "snapshot" ]]; then
4040
export SNAPSHOT=true
4141
VERSION="${VERSION}-SNAPSHOT"

.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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ else
1111
with_go
1212
fi
1313

14-
make local
14+
with_mage
15+
16+
mage build:local

.buildkite/scripts/package.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ with_mage
3535
case "${TYPE}" in
3636
"snapshot")
3737
export SNAPSHOT=true
38-
make release
38+
mage build:release
3939
;;
4040
"staging")
41-
make release
41+
mage build:release
4242
;;
4343
*)
4444
echo "The option is unsupported yet"

0 commit comments

Comments
 (0)