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

support compile binaries with kubeedge/build-tools images #3756

Merged
merged 1 commit into from
Apr 6, 2022

Conversation

gy95
Copy link
Member

@gy95 gy95 commented Mar 31, 2022

What type of PR is this?

What this PR does / why we need it:
support compile source code with images,but not depend on local machine golang.
Which issue(s) this PR fixes:

Fixes #3687

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


@kubeedge-bot kubeedge-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 31, 2022
Makefile Outdated
@@ -51,6 +51,9 @@ all:
KUBEEDGE_OUTPUT_SUBPATH=$(OUT_DIR) hack/make-rules/build.sh $(WHAT)
endif

.PHONY: compile
Copy link
Member

Choose a reason for hiding this comment

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

It should be part of make with export BUILD_WITH_CONTAINER=true
make all or make is also do the compilation work

if [ ${KUBEEDGE_COMPILE_WITH_IMAGE} = true ]; then
set -x
docker run --rm -e CGO_ENABLED=0 -v ${KUBEEDGE_ROOT}:${MOUNTPATH} -w ${MOUNTPATH} ${GOLANG_IMAGE} \
/usr/local/go/bin/go build -o ${MOUNTPATH}/_output/local/bin/${name} -gcflags="${gogcflags:-}" -ldflags "${goldflags:-}" $bin
Copy link
Member

Choose a reason for hiding this comment

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

it's better to use this image: kubeedge/build-tools, so all the compilation work can in one env.


source "${KUBEEDGE_ROOT}/hack/lib/init.sh"

kubeedge::golang::build_binaries "$@"
Copy link
Member

Choose a reason for hiding this comment

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

This script seems no needed?

@gy95 gy95 force-pushed the binary branch 3 times, most recently from be785f0 to 52e1d86 Compare April 1, 2022 01:20
Makefile Outdated
Comment on lines 50 to 52
else ifeq ($(KUBEEDGE_COMPILE_WITH_IMAGE),true)
all:
hack/make-rules/build.sh $(WHAT)
Copy link
Member Author

Choose a reason for hiding this comment

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

can also delete this block directly, or emphasize the env KUBEEDGE_COMPILE_WITH_IMAGE to make it separated from using local go. ?

Copy link
Member

Choose a reason for hiding this comment

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

BUILD_WITH_CONTAINER will be a better name, in container, not image.

Copy link
Member

Choose a reason for hiding this comment

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

We can set BUILD_WITH_CONTAINER as a env value like istio? so no need to add it to cmd everytime.

Copy link
Member

Choose a reason for hiding this comment

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

Looks like adding another script for container is fine.

Copy link
Member Author

@gy95 gy95 Apr 2, 2022

Choose a reason for hiding this comment

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

yes, we can use BUILD_WITH_CONTAINER as an env like below.

root@ecs-8f95:~/go/src/github.com/kubeedge/kubeedge# export BUILD_WITH_CONTAINER=true
root@ecs-8f95:~/go/src/github.com/kubeedge/kubeedge# make all WHAT=keadm
hack/make-rules/build_with_container.sh keadm
building github.com/kubeedge/kubeedge/keadm/cmd/keadm
+ docker run --rm -v /root/go/src/github.com/kubeedge/kubeedge:/kubeedge -w /kubeedge kubeedge/build-tools /usr/local/go/bin/go build -o /kubeedge/_output/local/bin/keadm -gcflags= -ldflags '-s -w -buildid= -X github.com/kubeedge/kubeedge/pkg/version.buildDate=2022-04-02T00:58:49Z -X github.com/kubeedge/kubeedge/pkg/version.gitCommit=e0d10fd6800e0fb02a9c307d98c23eac3d589121 -X github.com/kubeedge/kubeedge/pkg/version.gitTreeState=dirty -X github.com/kubeedge/kubeedge/pkg/version.gitVersion=v1.5.0-beta.0.1359+e0d10fd6800e0f-dirty -X github.com/kubeedge/kubeedge/pkg/version.gitMajor=1 -X github.com/kubeedge/kubeedge/pkg/version.gitMinor=5+' github.com/kubeedge/kubeedge/keadm/cmd/keadm
+ set +x


root@ecs-8f95:~/go/src/github.com/kubeedge/kubeedge# unset BUILD_WITH_CONTAINER
root@ecs-8f95:~/go/src/github.com/kubeedge/kubeedge# make all WHAT=keadm
KUBEEDGE_OUTPUT_SUBPATH=_output/local hack/make-rules/build.sh keadm
go detail version: go version go1.16.15 linux/amd64
go version: 1.16.15
building github.com/kubeedge/kubeedge/keadm/cmd/keadm
+ go build -o /root/go/src/github.com/kubeedge/kubeedge/_output/local/bin/keadm -gcflags= -ldflags '-s -w -buildid= -X github.com/kubeedge/kubeedge/pkg/version.buildDate=2022-04-02T01:00:08Z -X github.com/kubeedge/kubeedge/pkg/version.gitCommit=e0d10fd6800e0fb02a9c307d98c23eac3d589121 -X github.com/kubeedge/kubeedge/pkg/version.gitTreeState=dirty -X github.com/kubeedge/kubeedge/pkg/version.gitVersion=v1.5.0-beta.0.1359+e0d10fd6800e0f-dirty -X github.com/kubeedge/kubeedge/pkg/version.gitMajor=1 -X github.com/kubeedge/kubeedge/pkg/version.gitMinor=5+' github.com/kubeedge/kubeedge/keadm/cmd/keadm
+ set +x

Copy link
Member Author

Choose a reason for hiding this comment

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

And can also specify the BUILD_WITH_CONTAINER env in make command, just like this:

root@ecs-8f95:~/go/src/github.com/kubeedge/kubeedge# make all WHAT=keadm BUILD_WITH_CONTAINER=true
hack/make-rules/build_with_container.sh keadm
building github.com/kubeedge/kubeedge/keadm/cmd/keadm
+ docker run --rm -v /root/go/src/github.com/kubeedge/kubeedge:/kubeedge -w /kubeedge kubeedge/build-tools /usr/local/go/bin/go build -o /kubeedge/_output/local/bin/keadm -gcflags= -ldflags '-s -w -buildid= -X github.com/kubeedge/kubeedge/pkg/version.buildDate=2022-04-02T01:22:49Z -X github.com/kubeedge/kubeedge/pkg/version.gitCommit=b216deb58ac6de7f1e5bcab9c3ec136286ae3647 -X github.com/kubeedge/kubeedge/pkg/version.gitTreeState=clean -X github.com/kubeedge/kubeedge/pkg/version.gitVersion=v1.5.0-beta.0.1357+b216deb58ac6de -X github.com/kubeedge/kubeedge/pkg/version.gitMajor=1 -X github.com/kubeedge/kubeedge/pkg/version.gitMinor=5+' github.com/kubeedge/kubeedge/keadm/cmd/keadm
+ set +x



root@ecs-8f95:~/go/src/github.com/kubeedge/kubeedge# make all WHAT=keadm 
KUBEEDGE_OUTPUT_SUBPATH=_output/local hack/make-rules/build.sh keadm
go detail version: go version go1.16.15 linux/amd64
go version: 1.16.15
building github.com/kubeedge/kubeedge/keadm/cmd/keadm
+ go build -o /root/go/src/github.com/kubeedge/kubeedge/_output/local/bin/keadm -gcflags= -ldflags '-s -w -buildid= -X github.com/kubeedge/kubeedge/pkg/version.buildDate=2022-04-02T01:23:51Z -X github.com/kubeedge/kubeedge/pkg/version.gitCommit=b216deb58ac6de7f1e5bcab9c3ec136286ae3647 -X github.com/kubeedge/kubeedge/pkg/version.gitTreeState=clean -X github.com/kubeedge/kubeedge/pkg/version.gitVersion=v1.5.0-beta.0.1357+b216deb58ac6de -X github.com/kubeedge/kubeedge/pkg/version.gitMajor=1 -X github.com/kubeedge/kubeedge/pkg/version.gitMinor=5+' github.com/kubeedge/kubeedge/keadm/cmd/keadm
+ set +x

Makefile Outdated
@@ -35,6 +35,7 @@ define ALL_HELP_INFO
# make all
# make all HELP=y
# make all WHAT=cloudcore
# make all WHAT=cloudcore BUILD_WITH_CONTAINER=true
Copy link
Member

Choose a reason for hiding this comment

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

Need some comments for this

Copy link
Member Author

Choose a reason for hiding this comment

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

added.

Comment on lines 238 to 240
KUBEEDGE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
MOUNTPATH="/kubeedge"
KUBEEDGE_BUILD_IMAGE="kubeedge/build-tools"
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to place them to build_with_container.sh?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed, PTAL 😄

go build -o ${KUBEEDGE_OUTPUT_BINPATH}/${name} -gcflags="${gogcflags:-}" -ldflags "${goldflags:-}" $bin
set +x
# if env BUILD_WITH_CONTAINER exist, we build with docker images
set +u
Copy link
Member

Choose a reason for hiding this comment

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

Remove the set +/-u?

Copy link
Member Author

Choose a reason for hiding this comment

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

cannot, if want to check the variable exist or not using if [ ! -z ${BUILD_WITH_CONTAINER} ], we must set +u, or will report the error BUILD_WITH_CONTAINER: unbound variable
and there're lots of set -o nounset in the scripts, this will prevent we check the env exist or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

refactored, and more common, PTAL


KUBEEDGE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
MOUNTPATH="${MOUNTPATH:-/kubeedge}"
KUBEEDGE_BUILD_IMAGE="kubeedge/build-tools"
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
KUBEEDGE_BUILD_IMAGE="kubeedge/build-tools"
MOUNTPATH=${MOUNTPATH:-"/kubeedge"}
KUBEEDGE_BUILD_IMAGE=${KUBEEDGE_BUILD_IMAGE:-"kubeedge/build-tools"}

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed.

Makefile Outdated
Comment on lines 41 to 43
# If we want to build KubeEdge in image container mode, there're two ways to implement the function.
# 1) make all WHAT=cloudcore BUILD_WITH_CONTAINER=true
# 2) export BUILD_WITH_CONTAINER=true && make all WHAT=cloudcore
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
# If we want to build KubeEdge in image container mode, there're two ways to implement the function.
# 1) make all WHAT=cloudcore BUILD_WITH_CONTAINER=true
# 2) export BUILD_WITH_CONTAINER=true && make all WHAT=cloudcore
# Set the environment variable or arg BUILD_WITH_CONTAINER to build inside container,
# only docker and make are required in this mode.
# 1) make all WHAT=cloudcore BUILD_WITH_CONTAINER=true
# 2) export BUILD_WITH_CONTAINER=true && make all WHAT=cloudcore

Let's move them below L47

@@ -22,6 +22,8 @@ COMPONENTS=cloud \
.EXPORT_ALL_VARIABLES:
OUT_DIR ?= _output/local
Copy link
Member

Choose a reason for hiding this comment

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

Set a default value for BUILD_WITH_CONTAINER here? Let's build in container by default.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, but seems that we need more fix to adjust it, will open another PR to set build in container default
https://github.com/kubeedge/kubeedge/runs/5844143228?check_suite_focus=true

Copy link
Member

Choose a reason for hiding this comment

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

Ok, if there're some actions build in container originally, we can disable BUILD_WITH_CONTAINER.

Signed-off-by: gy95 <guoyao17@huawei.com>
Copy link
Member

@fisherxu fisherxu left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@kubeedge-bot kubeedge-bot added the lgtm Indicates that a PR is ready to be merged. label Apr 6, 2022
@kubeedge-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fisherxu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubeedge-bot kubeedge-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 6, 2022
@kubeedge-bot kubeedge-bot merged commit 595c970 into kubeedge:master Apr 6, 2022
@gy95 gy95 deleted the binary branch April 6, 2022 03:21
@gy95 gy95 changed the title support compile binaries with golang images support compile binaries with kubeedge/build-tools images Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the option to build binaries in container
3 participants