Make the build/release process more generic to allow multiple release targets
such as core and image binaries. This makes the build/release process once
again platform independent (provided docker is available on the host), and
re-enables support for build-release/build-images on OSX.
| ... | ... |
@@ -4,10 +4,3 @@ Hello, OpenShift! |
| 4 | 4 |
This example will serve an http response of "Hello Openshift!" to [http://localhost:6061](http://localhost:6061). To create the pod run: |
| 5 | 5 |
|
| 6 | 6 |
$ osc create -f examples/hello-openshift/hello-pod.json |
| 7 |
- |
|
| 8 |
-Contribute |
|
| 9 |
- |
|
| 10 |
-For any updates to hello_openshift.go, the hello_openshift binary should be rebuilt using: |
|
| 11 |
- |
|
| 12 |
- $ CGO_ENABLED=0 go build -a -ldflags '-s' hello_openshift.go |
| ... | ... |
@@ -9,11 +9,24 @@ set -o pipefail |
| 9 | 9 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
|
| 10 | 10 |
source "${OS_ROOT}/hack/common.sh"
|
| 11 | 11 |
|
| 12 |
-OS_BUILD_PLATFORMS=("${OS_COMPILE_PLATFORMS[@]-}")
|
|
| 13 |
-os::build::build_binaries "${OS_COMPILE_TARGETS[@]-}"
|
|
| 14 |
- |
|
| 12 |
+# Build the core client/server for all platforms |
|
| 15 | 13 |
OS_BUILD_PLATFORMS=("${OS_CROSS_COMPILE_PLATFORMS[@]}")
|
| 16 | 14 |
os::build::build_binaries "${OS_CROSS_COMPILE_TARGETS[@]}"
|
| 17 | 15 |
|
| 18 |
-OS_RELEASE_ARCHIVES="${OS_OUTPUT}/releases"
|
|
| 16 |
+# Build image binaries for a subset of platforms. Image binaries are currently |
|
| 17 |
+# linux-only, and are compiled with flags to make them static for use in Docker |
|
| 18 |
+# images "FROM scratch". |
|
| 19 |
+OS_BUILD_PLATFORMS=("${OS_IMAGE_COMPILE_PLATFORMS[@]-}")
|
|
| 20 |
+CGO_ENABLED=0 OS_GOFLAGS="-a" os::build::build_binaries "${OS_IMAGE_COMPILE_TARGETS[@]-}"
|
|
| 21 |
+ |
|
| 22 |
+# Make the core client/server release. |
|
| 23 |
+OS_RELEASE_ARCHIVE="openshift-origin-core" |
|
| 24 |
+OS_RELEASE_PLATFORMS=("${OS_CROSS_COMPILE_PLATFORMS[@]}")
|
|
| 25 |
+OS_RELEASE_BINARIES=("${OS_CROSS_COMPILE_BINARIES[@]}")
|
|
| 26 |
+os::build::place_bins |
|
| 27 |
+ |
|
| 28 |
+# Make the image binaries release. |
|
| 29 |
+OS_RELEASE_ARCHIVE="openshift-origin-image" |
|
| 30 |
+OS_RELEASE_PLATFORMS=("${OS_IMAGE_COMPILE_PLATFORMS[@]-}")
|
|
| 31 |
+OS_RELEASE_BINARIES=("${OS_IMAGE_COMPILE_BINARIES[@]}")
|
|
| 19 | 32 |
os::build::place_bins |
| ... | ... |
@@ -18,29 +18,27 @@ if [[ ! -d _output/local/releases ]]; then |
| 18 | 18 |
echo "No release has been built. Run hack/build-release.sh" |
| 19 | 19 |
exit 1 |
| 20 | 20 |
fi |
| 21 |
-releases=$(find _output/local/releases/ -print | grep 'openshift-origin-.*-linux-' --color=never) |
|
| 22 |
-if [[ $(echo $releases | wc -l) -ne 1 ]]; then |
|
| 23 |
- echo "There must be exactly one Linux release tar in _output/local/releases" |
|
| 24 |
- exit 1 |
|
| 25 |
-fi |
|
| 26 |
-echo "Building images from ${releases}"
|
|
| 21 |
+ |
|
| 22 |
+# Extract the release achives to a staging area. |
|
| 23 |
+os::build::detect_local_release_tars "linux" |
|
| 24 |
+ |
|
| 25 |
+echo "Building images from release tars:" |
|
| 26 |
+echo " core: $(basename ${OS_CORE_RELEASE_TAR})"
|
|
| 27 |
+echo " image: $(basename ${OS_IMAGE_RELEASE_TAR})"
|
|
| 27 | 28 |
|
| 28 | 29 |
imagedir="_output/imagecontext" |
| 29 | 30 |
rm -rf "${imagedir}"
|
| 30 | 31 |
mkdir -p "${imagedir}"
|
| 31 |
-tar xzf "${releases}" -C "${imagedir}"
|
|
| 32 |
+tar xzf "${OS_CORE_RELEASE_TAR}" -C "${imagedir}"
|
|
| 33 |
+tar xzf "${OS_IMAGE_RELEASE_TAR}" -C "${imagedir}"
|
|
| 32 | 34 |
|
| 33 |
-# copy build artifacts to the appropriate locations |
|
| 35 |
+# Copy core binaries to the appropriate locations. |
|
| 34 | 36 |
cp -f "${imagedir}/openshift" images/origin/bin
|
| 35 | 37 |
cp -f "${imagedir}/openshift" images/router/haproxy/bin
|
| 36 | 38 |
|
| 37 |
-# build hello-openshift binary |
|
| 38 |
-"${OS_ROOT}/hack/build-go.sh" examples/hello-openshift
|
|
| 39 |
- |
|
| 40 |
-# build pod binary |
|
| 41 |
-# TODO: move me to build release |
|
| 42 |
-"${OS_ROOT}/hack/build-go.sh" images/pod
|
|
| 43 |
-cp -f "_output/local/go/bin/pod" images/pod/bin |
|
| 39 |
+# Copy image binaries to the appropriate locations. |
|
| 40 |
+cp -f "${imagedir}/pod" images/pod/bin
|
|
| 41 |
+cp -f "${imagedir}/hello-openshift" examples/hello-openshift/bin
|
|
| 44 | 42 |
|
| 45 | 43 |
# images that depend on scratch |
| 46 | 44 |
echo "--- openshift/origin-pod ---" |
| ... | ... |
@@ -15,35 +15,31 @@ cd "${OS_ROOT}"
|
| 15 | 15 |
|
| 16 | 16 |
context="${OS_ROOT}/_output/buildenv-context"
|
| 17 | 17 |
|
| 18 |
-# clean existing output |
|
| 18 |
+# Clean existing output. |
|
| 19 | 19 |
rm -rf "${OS_ROOT}/_output/local/releases"
|
| 20 | 20 |
rm -rf "${OS_ROOT}/_output/local/go/bin"
|
| 21 | 21 |
rm -rf "${context}"
|
| 22 | 22 |
mkdir -p "${context}"
|
| 23 | 23 |
mkdir -p "${OS_ROOT}/_output/local"
|
| 24 | 24 |
|
| 25 |
-# generate version definitions |
|
| 25 |
+# Generate version definitions. |
|
| 26 | 26 |
os::build::get_version_vars |
| 27 | 27 |
os::build::save_version_vars "${context}/os-version-defs"
|
| 28 | 28 |
|
| 29 |
-# create the input archive |
|
| 29 |
+# Create the input archive. |
|
| 30 | 30 |
git archive --format=tar -o "${context}/archive.tar" HEAD
|
| 31 | 31 |
tar -rf "${context}/archive.tar" -C "${context}" os-version-defs
|
| 32 | 32 |
gzip -f "${context}/archive.tar"
|
| 33 | 33 |
|
| 34 |
-# build in the clean environment |
|
| 34 |
+# Perform the build and release in Docker. |
|
| 35 | 35 |
cat "${context}/archive.tar.gz" | docker run -i --cidfile="${context}/cid" openshift/origin-release
|
| 36 | 36 |
docker cp $(cat ${context}/cid):/go/src/github.com/openshift/origin/_output/local/releases "${OS_ROOT}/_output/local"
|
| 37 | 37 |
|
| 38 |
-# copy the linux release back to the _output/local/go/bin dir |
|
| 39 |
-releases=$(find _output/local/releases/ -print | grep 'openshift-origin-.*-linux-' --color=never) |
|
| 40 |
-if [[ $(echo $releases | wc -l) -ne 1 ]]; then |
|
| 41 |
- echo "There should be exactly one Linux release tar in _output/local/releases" |
|
| 42 |
- exit 1 |
|
| 43 |
-fi |
|
| 38 |
+# Copy the linux release archives release back to the local _output/local/go/bin directory. |
|
| 39 |
+os::build::detect_local_release_tars "linux" |
|
| 44 | 40 |
|
| 45 |
-bindir="_output/local/go/bin" |
|
| 46 |
-mkdir -p "${bindir}"
|
|
| 47 |
-tar mxzf "${releases}" -C "${bindir}"
|
|
| 41 |
+mkdir -p "${OS_LOCAL_BINPATH}"
|
|
| 42 |
+tar mxzf "${OS_CORE_RELEASE_TAR}" -C "${OS_LOCAL_BINPATH}"
|
|
| 43 |
+tar mxzf "${OS_IMAGE_RELEASE_TAR}" -C "${OS_LOCAL_BINPATH}"
|
|
| 48 | 44 |
|
| 49 | 45 |
os::build::make_openshift_binary_symlinks |
| ... | ... |
@@ -19,16 +19,19 @@ OS_OUTPUT_SUBPATH="${OS_OUTPUT_SUBPATH:-_output/local}"
|
| 19 | 19 |
OS_OUTPUT="${OS_ROOT}/${OS_OUTPUT_SUBPATH}"
|
| 20 | 20 |
OS_OUTPUT_BINPATH="${OS_OUTPUT}/bin"
|
| 21 | 21 |
OS_LOCAL_BINPATH="${OS_ROOT}/_output/local/go/bin"
|
| 22 |
+OS_LOCAL_RELEASEPATH="${OS_ROOT}/_output/local/releases"
|
|
| 22 | 23 |
|
| 23 | 24 |
readonly OS_GO_PACKAGE=github.com/openshift/origin |
| 24 | 25 |
readonly OS_GOPATH="${OS_OUTPUT}/go"
|
| 25 | 26 |
|
| 26 |
-readonly OS_COMPILE_PLATFORMS=( |
|
| 27 |
+readonly OS_IMAGE_COMPILE_PLATFORMS=( |
|
| 27 | 28 |
linux/amd64 |
| 28 | 29 |
) |
| 29 |
-readonly OS_COMPILE_TARGETS=( |
|
| 30 |
+readonly OS_IMAGE_COMPILE_TARGETS=( |
|
| 31 |
+ images/pod |
|
| 32 |
+ examples/hello-openshift |
|
| 30 | 33 |
) |
| 31 |
-readonly OS_COMPILE_BINARIES=("${OS_COMPILE_TARGETS[@]-##*/}")
|
|
| 34 |
+readonly OS_IMAGE_COMPILE_BINARIES=("${OS_IMAGE_COMPILE_TARGETS[@]##*/}")
|
|
| 32 | 35 |
|
| 33 | 36 |
readonly OS_CROSS_COMPILE_PLATFORMS=( |
| 34 | 37 |
linux/amd64 |
| ... | ... |
@@ -41,7 +44,7 @@ readonly OS_CROSS_COMPILE_TARGETS=( |
| 41 | 41 |
readonly OS_CROSS_COMPILE_BINARIES=("${OS_CROSS_COMPILE_TARGETS[@]##*/}")
|
| 42 | 42 |
|
| 43 | 43 |
readonly OS_ALL_TARGETS=( |
| 44 |
- "${OS_COMPILE_TARGETS[@]-}"
|
|
| 44 |
+ "${OS_IMAGE_COMPILE_TARGETS[@]-}"
|
|
| 45 | 45 |
"${OS_CROSS_COMPILE_TARGETS[@]}"
|
| 46 | 46 |
) |
| 47 | 47 |
readonly OS_ALL_BINARIES=("${OS_ALL_TARGETS[@]##*/}")
|
| ... | ... |
@@ -220,11 +223,11 @@ EOF |
| 220 | 220 |
unset GOBIN |
| 221 | 221 |
} |
| 222 | 222 |
|
| 223 |
-# This will take binaries from $GOPATH/bin and copy them to the appropriate |
|
| 223 |
+# This will take OS_RELEASE_BINARIES from $GOPATH/bin and copy them to the appropriate |
|
| 224 | 224 |
# place in ${OS_OUTPUT_BINDIR}
|
| 225 | 225 |
# |
| 226 |
-# If OS_RELEASE_ARCHIVES is set to a directory, it will have tar archives of |
|
| 227 |
-# each CROSS_COMPILE_PLATFORM created |
|
| 226 |
+# If OS_RELEASE_ARCHIVE is set, tar archives prefixed with OS_RELEASE_ARCHIVE for |
|
| 227 |
+# each OS_RELEASE_PLATFORMS are created. |
|
| 228 | 228 |
# |
| 229 | 229 |
# Ideally this wouldn't be necessary and we could just set GOBIN to |
| 230 | 230 |
# OS_OUTPUT_BINDIR but that won't work in the face of cross compilation. 'go |
| ... | ... |
@@ -238,41 +241,74 @@ os::build::place_bins() {
|
| 238 | 238 |
|
| 239 | 239 |
echo "++ Placing binaries" |
| 240 | 240 |
|
| 241 |
- if [[ "${OS_RELEASE_ARCHIVES-}" != "" ]]; then
|
|
| 241 |
+ if [[ "${OS_RELEASE_ARCHIVE-}" != "" ]]; then
|
|
| 242 | 242 |
os::build::get_version_vars |
| 243 |
- rm -rf "${OS_RELEASE_ARCHIVES}"
|
|
| 244 |
- mkdir -p "${OS_RELEASE_ARCHIVES}"
|
|
| 243 |
+ mkdir -p "${OS_LOCAL_RELEASEPATH}"
|
|
| 245 | 244 |
fi |
| 246 | 245 |
|
| 247 |
- local platform |
|
| 248 |
- for platform in "${OS_CROSS_COMPILE_PLATFORMS[@]}"; do
|
|
| 246 |
+ for platform in "${OS_RELEASE_PLATFORMS[@]-(host_platform)}"; do
|
|
| 249 | 247 |
# The substitution on platform_src below will replace all slashes with |
| 250 | 248 |
# underscores. It'll transform darwin/amd64 -> darwin_amd64. |
| 251 | 249 |
local platform_src="/${platform//\//_}"
|
| 252 | 250 |
if [[ $platform == $host_platform ]]; then |
| 253 | 251 |
platform_src="" |
| 254 | 252 |
fi |
| 253 |
+ |
|
| 254 |
+ # Skip this directory if the platform has no binaries. |
|
| 255 |
+ local full_binpath_src="${OS_GOPATH}/bin${platform_src}"
|
|
| 256 |
+ if [[ ! -d "${full_binpath_src}" ]]; then
|
|
| 257 |
+ continue |
|
| 258 |
+ fi |
|
| 259 |
+ |
|
| 260 |
+ mkdir -p "${OS_OUTPUT_BINPATH}/${platform}"
|
|
| 261 |
+ |
|
| 262 |
+ # Create an array of binaries to release. Append .exe variants if the platform is windows. |
|
| 263 |
+ local -a binaries=() |
|
| 264 |
+ local binary |
|
| 265 |
+ for binary in "${OS_RELEASE_BINARIES[@]}"; do
|
|
| 266 |
+ binaries+=("${binary}")
|
|
| 267 |
+ if [[ $platform == "windows/amd64" ]]; then |
|
| 268 |
+ binaries+=("${binary}.exe")
|
|
| 269 |
+ fi |
|
| 270 |
+ done |
|
| 271 |
+ |
|
| 272 |
+ # Copy the only the specified release binaries to the shared OS_OUTPUT_BINPATH. |
|
| 273 |
+ local -a includes=() |
|
| 274 |
+ for binary in "${binaries[@]}"; do
|
|
| 275 |
+ includes+=("--include=${binary}")
|
|
| 276 |
+ done |
|
| 277 |
+ find "${full_binpath_src}" -maxdepth 1 -type f -exec \
|
|
| 278 |
+ rsync "${includes[@]}" --exclude="*" -pt {} "${OS_OUTPUT_BINPATH}/${platform}" \;
|
|
| 279 |
+ |
|
| 280 |
+ # If no release archive was requested, we're done. |
|
| 281 |
+ if [[ "${OS_RELEASE_ARCHIVE-}" == "" ]]; then
|
|
| 282 |
+ continue |
|
| 283 |
+ fi |
|
| 284 |
+ |
|
| 285 |
+ # Create a temporary bin directory containing only the binaries marked for release. |
|
| 286 |
+ local release_binpath=$(mktemp -d openshift.release.${OS_RELEASE_ARCHIVE}.XXX)
|
|
| 287 |
+ find "${full_binpath_src}" -maxdepth 1 -type f -exec \
|
|
| 288 |
+ rsync "${includes[@]}" --exclude="*" -pt {} "${release_binpath}" \;
|
|
| 289 |
+ |
|
| 290 |
+ # Create binary copies where specified. |
|
| 255 | 291 |
local suffix="" |
| 256 | 292 |
if [[ $platform == "windows/amd64" ]]; then |
| 257 | 293 |
suffix=".exe" |
| 258 | 294 |
fi |
| 259 |
- |
|
| 260 |
- local full_binpath_src="${OS_GOPATH}/bin${platform_src}"
|
|
| 261 |
- if [[ -d "${full_binpath_src}" ]]; then
|
|
| 262 |
- mkdir -p "${OS_OUTPUT_BINPATH}/${platform}"
|
|
| 263 |
- find "${full_binpath_src}" -maxdepth 1 -type f -exec \
|
|
| 264 |
- rsync -pt {} "${OS_OUTPUT_BINPATH}/${platform}" \;
|
|
| 265 |
- |
|
| 266 |
- if [[ "${OS_RELEASE_ARCHIVES-}" != "" ]]; then
|
|
| 267 |
- local platform_segment="${platform//\//-}"
|
|
| 268 |
- local archive_name="openshift-origin-${OS_GIT_VERSION}-${OS_GIT_COMMIT}-${platform_segment}.tar.gz"
|
|
| 269 |
- for linkname in "${OPENSHIFT_BINARY_COPY[@]}"; do
|
|
| 270 |
- cp "${OS_OUTPUT_BINPATH}/${platform}/openshift${suffix}" "${OS_OUTPUT_BINPATH}/${platform}/${linkname}${suffix}"
|
|
| 271 |
- done |
|
| 272 |
- echo "++ Creating ${archive_name}"
|
|
| 273 |
- tar -czf "${OS_RELEASE_ARCHIVES}/${archive_name}" -C "${OS_OUTPUT_BINPATH}/${platform}" .
|
|
| 295 |
+ for linkname in "${OPENSHIFT_BINARY_COPY[@]}"; do
|
|
| 296 |
+ local src="${release_binpath}/openshift${suffix}"
|
|
| 297 |
+ if [[ -f "${src}" ]]; then
|
|
| 298 |
+ cp "${release_binpath}/openshift${suffix}" "${release_binpath}/${linkname}${suffix}"
|
|
| 274 | 299 |
fi |
| 275 |
- fi |
|
| 300 |
+ done |
|
| 301 |
+ |
|
| 302 |
+ # Create the release archive. |
|
| 303 |
+ local platform_segment="${platform//\//-}"
|
|
| 304 |
+ local archive_name="${OS_RELEASE_ARCHIVE}-${OS_GIT_VERSION}-${OS_GIT_COMMIT}-${platform_segment}.tar.gz"
|
|
| 305 |
+ |
|
| 306 |
+ echo "++ Creating ${archive_name}"
|
|
| 307 |
+ tar -czf "${OS_LOCAL_RELEASEPATH}/${archive_name}" -C "${release_binpath}" .
|
|
| 308 |
+ rm -rf "${release_binpath}"
|
|
| 276 | 309 |
done |
| 277 | 310 |
) |
| 278 | 311 |
} |
| ... | ... |
@@ -287,6 +323,33 @@ os::build::make_openshift_binary_symlinks() {
|
| 287 | 287 |
fi |
| 288 | 288 |
} |
| 289 | 289 |
|
| 290 |
+# os::build::detect_local_release_tars verifies there is only one core and one |
|
| 291 |
+# image binaries release tar in OS_LOCAL_RELEASEPATH for the given platform specified by |
|
| 292 |
+# argument 1, exiting if more than one of either is found. |
|
| 293 |
+# |
|
| 294 |
+# If the tars are discovered, their full paths are exported to the following env vars: |
|
| 295 |
+# |
|
| 296 |
+# OS_CORE_RELEASE_TAR |
|
| 297 |
+# OS_IMAGE_RELEASE_TAR |
|
| 298 |
+os::build::detect_local_release_tars() {
|
|
| 299 |
+ local platform="$1" |
|
| 300 |
+ |
|
| 301 |
+ local core=$(find ${OS_LOCAL_RELEASEPATH} -type f -maxdepth 1 -name openshift-origin-core*-${platform}-*)
|
|
| 302 |
+ if [[ $(echo "${core}" | wc -l) -ne 1 ]]; then
|
|
| 303 |
+ echo "There should be exactly one ${platform} core tar in $OS_LOCAL_RELEASEPATH"
|
|
| 304 |
+ exit 2 |
|
| 305 |
+ fi |
|
| 306 |
+ |
|
| 307 |
+ local image=$(find ${OS_LOCAL_RELEASEPATH} -type f -maxdepth 1 -name openshift-origin-image*-${platform}-*)
|
|
| 308 |
+ if [[ $(echo "${image}" | wc -l) -ne 1 ]]; then
|
|
| 309 |
+ echo "There should be exactly one ${platform} image tar in $OS_LOCAL_RELEASEPATH"
|
|
| 310 |
+ exit 3 |
|
| 311 |
+ fi |
|
| 312 |
+ |
|
| 313 |
+ export OS_CORE_RELEASE_TAR="${core}"
|
|
| 314 |
+ export OS_IMAGE_RELEASE_TAR="${image}"
|
|
| 315 |
+} |
|
| 316 |
+ |
|
| 290 | 317 |
# os::build::get_version_vars loads the standard version variables as |
| 291 | 318 |
# ENV vars |
| 292 | 319 |
os::build::get_version_vars() {
|