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

misc: finalize asset names for Linux #107

Merged
merged 1 commit into from
Apr 3, 2024
Merged
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
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -54,6 +54,10 @@ RUN useradd -m -u $UID -g $UID $USERNAME
RUN chown -R $USERNAME:$USERNAME /etc/alloy
RUN chown -R $USERNAME:$USERNAME /bin/alloy

RUN mkdir -p /var/lib/alloy/data
RUN chown -R $USERNAME:$USERNAME /var/lib/alloy
RUN chmod -R 770 /var/lib/alloy

ENTRYPOINT ["/bin/alloy"]
ENV ALLOY_DEPLOY_MODE=docker
CMD ["run", "/etc/alloy/config.alloy", "--storage.path=/etc/alloy/data"]
CMD ["run", "/etc/alloy/config.alloy", "--storage.path=/var/lib/alloy/data"]
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -140,8 +140,12 @@ test:
$(GO_ENV) find . -name go.mod -not -path "./go.mod" -execdir go test -race ./... \;

test-packages:
ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
docker pull $(BUILD_IMAGE)
go test -tags=packaging ./internal/tools/packaging_test
endif

.PHONY: integration-test
integration-test:
19 changes: 13 additions & 6 deletions internal/tools/packaging_test/alloy_linux_packages_test.go
Original file line number Diff line number Diff line change
@@ -81,9 +81,13 @@ func (env *AlloyEnvironment) TestInstall(t *testing.T) {

res = env.ExecScript(`[ -f /usr/bin/alloy ]`)
require.Equal(t, 0, res.ExitCode, "expected Alloy to be installed")
res = env.ExecScript(`[ -f /etc/alloy.alloy ]`)
res = env.ExecScript(`[ -f /etc/alloy/config.alloy ]`)
require.Equal(t, 0, res.ExitCode, "expected Alloy configuration file to exist")

res = env.ExecScript(`stat -c '%a:%U:%G' /etc/alloy`)
require.Equal(t, "770:root:alloy\n", res.Stdout, "wrong permissions for config folder")
require.Equal(t, 0, res.ExitCode, "stat'ing config folder failed")

res = env.Uninstall()
require.Equal(t, 0, res.ExitCode, "uninstalling failed")

@@ -94,13 +98,16 @@ func (env *AlloyEnvironment) TestInstall(t *testing.T) {
}

func (env *AlloyEnvironment) TestConfigPersistence(t *testing.T) {
res := env.ExecScript(`echo -n "keepalive" > /etc/alloy.alloy`)
res := env.ExecScript(`mkdir -p /etc/alloy`)
require.Equal(t, 0, res.ExitCode, "failed to create config directory")

res = env.ExecScript(`echo -n "keepalive" > /etc/alloy/config.alloy`)
require.Equal(t, 0, res.ExitCode, "failed to write config file")

res = env.Install()
require.Equal(t, 0, res.ExitCode, "installation failed")

res = env.ExecScript(`cat /etc/alloy.alloy`)
res = env.ExecScript(`cat /etc/alloy/config.alloy`)
require.Equal(t, "keepalive", res.Stdout, "Expected existing file to not be overridden")
}

@@ -110,10 +117,10 @@ func (env *AlloyEnvironment) TestDataFolderPermissions(t *testing.T) {
res := env.Install()
require.Equal(t, 0, res.ExitCode, "installation failed")

res = env.ExecScript(`[ -d /var/lib/alloy ]`)
require.Equal(t, 0, res.ExitCode, "Expected /var/lib/alloy to have been created during install")
res = env.ExecScript(`[ -d /var/lib/alloy/data ]`)
require.Equal(t, 0, res.ExitCode, "Expected /var/lib/alloy/data to have been created during install")

res = env.ExecScript(`stat -c '%a:%U:%G' /var/lib/alloy`)
res = env.ExecScript(`stat -c '%a:%U:%G' /var/lib/alloy/data`)
require.Equal(t, "770:alloy:alloy\n", res.Stdout, "wrong permissions for data folder")
require.Equal(t, 0, res.ExitCode, "stat'ing data folder failed")
}
27 changes: 0 additions & 27 deletions packaging/alloy.alloy

This file was deleted.

27 changes: 27 additions & 0 deletions packaging/config.alloy
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Sample config for Alloy.
//
// For a full configuration reference, see https://grafana.com/docs/alloy
logging {
level = "warn"
}

prometheus.exporter.unix "default" {
include_exporter_metrics = true
disable_collectors = ["mdadm"]
}

prometheus.scrape "default" {
targets = concat(
prometheus.exporter.unix.default.targets,
[{
// Self-collect metrics
job = "alloy",
__address__ = "127.0.0.1:12345",
}],
)

forward_to = [
// TODO: components to forward metrics to (like prometheus.remote_write or
// prometheus.relabel).
]
}
2 changes: 1 addition & 1 deletion packaging/deb/alloy.service
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ Environment=HOSTNAME=%H
Environment=ALLOY_DEPLOY_MODE=deb
EnvironmentFile=/etc/default/alloy
WorkingDirectory=/var/lib/alloy
ExecStart=/usr/bin/alloy run $CUSTOM_ARGS --storage.path=/var/lib/alloy $CONFIG_FILE
ExecStart=/usr/bin/alloy run $CUSTOM_ARGS --storage.path=/var/lib/alloy/data $CONFIG_FILE
ExecReload=/usr/bin/env kill -HUP $MAINPID
TimeoutStopSec=20s
SendSIGKILL=no
10 changes: 8 additions & 2 deletions packaging/deb/control/postinst
Original file line number Diff line number Diff line change
@@ -29,8 +29,14 @@ case "$1" in
chown $ALLOY_USER:$ALLOY_GROUP /var/lib/alloy
chmod 770 /var/lib/alloy

chmod 640 /etc/alloy.alloy
chown root:$ALLOY_GROUP /etc/alloy.alloy
if [ ! -d /var/lib/alloy/data ]; then
mkdir /var/lib/alloy/data
chown $ALLOY_USER:$ALLOY_GROUP /var/lib/alloy/data
chmod 770 /var/lib/alloy/data
fi

chown root:$ALLOY_GROUP /etc/alloy
chmod 770 /etc/alloy

if [ -z ${2+x} ] && [ "$RESTART_ON_UPGRADE" = "true" ]; then
if command -v systemctl 2>/dev/null; then
2 changes: 1 addition & 1 deletion packaging/environment-file
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
# Command line options for Alloy.
#
# The configuration file holding the Alloy config.
CONFIG_FILE="/etc/alloy.alloy"
CONFIG_FILE="/etc/alloy/config.alloy"

# User-defined arguments to pass to the run command.
CUSTOM_ARGS=""
2 changes: 1 addition & 1 deletion packaging/rpm/alloy.service
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ Environment=HOSTNAME=%H
Environment=ALLOY_DEPLOY_MODE=rpm
EnvironmentFile=/etc/sysconfig/alloy
WorkingDirectory=/var/lib/alloy
ExecStart=/usr/bin/alloy run $CUSTOM_ARGS --storage.path=/var/lib/alloy $CONFIG_FILE
ExecStart=/usr/bin/alloy run $CUSTOM_ARGS --storage.path=/var/lib/alloy/data $CONFIG_FILE
ExecReload=/usr/bin/env kill -HUP $MAINPID
TimeoutStopSec=20s
SendSIGKILL=no
10 changes: 8 additions & 2 deletions packaging/rpm/control/postinst
Original file line number Diff line number Diff line change
@@ -32,8 +32,14 @@ if [ "$1" -eq 1 ] ; then
chown $ALLOY_USER:$ALLOY_GROUP /var/lib/alloy
chmod 770 /var/lib/alloy

chmod 640 /etc/alloy.alloy
chown root:$ALLOY_GROUP /etc/alloy.alloy
if [ ! -d /var/lib/alloy/data ]; then
mkdir /var/lib/alloy/data
chown $ALLOY_USER:$ALLOY_GROUP /var/lib/alloy/data
chmod 770 /var/lib/alloy/data
fi

chown root:$ALLOY_GROUP /etc/alloy
chmod 770 /etc/alloy

elif [ "$1" -ge 2 ] ; then
add_to_logging_groups
4 changes: 2 additions & 2 deletions tools/make/packaging.mk
Original file line number Diff line number Diff line change
@@ -124,12 +124,12 @@ define generate_alloy_fpm =
-t $(1) \
--after-install packaging/$(1)/control/postinst \
--before-remove packaging/$(1)/control/prerm \
--config-files /etc/alloy.alloy \
--config-files /etc/alloy/config.alloy \
--config-files $(ALLOY_ENVIRONMENT_FILE_$(1)) \
--rpm-rpmbuild-define "_build_id_links none" \
--package $(4) \
dist/alloy-linux-$(3)=/usr/bin/alloy \
packaging/alloy.alloy=/etc/alloy.alloy \
packaging/config.alloy=/etc/alloy/config.alloy \
packaging/environment-file=$(ALLOY_ENVIRONMENT_FILE_$(1)) \
packaging/$(1)/alloy.service=/usr/lib/systemd/system/alloy.service
endef