Skip to content

Commit

Permalink
Cross-compile virtctl and copy the result to _out/cmd/virtctl/
Browse files Browse the repository at this point in the history
  • Loading branch information
rmohr committed Mar 15, 2019
1 parent 8f2ad4b commit 23782da
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ deploy:
secure: KD1d1EkvX5iY5pvKQbi6Aj6y49XXnQBxBMok9x2d9LVMbmzBQIHoTqUQz2Dv2TSpANshkIrLmR1eT/brCK382cIUVvA6kG8JB2yqAAE2hzJ8u49+CI4iyqpBWw1HCuH/4xPWZUPVBW0Yl9WsW0vencAeKK6cTDm4Z9K3esJf+iZMpJh7ZpK2ESn9d2RZsrpOKJpxYrvt14Wox+8YfqPRCTJoO/Q8vdXbyOrRVpK6daSe11HsmTZZpFzgLWGojpjH05wcENUaokpCIp8Hgx3rJmO9z5iReNG+2QuPCw0QyEIKGAvzlA5KbYFWBUurxz0XsnaovbJ7BKI070arxQKjKRnjSNE3kEValOwMIE8dA835A1nChm85NILQdWvlbexSxPpz0z62SGPjFthUj9VBx/RnUrd1itxWOi6ZW5k6PnWDUoKPr63+fYSAkp6bXO9ELexA19wUfQCicGRBEO3mJ6QvKKbiDAFKWcABlavxlNtFgw1mMPxxWEhKkW0PrCqOVu9fDDzJ48DCD5XHRT8HUVHDeKcscMTW675rlzo3SxTJdqnZSybpbMSmKbxNs0rM8kPXf1RQLsGDg4CC6Daxz255PV5Y/+p0AhZ2hWtfC3c/Ff8wOdDSdCaEcg5tGa/e1kJWAKuIATUGdZsFZUri8ePQcgcXzM4ihANn7gP8Cl4=
file_glob: true
file:
- _out/cmd/virtctl/virtctl-v*
- _out/cmd/virtctl/virtctl-*
- _out/manifests/release/kubevirt.yaml
- _out/templates/manifests/release/kubevirt.yaml.j2
- _out/manifests/release/demo-content.yaml
Expand Down
10 changes: 10 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,13 @@ go_library(
importpath = "kubevirt.io/kubevirt",
visibility = ["//visibility:public"],
)

genrule(
name = "build-virtctl",
srcs = [
"//cmd/virtctl",
],
outs = ["virtctl-copier"],
cmd = "echo '#!/bin/sh\n\ncp $(SRCS) $$1' > \"$@\"",
executable = 1,
)
10 changes: 2 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ export GO15VENDOREXPERIMENT := 1

all:
hack/dockerized "DOCKER_PREFIX=${DOCKER_PREFIX} DOCKER_TAG=${DOCKER_TAG} IMAGE_PULL_POLICY=${IMAGE_PULL_POLICY} VERBOSITY=${VERBOSITY} ./hack/build-manifests.sh && \
hack/bazel-fmt.sh && bazel build \
--platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 \
--workspace_status_command=./hack/print-workspace-status.sh \
//cmd/..."
hack/bazel-fmt.sh && hack/bazel-build.sh"

go-all:
hack/dockerized "KUBEVIRT_VERSION=${KUBEVIRT_VERSION} ./hack/build-go.sh install ${WHAT} && ./hack/build-copy-artifacts.sh ${WHAT} && DOCKER_PREFIX=${DOCKER_PREFIX} DOCKER_TAG=${DOCKER_TAG} IMAGE_PULL_POLICY=${IMAGE_PULL_POLICY} VERBOSITY=${VERBOSITY} ./hack/build-manifests.sh"
Expand All @@ -15,10 +12,7 @@ bazel-generate:
SYNC_VENDOR=true hack/dockerized "./hack/bazel-generate.sh"

bazel-build:
hack/dockerized "hack/bazel-fmt.sh && bazel build \
--platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 \
--workspace_status_command=./hack/print-workspace-status.sh \
//cmd/..."
hack/dockerized "hack/bazel-fmt.sh && hack/bazel-build.sh"

bazel-build-images:
hack/dockerized "DOCKER_PREFIX=${DOCKER_PREFIX} DOCKER_TAG=${DOCKER_TAG} DOCKER_TAG_ALT=${DOCKER_TAG_ALT} ./hack/bazel-build-images.sh"
Expand Down
1 change: 1 addition & 0 deletions cluster/ephemeral-provider-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function _add_common_params() {
function build() {
# Build everyting and publish it
${KUBEVIRT_PATH}hack/dockerized "DOCKER_PREFIX=${DOCKER_PREFIX} DOCKER_TAG=${DOCKER_TAG} KUBEVIRT_PROVIDER=${KUBEVIRT_PROVIDER} IMAGE_PULL_POLICY=${IMAGE_PULL_POLICY} VERBOSITY=${VERBOSITY} ./hack/build-manifests.sh"
${KUBEVIRT_PATH}hack/dockerized "DOCKER_PREFIX=${DOCKER_PREFIX} DOCKER_TAG=${DOCKER_TAG} KUBEVIRT_PROVIDER=${KUBEVIRT_PROVIDER} ./hack/bazel-build.sh"
${KUBEVIRT_PATH}hack/dockerized "DOCKER_PREFIX=${DOCKER_PREFIX} DOCKER_TAG=${DOCKER_TAG} DOCKER_TAG_ALT=${DOCKER_TAG_ALT} KUBEVIRT_PROVIDER=${KUBEVIRT_PROVIDER} ./hack/bazel-push-images.sh"

# Make sure that all nodes use the newest images
Expand Down
2 changes: 1 addition & 1 deletion cluster/external/provider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ function down() {
function build() {
# Build code and manifests
${KUBEVIRT_PATH}hack/dockerized "DOCKER_TAG=${DOCKER_TAG} DOCKER_PREFIX=${docker_prefix} KUBEVIRT_PROVIDER=${KUBEVIRT_PROVIDER} ./hack/build-manifests.sh"
DOCKER_PREFIX=${docker_prefix} DOCKER_TAG=${docker_tag} make bazel-push-images
DOCKER_PREFIX=${docker_prefix} DOCKER_TAG=${docker_tag} make build bazel-push-images
}
7 changes: 1 addition & 6 deletions cluster/virtctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,4 @@ elif [ -n "$KUBECONFIG" ]; then
CONFIG_ARGS="--kubeconfig=${KUBECONFIG}"
fi

VIRTCTL=virtctl
if [ "$(uname -s)" = "Darwin" ]; then
VIRTCTL='virtctl-darwin'
fi

${KUBEVIRT_DIR}/_out/cmd/virtctl/${VIRTCTL} $CONFIG_ARGS "$@"
${KUBEVIRT_DIR}/_out/cmd/virtctl/virtctl $CONFIG_ARGS "$@"
57 changes: 57 additions & 0 deletions hack/bazel-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
#
# This file is part of the KubeVirt project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright 2019 Red Hat, Inc.
#

set -e

source hack/common.sh
source hack/config.sh

rm -rf ${CMD_OUT_DIR}
mkdir -p ${CMD_OUT_DIR}/virtctl

# Build all binaries for amd64
bazel build \
--platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 \
--workspace_status_command=./hack/print-workspace-status.sh \
//cmd/...

# build platform native virtctl explicitly
bazel run \
--workspace_status_command=./hack/print-workspace-status.sh \
:build-virtctl -- ${CMD_OUT_DIR}/virtctl/virtctl

# cross-compile virtctl for

# linux
bazel run \
--platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 \
--workspace_status_command=./hack/print-workspace-status.sh \
:build-virtctl -- ${CMD_OUT_DIR}/virtctl/virtctl-${KUBEVIRT_VERSION}-linux-amd64

# darwin
bazel run \
--platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64 \
--workspace_status_command=./hack/print-workspace-status.sh \
:build-virtctl -- ${CMD_OUT_DIR}/virtctl/virtctl-${KUBEVIRT_VERSION}-darwin-amd64

# windows
bazel run \
--platforms=@io_bazel_rules_go//go/toolchain:windows_amd64 \
--workspace_status_command=./hack/print-workspace-status.sh \
:build-virtctl -- ${CMD_OUT_DIR}/virtctl/virtctl-${KUBEVIRT_VERSION}-windows-amd64.exe

0 comments on commit 23782da

Please sign in to comment.