Skip to content

Commit

Permalink
misc: move cmd/alloy to root of repository (#77)
Browse files Browse the repository at this point in the history
Following the Go documentation on how to
[Organize a Go module][modules-layout], a single-command repository
should have its main package at the root of the repository rather than
in a cmd/ folder.

As all internal tooling is now in internal/cmd, and there's only one
non-internal binary, that binary has been moved to the root of the
repository to align with best practices.

[modules-layout]: https://go.dev/doc/modules/layout
  • Loading branch information
rfratto authored Mar 25, 2024
1 parent 0250859 commit 5e92690
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions .drone/drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ steps:
path: /var/run/docker.sock
trigger:
paths:
- cmd/alloy/Dockerfile
- Dockerfile
- tools/ci/docker-containers
ref:
- refs/heads/main
Expand All @@ -109,7 +109,7 @@ steps:
path: //./pipe/docker_engine/
trigger:
paths:
- cmd/alloy/Dockerfile.windows
- Dockerfile.windows
- tools/ci/docker-containers-windows
ref:
- refs/heads/main
Expand Down Expand Up @@ -401,6 +401,6 @@ kind: secret
name: updater_private_key
---
kind: signature
hmac: 1a44f5bcd0f52805d4b7d1f11433f993832627118bbae3956fe5aa49b68d5a31
hmac: 1c75c3c155d1dba9707728f7b6a5fed9399518900e86c7fba55e52a253bdb26b

...
4 changes: 2 additions & 2 deletions .drone/pipelines/check_containers.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ local build_image = import '../util/build_image.jsonnet';
local pipelines = import '../util/pipelines.jsonnet';

local linux_containers = [
{ name: 'grafana/alloy', make: 'make alloy-image', path: 'cmd/alloy/Dockerfile' },
{ name: 'grafana/alloy', make: 'make alloy-image', path: 'Dockerfile' },
];

local windows_containers = [
{ name: 'grafana/alloy', argument: 'alloy', path: 'cmd/alloy/Dockerfile.windows' },
{ name: 'grafana/alloy', argument: 'alloy', path: 'Dockerfile.windows' },
];

(
Expand Down
2 changes: 1 addition & 1 deletion cmd/alloy/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RUN <<EOF
EOF

COPY --from=build /src/alloy/build/alloy /bin/alloy
COPY cmd/alloy/example-config.river /etc/alloy/config.river
COPY example-config.river /etc/alloy/config.river

# Create alloy user in container, but do not set it as default
RUN groupadd --gid $UID $USERNAME
Expand Down
2 changes: 1 addition & 1 deletion cmd/alloy/Dockerfile.windows → Dockerfile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RUN ""C:\Program Files\git\bin\bash.exe" -c "go clean -cache -modcache""
FROM mcr.microsoft.com/windows/nanoserver:1809

COPY --from=builder /src/alloy/build/alloy /bin/alloy
COPY --from=builder /src/alloy/cmd/alloy/example-config.river /etc/alloy/config.river
COPY --from=builder /src/alloy/example-config.river /etc/alloy/config.river

ENTRYPOINT ["/bin/alloy"]
CMD ["run", "/etc/alloy/config.river", "--storage.path=/etc/alloy/data"]
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
## Targets for building binaries:
##
## binaries Compiles all binaries.
## alloy Compiles cmd/alloy to $(ALLOY_BINARY)
## alloy Compiles Alloy to $(ALLOY_BINARY)
## alloy-service Compiles internal/cmd/alloy-service to $(SERVICE_BINARY)
##
## Targets for building Docker images:
Expand Down Expand Up @@ -158,7 +158,7 @@ alloy:
ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
$(GO_ENV) go build $(GO_FLAGS) -o $(ALLOY_BINARY) ./cmd/alloy
$(GO_ENV) go build $(GO_FLAGS) -o $(ALLOY_BINARY) .
endif

# alloy-service is not included in binaries since it's Windows-only.
Expand Down Expand Up @@ -190,7 +190,7 @@ endif
images: alloy-image

alloy-image:
DOCKER_BUILDKIT=1 docker build $(DOCKER_FLAGS) -t $(ALLOY_IMAGE) -f cmd/alloy/Dockerfile .
DOCKER_BUILDKIT=1 docker build $(DOCKER_FLAGS) -t $(ALLOY_IMAGE) -f Dockerfile .

#
# Targets for generating assets
Expand Down
6 changes: 3 additions & 3 deletions docs/developer/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ compiling and testing your changes do:

```bash
# For building:
go build ./cmd/alloy/
go build .
./alloy -config.file=<config-file>

# For testing:
Expand Down Expand Up @@ -62,7 +62,7 @@ To build Grafana Agent from source code, please install the following tools:

You can directly use the go tool to download and install the agent binary into your GOPATH:

$ GO111MODULE=on go install github.com/grafana/alloy/cmd/alloy
$ GO111MODULE=on go install github.com/grafana/alloy
$ alloy run your_config.river

An example of the above configuration file can be found [here][example-config].
Expand Down Expand Up @@ -205,5 +205,5 @@ a hard fork (i.e., creating a new Go module with the same source).
[CLA]: https://cla-assistant.io/grafana/alloy
[good-first-issue]: https://github.com/grafana/alloy/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22
[community-slack]: https://slack.grafana.com/
[example-config]: ../../cmd/alloy/example-config.river
[example-config]: ../../example-config.river
[go-modules]: https://golang.org/cmd/go/#hdr-Modules__module_versions__and_more
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tools/ci/docker-containers
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ case "$TARGET_CONTAINER" in
--build-arg VERSION="$VERSION" \
-t "$ALLOY_IMAGE:$TAG_VERSION" \
-t "$ALLOY_IMAGE:$BRANCH_TAG" \
-f cmd/alloy/Dockerfile \
-f Dockerfile \
.
;;

Expand Down
2 changes: 1 addition & 1 deletion tools/ci/docker-containers-windows
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ case "$TARGET_CONTAINER" in
-t "$ALLOY_IMAGE:$BRANCH_TAG" \
--build-arg VERSION="$VERSION" \
--build-arg RELEASE_BUILD=1 \
-f ./cmd/alloy/Dockerfile.windows \
-f ./Dockerfile.windows \
.
;;

Expand Down

0 comments on commit 5e92690

Please sign in to comment.