-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
Makefile
Outdated
@@ -51,6 +51,9 @@ all: | |||
KUBEEDGE_OUTPUT_SUBPATH=$(OUT_DIR) hack/make-rules/build.sh $(WHAT) | |||
endif | |||
|
|||
.PHONY: compile |
There was a problem hiding this comment.
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
hack/lib/golang.sh
Outdated
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 |
There was a problem hiding this comment.
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.
hack/make-rules/compile.sh
Outdated
|
||
source "${KUBEEDGE_ROOT}/hack/lib/init.sh" | ||
|
||
kubeedge::golang::build_binaries "$@" |
There was a problem hiding this comment.
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?
be785f0
to
52e1d86
Compare
Makefile
Outdated
else ifeq ($(KUBEEDGE_COMPILE_WITH_IMAGE),true) | ||
all: | ||
hack/make-rules/build.sh $(WHAT) |
There was a problem hiding this comment.
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. ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added.
hack/lib/golang.sh
Outdated
KUBEEDGE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" | ||
MOUNTPATH="/kubeedge" | ||
KUBEEDGE_BUILD_IMAGE="kubeedge/build-tools" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, PTAL 😄
hack/lib/golang.sh
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the set +/-u?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KUBEEDGE_BUILD_IMAGE="kubeedge/build-tools" | |
MOUNTPATH=${MOUNTPATH:-"/kubeedge"} | |
KUBEEDGE_BUILD_IMAGE=${KUBEEDGE_BUILD_IMAGE:-"kubeedge/build-tools"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
Makefile
Outdated
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
[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 |
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?: