Skip to content

Conversation

@endorama
Copy link
Contributor

@endorama endorama commented Jan 24, 2022

Follow-up for a conversation @jsoriano, @mtojek and me had about how make build works at the moment.

make build performs go install under the hood. This behaviour is unexpected as go install moves the built binary to GOBIN folder, which in most system is part of system PATH. While this is the purpose of go install in the context of elastic-package makes a bit troublesome to build binary for development and local testing.

The current workaround is to manually run go build, but we loose version information and is undocumented.

To improve the situation this PR moves the current build task logic to a separate install one and changes the build task to perform go build, creating the executable in the project folder.

go install builds the executable and move it to GOBIN. This is useful
for installing the tool but can become troublesome during development.

Having go install performed in the build task is confusing, as running
make build would create a "system wide" binary (as most devs have GOBIN
in their PATH).

To overcome this go install is moved to a dedicated make task: install.
@endorama endorama requested a review from mtojek January 24, 2022 16:19
@elasticmachine
Copy link
Collaborator

elasticmachine commented Jan 24, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Reason: null

  • Start Time: 2022-01-27T15:57:44.782+0000

  • Duration: 34 min 25 sec

  • Commit: 5af928c

Test stats 🧪

Test Results
Failed 0
Passed 469
Skipped 0
Total 469

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@jsoriano
Copy link
Member

Thanks for opening this PR! Could you please also check what documentation needs to be updated?

Makefile Outdated
build:
go install -ldflags \
go build -ldflags \
"-X $(VERSION_IMPORT_PATH).CommitHash=`git describe --always --long --dirty` -X $(VERSION_IMPORT_PATH).BuildTime=`date +%s` -X $(VERSION_IMPORT_PATH).Tag=`(git describe --exact-match --tags 2>/dev/null || echo '') | tr -d '\n'`" \
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this string be factored out since it appears twice?

Copy link
Contributor

Choose a reason for hiding this comment

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

In general, there is a rule of three, but if it isn't a big deal, we can extract this line to the top.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I extracted and split the line to give it more clarity in 8182d2f

Copy link
Contributor

Choose a reason for hiding this comment

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

What you have now is very nice. Thanks.

Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

You have to adjust also all scripts (.sh) as they refer to the globally installed elastic-package:

[2022-01-24T17:32:17.361Z] + make PACKAGE_UNDER_TEST=aws test-check-packages-parallel
[2022-01-24T17:32:17.361Z] PACKAGE_TEST_TYPE=parallel ./scripts/test-check-packages.sh
[2022-01-24T17:32:17.361Z] + trap cleanup EXIT
[2022-01-24T17:32:17.361Z] + OLDPWD=/var/lib/jenkins/workspace/PR-663-2-a78640ec-85fd-454a-a89c-932d6fe3894a/src/github.com/elastic/elastic-package
[2022-01-24T17:32:17.361Z] + for d in test/packages/${PACKAGE_TEST_TYPE:-other}/${PACKAGE_UNDER_TEST:-*}/
[2022-01-24T17:32:17.361Z] + cd test/packages/parallel/aws/
[2022-01-24T17:32:17.361Z] + elastic-package check -v
[2022-01-24T17:32:17.361Z] ./scripts/test-check-packages.sh: line 41: elastic-package: command not found
[2022-01-24T17:32:17.361Z] + cleanup
[2022-01-24T17:32:17.361Z] + r=127
[2022-01-24T17:32:17.361Z] + elastic-package stack dump -v --output build/elastic-stack-dump/check-aws
[2022-01-24T17:32:17.361Z] ./scripts/test-check-packages.sh: line 9: elastic-package: command not found
[2022-01-24T17:32:17.361Z] make: *** [Makefile:79: test-check-packages-parallel] Error 127

As a simple solution you can prepend an extra PATH=$PATH:\pwd`/build(considering that the binary is stored inbuild`).

@endorama
Copy link
Contributor Author

@jsoriano I found a reference to make build in README, so I updated template and README adding make install in 96a3691

@endorama
Copy link
Contributor Author

@mtojek I preferred to replace make build with make install as it keeps the same logic tests were using before. But I missed one that I changed in 60ed6bd

Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

small nit-picks, but I think we're aligned in general :)

Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

LGTM

Feel free to merge if CI is happy.

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

👍

@mtojek mtojek merged commit 8a58236 into elastic:main Jan 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants