Skip to content

Commit

Permalink
Portably cross-compile image binaries
Browse files Browse the repository at this point in the history
Special-case binaries destined for extra images (like images/pod) by
building them as normal compilation targets, excluding them from the release
tarball, and pulling them from docker individually (rather than extracting
them from the release tarball). This is effectively cross-compiling the image
binaries via docker so the binaries can be included in their platform-specific
images (via the image bin directories, in which the binaries are places during
the release).

This change re-enables support for native use of build-images.sh on OSX.
  • Loading branch information
ironcladlou committed Feb 9, 2015
1 parent f23fe62 commit 96f4569
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 25 deletions.
21 changes: 9 additions & 12 deletions hack/build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,27 @@ if [[ ! -d _output/local/releases ]]; then
echo "No release has been built. Run hack/build-release.sh"
exit 1
fi
releases=$(find _output/local/releases/ -print | grep 'openshift-origin-.*-linux-' --color=never)
if [[ $(echo $releases | wc -l) -ne 1 ]]; then
echo "There must be exactly one Linux release tar in _output/local/releases"
exit 1
fi
echo "Building images from ${releases}"

os::build::verify_local_linux_release_tars

echo "Building images from ${OS_RELEASE_LINUX_TAR} and ${OS_IMAGEBINS_LINUX_TAR}"

imagedir="_output/imagecontext"
rm -rf "${imagedir}"
mkdir -p "${imagedir}"
tar xzf "${releases}" -C "${imagedir}"
tar xzf "${OS_RELEASE_LINUX_TAR}" -C "${imagedir}"
tar xzf "${OS_IMAGEBINS_LINUX_TAR}" -C "${imagedir}"

# copy build artifacts to the appropriate locations
cp -f "${imagedir}/openshift" images/origin/bin
cp -f "${imagedir}/openshift" images/router/haproxy/bin

# copy image binaries to their image bin directories
cp -f "${imagedir}/openshift" images/pod/bin

# build hello-openshift binary
"${OS_ROOT}/hack/build-go.sh" examples/hello-openshift

# build pod binary
# TODO: move me to build release
"${OS_ROOT}/hack/build-go.sh" images/pod
cp -f "_output/local/go/bin/pod" images/pod/bin

# images that depend on scratch
echo "--- openshift/origin-pod ---"
docker build -t openshift/origin-pod images/pod
Expand Down
14 changes: 5 additions & 9 deletions hack/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,10 @@ cat "${context}/archive.tar.gz" | docker run -i --cidfile="${context}/cid" opens
docker cp $(cat ${context}/cid):/go/src/github.com/openshift/origin/_output/local/releases "${OS_ROOT}/_output/local"

# copy the linux release back to the _output/local/go/bin dir
releases=$(find _output/local/releases/ -print | grep 'openshift-origin-.*-linux-' --color=never)
if [[ $(echo $releases | wc -l) -ne 1 ]]; then
echo "There should be exactly one Linux release tar in _output/local/releases"
exit 1
fi

bindir="_output/local/go/bin"
mkdir -p "${bindir}"
tar mxzf "${releases}" -C "${bindir}"
os::build::verify_local_linux_release_tars

mkdir -p "${OS_LOCAL_BINPATH}"
tar mxzf "${OS_RELEASE_LINUX_TAR}" -C "${OS_LOCAL_BINPATH}"
tar mxzf "${OS_IMAGEBINS_LINUX_TAR}" -C "${OS_LOCAL_BINPATH}"

os::build::make_openshift_binary_symlinks
62 changes: 60 additions & 2 deletions hack/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ OS_OUTPUT_SUBPATH="${OS_OUTPUT_SUBPATH:-_output/local}"
OS_OUTPUT="${OS_ROOT}/${OS_OUTPUT_SUBPATH}"
OS_OUTPUT_BINPATH="${OS_OUTPUT}/bin"
OS_LOCAL_BINPATH="${OS_ROOT}/_output/local/go/bin"
OS_LOCAL_RELEASEPATH="${OS_ROOT}/_output/local/releases"

readonly OS_GO_PACKAGE=github.com/openshift/origin
readonly OS_GOPATH="${OS_OUTPUT}/go"
Expand All @@ -27,6 +28,7 @@ readonly OS_COMPILE_PLATFORMS=(
linux/amd64
)
readonly OS_COMPILE_TARGETS=(
images/pod
)
readonly OS_COMPILE_BINARIES=("${OS_COMPILE_TARGETS[@]-##*/}")

Expand Down Expand Up @@ -55,6 +57,15 @@ readonly OPENSHIFT_BINARY_SYMLINKS=(
readonly OPENSHIFT_BINARY_COPY=(
osc
)
# These are binaries which should be included in the primary release tar.
readonly OPENSHIFT_RELEASE_BINARIES=(
openshift
openshift.exe
)
# These are binaries which should be included in the image binaries tar.
readonly OPENSHIFT_IMAGE_BINARIES=(
pod
)

# os::build::binaries_from_targets take a list of build targets and return the
# full go package to be built
Expand Down Expand Up @@ -260,17 +271,40 @@ os::build::place_bins() {
local full_binpath_src="${OS_GOPATH}/bin${platform_src}"
if [[ -d "${full_binpath_src}" ]]; then
mkdir -p "${OS_OUTPUT_BINPATH}/${platform}"
mkdir -p "${OS_OUTPUT_BINPATH}/image-bin/${platform}"

# Sync only the release binaries to the release bin directory
local -a includes=()
local binary
for binary in "${OPENSHIFT_RELEASE_BINARIES[@]}"; do
includes+=("--include=${binary}")
done

find "${full_binpath_src}" -maxdepth 1 -type f -exec \
rsync "${includes[@]}" --exclude="*" -pt {} "${OS_OUTPUT_BINPATH}/${platform}" \;

# Sync only the image binaries to the image bin directory
includes=()
for binary in "${OPENSHIFT_IMAGE_BINARIES[@]}"; do
includes+=("--include=${binary}")
done

find "${full_binpath_src}" -maxdepth 1 -type f -exec \
rsync -pt {} "${OS_OUTPUT_BINPATH}/${platform}" \;
rsync "${includes[@]}" --exclude="*" -pt {} "${OS_OUTPUT_BINPATH}/image-bin/${platform}" \;

if [[ "${OS_RELEASE_ARCHIVES-}" != "" ]]; then
local platform_segment="${platform//\//-}"
local archive_name="openshift-origin-${OS_GIT_VERSION}-${OS_GIT_COMMIT}-${platform_segment}.tar.gz"
local archive_name="openshift-origin-release-${OS_GIT_VERSION}-${OS_GIT_COMMIT}-${platform_segment}.tar.gz"
for linkname in "${OPENSHIFT_BINARY_COPY[@]}"; do
cp "${OS_OUTPUT_BINPATH}/${platform}/openshift${suffix}" "${OS_OUTPUT_BINPATH}/${platform}/${linkname}${suffix}"
done
echo "++ Creating ${archive_name}"
tar -czf "${OS_RELEASE_ARCHIVES}/${archive_name}" -C "${OS_OUTPUT_BINPATH}/${platform}" .

# Create a tar for image binaries
archive_name="openshift-origin-imagebins-${OS_GIT_VERSION}-${OS_GIT_COMMIT}-${platform_segment}.tar.gz"
echo "++ Creating ${archive_name}"
tar -czf "${OS_RELEASE_ARCHIVES}/${archive_name}" -C "${OS_OUTPUT_BINPATH}/image-bin/${platform}" .
fi
fi
done
Expand All @@ -287,6 +321,30 @@ os::build::make_openshift_binary_symlinks() {
fi
}

# os::build::verify_local_linux_release_tars verifies there are only one release and one
# image binaries tar in OS_LOCAL_RELEASEPATH, exiting if more than one of either is found.
#
# If the tars are discovered, their full paths are exported to the following env vars:
#
# OS_RELEASE_LINUX_TAR
# OS_IMAGEBINS_LINUX_TAR
os::build::verify_local_linux_release_tars() {
local release=$(find $OS_LOCAL_RELEASEPATH -print | grep 'openshift-origin-release.*-linux-' --color=never)
if [[ $(echo "$release" | wc -l) -ne 1 ]]; then
echo "There should be exactly one Linux release tar in $OS_LOCAL_RELEASEPATH"
exit 1
fi

local imagebins=$(find $OS_LOCAL_RELEASEPATH -print | grep 'openshift-origin-imagebins.*-linux-' --color=never)
if [[ $(echo "$imagebins" | wc -l) -ne 1 ]]; then
echo "There should be exactly one Linux image binaries tar in $OS_LOCAL_RELEASEPATH"
exit 1
fi

export OS_RELEASE_LINUX_TAR="${release}"
export OS_IMAGEBINS_LINUX_TAR="${imagebins}"
}

# os::build::get_version_vars loads the standard version variables as
# ENV vars
os::build::get_version_vars() {
Expand Down
2 changes: 0 additions & 2 deletions images/pod/pod.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build linux

/*
Copyright 2014 Google Inc. All rights reserved.
Expand Down

0 comments on commit 96f4569

Please sign in to comment.