Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Magefile POC #819

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,8 @@ ARG GOEXPERIMENT
COPY . /src/alloy
WORKDIR /src/alloy

# Build the UI before building Alloy, which will then bake the final UI into
# the binary.
RUN --mount=type=cache,target=/src/alloy/web/ui/node_modules,sharing=locked \
make generate-ui

RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
GOOS=$TARGETOS GOARCH=$TARGETARCH GOARM=${TARGETVARIANT#v} \
RELEASE_BUILD=${RELEASE_BUILD} VERSION=${VERSION} \
GO_TAGS="netgo builtinassets promtail_journal_enabled" \
GOEXPERIMENT=${GOEXPERIMENT} \
make alloy
RUN ./build-linux-amd64 alloy
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add this back in once I tighten everything up


FROM public.ecr.aws/ubuntu/ubuntu:mantic

Expand Down
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ PROPAGATE_VARS := \
ALLOY_IMAGE ALLOY_IMAGE_WINDOWS \
BUILD_IMAGE GOOS GOARCH GOARM CGO_ENABLED RELEASE_BUILD \
ALLOY_BINARY \
BUILD_IMAGE_VERSION \
VERSION GO_TAGS GOEXPERIMENT

#
Expand Down Expand Up @@ -170,6 +171,13 @@ else
$(GO_ENV) go build $(GO_FLAGS) -o $(ALLOY_BINARY) .
endif

alloy-boringcrypto:
ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
$(GO_ENV) go build $(GO_FLAGS) -o $(ALLOY_BINARY) .
endif

# alloy-service is not included in binaries since it's Windows-only.
alloy-service:
ifeq ($(USE_CONTAINER),1)
Expand Down Expand Up @@ -256,7 +264,7 @@ generate-winmanifest:
ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
go generate ./internal/winmanifest
GOOS=linux GOARCH=amd64 go generate ./internal/winmanifest
endif
#
# Other targets
Expand Down Expand Up @@ -297,3 +305,9 @@ info:
.PHONY: help
help:
@awk 'BEGIN {FS="## "} /^##\s*(.*)/ { print $$2 }' $(MAKEFILE_LIST)


magefile:
mage -d ./internal/cmd/build -compile ../../../build-linux-amd64 -goarch=amd64 -goos=linux
mage -d ./internal/cmd/build -compile ../../../build-darwin-amd64 -goarch=amd64 -goos=darwin
mage -d ./internal/cmd/build -compile ../../../build-darwin-arm64 -goarch=arm64 -goos=darwin
Binary file added build-darwin-amd64
Binary file not shown.
Binary file added build-darwin-arm64
Binary file not shown.
Binary file added build-linux-amd64
Binary file not shown.
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ module github.com/grafana/alloy
go 1.22.3

require (
github.com/KimMachineGun/automemlimit v0.6.0
github.com/Shopify/sarama v1.38.1
github.com/aws/aws-sdk-go-v2/service/servicediscovery v1.29.5
github.com/ettle/strcase v0.2.0
github.com/grafana/kafka_exporter v0.0.0-20240409084445-5e3488ad9f9a
github.com/magefile/mage v1.15.0
cloud.google.com/go/pubsub v1.36.1
connectrpc.com/connect v1.14.0
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.10.0
Expand Down Expand Up @@ -34,7 +40,7 @@ require (
github.com/docker/docker v25.0.5+incompatible
github.com/docker/go-connections v0.5.0
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46
github.com/fatih/color v1.15.0
github.com/fatih/color v1.16.0
github.com/fortytw2/leaktest v1.3.0
github.com/fsnotify/fsnotify v1.7.0
github.com/github/smimesign v0.2.0
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A=
github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew=
github.com/ericchiang/k8s v1.2.0/go.mod h1:/OmBgSq2cd9IANnsGHGlEz27nwMZV2YxlpXuQtU3Bz4=
github.com/ettle/strcase v0.2.0 h1:fGNiVF21fHXpX1niBgk0aROov1LagYsOwV/xqKDKR/Q=
github.com/ettle/strcase v0.2.0/go.mod h1:DajmHElDSaX76ITe3/VHVyMin4LWSJN5Z909Wp+ED1A=
github.com/euank/go-kmsg-parser v2.0.0+incompatible h1:cHD53+PLQuuQyLZeriD1V/esuG4MuU0Pjs5y6iknohY=
github.com/euank/go-kmsg-parser v2.0.0+incompatible/go.mod h1:MhmAMZ8V4CYH4ybgdRwPr2TU5ThnS43puaKEMpja1uw=
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
Expand All @@ -660,8 +662,8 @@ github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwo
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fatih/structs v0.0.0-20180123065059-ebf56d35bba7/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/felixge/fgprof v0.9.3 h1:VvyZxILNuCiUCSXtPtYmmtGvb65nqXh2QFWc0Wpf2/g=
Expand Down Expand Up @@ -1497,6 +1499,8 @@ github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c h1:VtwQ41oftZwlMn
github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c/go.mod h1:JKx41uQRwqlTZabZc+kILPrO/3jlKnQ2Z8b7YiVw5cE=
github.com/lyft/protoc-gen-validate v0.0.0-20180911180927-64fcb82c878e/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand Down
117 changes: 117 additions & 0 deletions internal/cmd/build/cmds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
//go:build mage

package main

import (
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)

// AlloyBuildAll builds the all the dist targets.
func AlloyBuildAll() {
mg.SerialDeps(
AlloyDarwinArm64,
AlloyDarwinAmd64,
AlloyLinuxArm64,
AlloyLinuxAmd64,
AlloyLinuxs390x,
AlloyLinuxPpc64le,
AlloyWindowsAmd64,
AlloyFreebsdAmd64,
)
}

// Alloy builds the current OS and ARCH system to `build/alloy`.
func Alloy() error {
return buildAlloy("", "", "", "build/alloy")
}

// AlloyGoMod runs `go mod vendor` in the current directory.
func AlloyGoMod() error {
return runGoMod("", "")
}

// AlloyImage builds the linux amd64 docker image for alloy.
func AlloyImage() error {
args := map[string]string{
"DOCKER_BUILDKIT": "1",
}
version, err := sh.Output("bash", "./tools/image-tag")
if err != nil {
return err
}
err = ExecNoEnv("build image", "go", "mod", "vendor")
if err != nil {
return err
}
return Exec("build image", args,
"docker",
"build",
"--platform", "linux/amd64",
"--build-arg", "RELEASE_BUILD=0",
"--build-arg", "VERSION="+version,
"--build-arg", "BUILDPLATFORM=linux/amd64",
"--build-arg", "TARGETOS=linux",
"--build-arg", "TARGETARCH=amd64",
"-t", "grafana/alloy:latest",
"-f", "Dockerfile",
".",
)
}

// AlloyImageBoringCrypto builds the linux amd64 docker image for alloy with boring crypto.
func AlloyImageBoringCrypto() error {
args := map[string]string{
"DOCKER_BUILDKIT": "1",
}
version, err := sh.Output("bash", "./tools/image-tag")
if err != nil {
return err
}
err = ExecNoEnv("build image", "go", "mod", "vendor")
if err != nil {
return err
}
return Exec("build image", args,
"docker",
"build",
"--platform", "linux/amd64",
"--build-arg", "RELEASE_BUILD=0",
"--build-arg", "VERSION="+version,
"--build-arg", "BUILDPLATFORM=linux/amd64",
"--build-arg", "TARGETOS=linux",
"--build-arg", "TARGETARCH=amd64",
"--build-arg", "GOEXPERIMENT=boringcrypto",
"-t", "grafana/alloy:boringcrypto",
"-f", "Dockerfile",
".",
)
}

// AlloyImageWindows builds the windows amd64 docker image for alloy.
func AlloyImageWindows() error {
args := map[string]string{
"DOCKER_BUILDKIT": "1",
}
version, err := sh.Output("bash", "./tools/image-tag")
if err != nil {
return err
}
err = ExecNoEnv("build image", "go", "mod", "vendor")
if err != nil {
return err
}
return Exec("build image", args,
"docker",
"build",
"--platform", "windows/amd64",
"--build-arg", "RELEASE_BUILD=0",
"--build-arg", "VERSION="+version,
"--build-arg", "BUILDPLATFORM=windows/amd64",
"--build-arg", "TARGETOS=windows",
"--build-arg", "TARGETARCH=amd64",
"-t", "grafana/alloy:nanoserver-1809",
"-f", "Dockerfile.windows",
".",
)
}
6 changes: 6 additions & 0 deletions internal/cmd/build/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//go:build mage

package main

const buildVersion = "v0.1.0"
const buildImage = "grafana/alloy-build-image:" + buildVersion
85 changes: 85 additions & 0 deletions internal/cmd/build/dist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//go:build mage

package main

func AlloyDarwinArm64() error {
return buildAlloy(
"darwin",
"arm64",
"netgo builtinassets",
"",
)
}

func AlloyDarwinAmd64() error {
return buildAlloy(
"darwin",
"amd64",
"netgo builtinassets",
"",
)
}

func AlloyLinuxs390x() error {
return buildAlloy(
"linux",
"s390x",
"netgo builtinassets promtail_journal_enabled",
"",
)
}

func AlloyLinuxPpc64le() error {
return buildAlloy(
"linux",
"ppc64le",
"netgo builtinassets promtail_journal_enabled",
"",
)
}

func AlloyLinuxArm64() error {
return buildAlloy(
"linux",
"ppc64le",
"netgo builtinassets promtail_journal_enabled",
"",
)
}

func AlloyLinuxAmd64() error {
return buildAlloy(
"linux",
"amd64",
"netgo builtinassets promtail_journal_enabled",
"",
)
}

func AlloyLinuxAmd64BoringCrypto() error {
return buildAlloyFull(
"linux",
"amd64",
"netgo builtinassets promtail_journal_enabled",
"",
"boringcrypto",
)
}

func AlloyWindowsAmd64() error {
return buildAlloy(
"windows",
"amd64",
"builtinassets",
"",
)
}

func AlloyFreebsdAmd64() error {
return buildAlloy(
"freebsd",
"amd64",
"netgo builtinassets",
"",
)
}
Loading
Loading