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

Upgrade libgit2 and fix static builds #311

Merged
merged 1 commit into from
Feb 10, 2022

Conversation

aryan9600
Copy link
Member

@aryan9600 aryan9600 commented Feb 8, 2022

  • Bump to golang-with-libgit2:1.1.1.6 to speed up build time when cross compiling. Previous version was compiling in emulation mode instead, which added +10x overhead.
  • Ensure that make test is executed against the exact same libraries that will be shipped on the built image.
  • Simplify Makefile to reduce its complexity.
  • Libgit2 behaviour:
    linux-amd64 download static libraries from the official container image.
    linux-arm64 on top of the above, requires static musl tool chain (automatically downloaded).
    darwin-amd64 and darwin-arm64 download universal static libraries for darwin from https://github.com/fluxcd/golang-with-libgit2 releases.

Fixes: #309

Co-authored-by: Paulo Gomes [email protected]
Signed-off-by: Sanskar Jaiswal [email protected]

Copy link
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

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

Nice one, @aryan9600. Just a few nits from me, apart from that really good stuff. 👍

Comment on lines 49 to 50
GOBIN="${GITHUB_WORKSPACE}/build/gobin" go install sigs.k8s.io/controller-tools/cmd/[email protected]
GOBIN="${GITHUB_WORKSPACE}/build/gobin" go install github.com/ahmetb/[email protected]
Copy link
Member

Choose a reason for hiding this comment

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

When building against the arm64 runners for SC, only the setup-envtest did not work via Makefile. Did you also have issues with controller-gen and gen-crd-api-reference-docs?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Ca we set GOBIN for Make and get rid of the duplicate install? The issue with this is that the controller-gen version will diverge from the one in the Makefile.

Copy link
Member Author

Choose a reason for hiding this comment

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

We do set GOBIN in the Makefile which works for linux-amd64 and darwin-amd64 but it mysteriously fails on linux-arm64.

Makefile Outdated
@@ -148,7 +192,7 @@ docker-build: ## Build the Docker image
docker buildx build \
--build-arg LIBGIT2_IMG=$(LIBGIT2_IMG) \
--build-arg LIBGIT2_TAG=$(LIBGIT2_TAG) \
--platform=$(BUILD_PLATFORMS) \
--platform=linux/amd64 \
Copy link
Member

Choose a reason for hiding this comment

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

We probably need to revert this:

Suggested change
--platform=linux/amd64 \
--platform=$(BUILD_PLATFORMS) \

if [[ $OSTYPE == 'darwin'* ]]; then
# For MacOS development environments, download the amd64 static libraries released from from golang-with-libgit2.

#TODO: update URL with official URL + TAG:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#TODO: update URL with official URL + TAG:

@aryan9600 aryan9600 force-pushed the aryan9600/static-build branch 5 times, most recently from 5e0562e to cdcccff Compare February 10, 2022 09:44
Copy link
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

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

It is looking really good, thank you @aryan9600. The only change we must do before merging is to reset the img/tag on the Dockerfile, otherwise this will cause the release workflow to fail.

Dockerfile Outdated
Comment on lines 5 to 6
ARG LIBGIT2_IMG=ghcr.io/fluxcd/golang-with-libgit2
ARG LIBGIT2_TAG=libgit2-1.1.1-4
Copy link
Member

Choose a reason for hiding this comment

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

This is required for release purposes xref: fluxcd/source-controller#574

Makefile Outdated
ENVTEST_KUBERNETES_VERSION?=latest
install-envtest: setup-envtest
mkdir -p ${ENVTEST_ASSETS_DIR}
$(ENVTEST) use $(ENVTEST_KUBERNETES_VERSION) --arch=$(ENVTEST_ARCH) --bin-dir=$(ENVTEST_ASSETS_DIR)
chmod -R u+w $(BUILD_DIR)
Copy link
Member

Choose a reason for hiding this comment

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

This may conflict with fuzzing, which creates files that are owned by root. I would rather just reset chmod of things that are set to 0555 by setenvtest:

Suggested change
chmod -R u+w $(BUILD_DIR)
chmod -R u+w $(BUILD_DIR)/testbin

* Bump to golang-with-libgit2:1.1.1.6 to speed up build time when cross compiling. Previous version was compiling in emulation mode instead, which added +10x overhead.
* Ensure that make test is executed against the exact same libraries that will be shipped on the built image.
* Simplify Makefile to reduce its complexity.
* Libgit2 behaviour:
    linux-amd64 download static libraries from the official container image.
    linux-arm64 on top of the above, requires static musl tool chain (automatically downloaded).
    darwin-amd64 and darwin-arm64 download universal static libraries for darwin from https://github.com/fluxcd/golang-with-libgit2 releases.

Co-authored-by: Paulo Gomes <[email protected]>
Signed-off-by: Sanskar Jaiswal <[email protected]>
Copy link
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

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

Great stuff @aryan9600, thank you! LGTM

@hiddeco hiddeco added the area/ci CI related issues and pull requests label Feb 10, 2022
@hiddeco hiddeco merged commit cd64a44 into fluxcd:main Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ci CI related issues and pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build fails on Apple Silicon
4 participants