Skip to content

Commit

Permalink
build folder
Browse files Browse the repository at this point in the history
  • Loading branch information
balanza committed Jan 10, 2025
1 parent 75a5616 commit 3f50cab
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 13 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ jobs:
- name: build
run: make -j4 cross-compiled
- name: compress
run: |
set -x
find ./build -maxdepth 1 -mindepth 1 -type d -exec sh -c 'tar -zcf build/trento-agent-$(basename {}).tgz -C {} trento-agent -C $(pwd)/packaging/systemd trento-agent.service' \;
run: make bundle
- uses: actions/upload-artifact@v4
with:
name: trento-binaries
Expand Down
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ VERSION ?= $(shell ./hack/get_version_from_git.sh)
INSTALLATIONSOURCE ?= "Community"
LDFLAGS = -X github.com/trento-project/agent/version.Version="$(VERSION)"
LDFLAGS := $(LDFLAGS) -X github.com/trento-project/agent/version.InstallationSource="$(INSTALLATIONSOURCE)"
CURRENT_ARCH := $(shell go env GOARCH)
ARCHS ?= amd64 arm64 ppc64le s390x
DEBUG ?= 0
BUILD_DIR ?= ./build
BUILD_DIR := ./build

ifeq ($(DEBUG), 0)
LDFLAGS += -s -w
Expand All @@ -19,18 +20,23 @@ default: clean mod-tidy fmt vet-check test build
.PHONY: build
build: agent
agent:
$(GO_BUILD) -o $(BUILD_DIR)/trento-agent
$(GO_BUILD) -o $(BUILD_DIR)/$(CURRENT_ARCH)/trento-agent

.PHONY: build-plugin-examples
build-plugin-examples:
$(GO_BUILD) -o $(BUILD_DIR)/plugin_examples/dummy ./plugin_examples/dummy.go
$(GO_BUILD) -o $(BUILD_DIR)/$(CURRENT_ARCH)/plugin_examples/dummy ./plugin_examples/dummy.go

.PHONY: cross-compiled $(ARCHS)
cross-compiled: $(ARCHS)
$(ARCHS):
@mkdir -p build/$@
GOOS=linux GOARCH=$@ $(GO_BUILD) -o build/$@/trento-agent
GOOS=linux GOARCH=$@ $(GO_BUILD) -o $(BUILD_DIR)/$@/trento-agent

.PHONY: bundle
bundle:
set -x
find $(BUILD_DIR) -maxdepth 1 -mindepth 1 -type d -exec sh -c 'tar -zcf build/trento-agent-$$(basename {}).tgz -C {} trento-agent -C $$(pwd)/packaging/systemd trento-agent.service' \;

.PHONY: clean
clean: clean-binary

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,13 @@ We use GNU Make as a task manager; here are some common targets:
```shell
make # clean, test and build everything

make build # build for the current architecture
make cross-compile # build for a list of supported architectures
make bundle # prepare all the bundles for each built artifact
make clean # removes any build artifact
make test # executes all the tests
make test-short # executes all tests that don't require dependencies
make test-build # executes tests on built artifacts
make fmt # fixes code formatting
make web-assets # invokes the frontend build scripts
make generate # refresh automatically generated code (e.g. static Go mocks)
Expand Down
3 changes: 2 additions & 1 deletion test/cli/agent.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ setup() {
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )/../.." >/dev/null 2>&1 && pwd )"

# Add the build folder to the PATH
PATH="$DIR/build:$PATH"
BUILD_DIR="$DIR/build/$(go env GOARCH)"
PATH="$BUILD_DIR:$PATH"
}

@test "it should show help" {
Expand Down
23 changes: 23 additions & 0 deletions test/cli/packaging.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
setup() {
# Set the test root as the project root
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )/../.." >/dev/null 2>&1 && pwd )"

# Add the build folder to the PATH
BUILD_DIR="$DIR/build/$(go env GOARCH)"
PATH="$BUILD_DIR:$PATH"
}

@test "it should package the artifact for the release including only the necessary files" {
run make bundle

[ "$status" -eq 0 ]
[ -f "$DIR/build/trento-agent-$(go env GOARCH).tgz" ]

TMP_DIR=$(mktemp -d)
run tar -xzf "$DIR/build/trento-agent-$(go env GOARCH).tgz" -C $TMP_DIR

[ "$status" -eq 0 ]
[ $(ls -1 $TMP_DIR | wc -l) -eq 2 ]
[ -f "$TMP_DIR/trento-agent" ]
[ -f "$TMP_DIR/trento-agent.service" ]
}
11 changes: 6 additions & 5 deletions test/cli/plugins.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ setup() {
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )/../.." >/dev/null 2>&1 && pwd )"

# Add the build folder to the PATH
PATH="$DIR/build:$PATH"
BUILD_DIR="$DIR/build/$(go env GOARCH)"
PATH="$BUILD_DIR:$PATH"
}


@test "it should include the dummy plugin into list" {
run trento-agent facts list --plugins-folder ./build/plugin_examples
run trento-agent facts list --plugins-folder $BUILD_DIR/plugin_examples

[ "$status" -eq 0 ]
echo "$output" | grep -q "dummy"
}

@test "it should should execute the dummy plugin" {
run trento-agent facts gather \
--plugins-folder ./build/plugin_examples \
--plugins-folder $BUILD_DIR/plugin_examples \
--gatherer dummy --argument 1

[ "$status" -eq 0 ]
Expand All @@ -25,9 +26,9 @@ setup() {

@test "it should execute the dummy plugin with a different argument" {
run trento-agent facts gather \
--plugins-folder ./build/plugin_examples \
--plugins-folder $BUILD_DIR/plugin_examples \
--gatherer dummy --argument 2

[ "$status" -eq 0 ]
echo $output | grep -q "Name: 2"
}
}

0 comments on commit 3f50cab

Please sign in to comment.