diff --git a/examples/hello-openshift/Dockerfile b/examples/hello-openshift/Dockerfile index 4672929d850e..6cca68decf80 100644 --- a/examples/hello-openshift/Dockerfile +++ b/examples/hello-openshift/Dockerfile @@ -1,4 +1,4 @@ FROM scratch MAINTAINER Jessica Forrester -ADD hello_openshift /hello_openshift -ENTRYPOINT ["/hello_openshift"] +ADD bin/hello-openshift /hello-openshift +ENTRYPOINT ["/hello-openshift"] diff --git a/examples/hello-openshift/README.md b/examples/hello-openshift/README.md index 7d4ce120c6a3..f25888c226ea 100644 --- a/examples/hello-openshift/README.md +++ b/examples/hello-openshift/README.md @@ -4,10 +4,3 @@ Hello, OpenShift! This example will serve an http response of "Hello Openshift!" to [http://localhost:6061](http://localhost:6061). To create the pod run: $ osc create -f examples/hello-openshift/hello-pod.json - -Contribute ----------- - -For any updates to hello_openshift.go, the hello_openshift binary should be rebuilt using: - - $ CGO_ENABLED=0 go build -a -ldflags '-s' hello_openshift.go diff --git a/examples/hello-openshift/bin/.gitignore b/examples/hello-openshift/bin/.gitignore new file mode 100644 index 000000000000..d6b7ef32c847 --- /dev/null +++ b/examples/hello-openshift/bin/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/examples/hello-openshift/hello_openshift b/examples/hello-openshift/hello_openshift deleted file mode 100755 index 74266a1a220a..000000000000 Binary files a/examples/hello-openshift/hello_openshift and /dev/null differ diff --git a/hack/build-cross.sh b/hack/build-cross.sh index 97c5a3bfce58..d159fb8369d6 100755 --- a/hack/build-cross.sh +++ b/hack/build-cross.sh @@ -9,11 +9,24 @@ set -o pipefail OS_ROOT=$(dirname "${BASH_SOURCE}")/.. source "${OS_ROOT}/hack/common.sh" -OS_BUILD_PLATFORMS=("${OS_COMPILE_PLATFORMS[@]-}") -os::build::build_binaries "${OS_COMPILE_TARGETS[@]-}" - +# Build the core client/server for all platforms OS_BUILD_PLATFORMS=("${OS_CROSS_COMPILE_PLATFORMS[@]}") os::build::build_binaries "${OS_CROSS_COMPILE_TARGETS[@]}" -OS_RELEASE_ARCHIVES="${OS_OUTPUT}/releases" +# Build image binaries for a subset of platforms. Image binaries are currently +# linux-only, and are compiled with flags to make them static for use in Docker +# images "FROM scratch". +OS_BUILD_PLATFORMS=("${OS_IMAGE_COMPILE_PLATFORMS[@]-}") +CGO_ENABLED=0 OS_GOFLAGS="-a" os::build::build_binaries "${OS_IMAGE_COMPILE_TARGETS[@]-}" + +# Make the core client/server release. +OS_RELEASE_ARCHIVE="openshift-origin-core" +OS_RELEASE_PLATFORMS=("${OS_CROSS_COMPILE_PLATFORMS[@]}") +OS_RELEASE_BINARIES=("${OS_CROSS_COMPILE_BINARIES[@]}") +os::build::place_bins + +# Make the image binaries release. +OS_RELEASE_ARCHIVE="openshift-origin-image" +OS_RELEASE_PLATFORMS=("${OS_IMAGE_COMPILE_PLATFORMS[@]-}") +OS_RELEASE_BINARIES=("${OS_IMAGE_COMPILE_BINARIES[@]}") os::build::place_bins diff --git a/hack/build-images.sh b/hack/build-images.sh index 971c7eb0e7c1..770363ae7435 100755 --- a/hack/build-images.sh +++ b/hack/build-images.sh @@ -18,29 +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}" + +# Extract the release achives to a staging area. +os::build::detect_local_release_tars "linux" + +echo "Building images from release tars:" +echo " core: $(basename ${OS_CORE_RELEASE_TAR})" +echo " image: $(basename ${OS_IMAGE_RELEASE_TAR})" imagedir="_output/imagecontext" rm -rf "${imagedir}" mkdir -p "${imagedir}" -tar xzf "${releases}" -C "${imagedir}" +tar xzf "${OS_CORE_RELEASE_TAR}" -C "${imagedir}" +tar xzf "${OS_IMAGE_RELEASE_TAR}" -C "${imagedir}" -# copy build artifacts to the appropriate locations +# Copy core binaries to the appropriate locations. cp -f "${imagedir}/openshift" images/origin/bin cp -f "${imagedir}/openshift" images/router/haproxy/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 +# Copy image binaries to the appropriate locations. +cp -f "${imagedir}/pod" images/pod/bin +cp -f "${imagedir}/hello-openshift" examples/hello-openshift/bin # images that depend on scratch echo "--- openshift/origin-pod ---" diff --git a/hack/build-release.sh b/hack/build-release.sh index 8d5c86978d0e..9d95da454a7c 100755 --- a/hack/build-release.sh +++ b/hack/build-release.sh @@ -15,35 +15,31 @@ cd "${OS_ROOT}" context="${OS_ROOT}/_output/buildenv-context" -# clean existing output +# Clean existing output. rm -rf "${OS_ROOT}/_output/local/releases" rm -rf "${OS_ROOT}/_output/local/go/bin" rm -rf "${context}" mkdir -p "${context}" mkdir -p "${OS_ROOT}/_output/local" -# generate version definitions +# Generate version definitions. os::build::get_version_vars os::build::save_version_vars "${context}/os-version-defs" -# create the input archive +# Create the input archive. git archive --format=tar -o "${context}/archive.tar" HEAD tar -rf "${context}/archive.tar" -C "${context}" os-version-defs gzip -f "${context}/archive.tar" -# build in the clean environment +# Perform the build and release in Docker. cat "${context}/archive.tar.gz" | docker run -i --cidfile="${context}/cid" openshift/origin-release 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 +# Copy the linux release archives release back to the local _output/local/go/bin directory. +os::build::detect_local_release_tars "linux" -bindir="_output/local/go/bin" -mkdir -p "${bindir}" -tar mxzf "${releases}" -C "${bindir}" +mkdir -p "${OS_LOCAL_BINPATH}" +tar mxzf "${OS_CORE_RELEASE_TAR}" -C "${OS_LOCAL_BINPATH}" +tar mxzf "${OS_IMAGE_RELEASE_TAR}" -C "${OS_LOCAL_BINPATH}" os::build::make_openshift_binary_symlinks diff --git a/hack/common.sh b/hack/common.sh index 5103e34cfe42..606317cafde8 100755 --- a/hack/common.sh +++ b/hack/common.sh @@ -19,16 +19,19 @@ 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" -readonly OS_COMPILE_PLATFORMS=( +readonly OS_IMAGE_COMPILE_PLATFORMS=( linux/amd64 ) -readonly OS_COMPILE_TARGETS=( +readonly OS_IMAGE_COMPILE_TARGETS=( + images/pod + examples/hello-openshift ) -readonly OS_COMPILE_BINARIES=("${OS_COMPILE_TARGETS[@]-##*/}") +readonly OS_IMAGE_COMPILE_BINARIES=("${OS_IMAGE_COMPILE_TARGETS[@]##*/}") readonly OS_CROSS_COMPILE_PLATFORMS=( linux/amd64 @@ -41,7 +44,7 @@ readonly OS_CROSS_COMPILE_TARGETS=( readonly OS_CROSS_COMPILE_BINARIES=("${OS_CROSS_COMPILE_TARGETS[@]##*/}") readonly OS_ALL_TARGETS=( - "${OS_COMPILE_TARGETS[@]-}" + "${OS_IMAGE_COMPILE_TARGETS[@]-}" "${OS_CROSS_COMPILE_TARGETS[@]}" ) readonly OS_ALL_BINARIES=("${OS_ALL_TARGETS[@]##*/}") @@ -220,11 +223,11 @@ EOF unset GOBIN } -# This will take binaries from $GOPATH/bin and copy them to the appropriate +# This will take OS_RELEASE_BINARIES from $GOPATH/bin and copy them to the appropriate # place in ${OS_OUTPUT_BINDIR} # -# If OS_RELEASE_ARCHIVES is set to a directory, it will have tar archives of -# each CROSS_COMPILE_PLATFORM created +# If OS_RELEASE_ARCHIVE is set, tar archives prefixed with OS_RELEASE_ARCHIVE for +# each OS_RELEASE_PLATFORMS are created. # # Ideally this wouldn't be necessary and we could just set GOBIN to # OS_OUTPUT_BINDIR but that won't work in the face of cross compilation. 'go @@ -238,41 +241,74 @@ os::build::place_bins() { echo "++ Placing binaries" - if [[ "${OS_RELEASE_ARCHIVES-}" != "" ]]; then + if [[ "${OS_RELEASE_ARCHIVE-}" != "" ]]; then os::build::get_version_vars - rm -rf "${OS_RELEASE_ARCHIVES}" - mkdir -p "${OS_RELEASE_ARCHIVES}" + mkdir -p "${OS_LOCAL_RELEASEPATH}" fi - local platform - for platform in "${OS_CROSS_COMPILE_PLATFORMS[@]}"; do + for platform in "${OS_RELEASE_PLATFORMS[@]-(host_platform)}"; do # The substitution on platform_src below will replace all slashes with # underscores. It'll transform darwin/amd64 -> darwin_amd64. local platform_src="/${platform//\//_}" if [[ $platform == $host_platform ]]; then platform_src="" fi + + # Skip this directory if the platform has no binaries. + local full_binpath_src="${OS_GOPATH}/bin${platform_src}" + if [[ ! -d "${full_binpath_src}" ]]; then + continue + fi + + mkdir -p "${OS_OUTPUT_BINPATH}/${platform}" + + # Create an array of binaries to release. Append .exe variants if the platform is windows. + local -a binaries=() + local binary + for binary in "${OS_RELEASE_BINARIES[@]}"; do + binaries+=("${binary}") + if [[ $platform == "windows/amd64" ]]; then + binaries+=("${binary}.exe") + fi + done + + # Copy the only the specified release binaries to the shared OS_OUTPUT_BINPATH. + local -a includes=() + for binary in "${binaries[@]}"; do + includes+=("--include=${binary}") + done + find "${full_binpath_src}" -maxdepth 1 -type f -exec \ + rsync "${includes[@]}" --exclude="*" -pt {} "${OS_OUTPUT_BINPATH}/${platform}" \; + + # If no release archive was requested, we're done. + if [[ "${OS_RELEASE_ARCHIVE-}" == "" ]]; then + continue + fi + + # Create a temporary bin directory containing only the binaries marked for release. + local release_binpath=$(mktemp -d openshift.release.${OS_RELEASE_ARCHIVE}.XXX) + find "${full_binpath_src}" -maxdepth 1 -type f -exec \ + rsync "${includes[@]}" --exclude="*" -pt {} "${release_binpath}" \; + + # Create binary copies where specified. local suffix="" if [[ $platform == "windows/amd64" ]]; then suffix=".exe" fi - - local full_binpath_src="${OS_GOPATH}/bin${platform_src}" - if [[ -d "${full_binpath_src}" ]]; then - mkdir -p "${OS_OUTPUT_BINPATH}/${platform}" - find "${full_binpath_src}" -maxdepth 1 -type f -exec \ - rsync -pt {} "${OS_OUTPUT_BINPATH}/${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" - 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}" . + for linkname in "${OPENSHIFT_BINARY_COPY[@]}"; do + local src="${release_binpath}/openshift${suffix}" + if [[ -f "${src}" ]]; then + cp "${release_binpath}/openshift${suffix}" "${release_binpath}/${linkname}${suffix}" fi - fi + done + + # Create the release archive. + local platform_segment="${platform//\//-}" + local archive_name="${OS_RELEASE_ARCHIVE}-${OS_GIT_VERSION}-${OS_GIT_COMMIT}-${platform_segment}.tar.gz" + + echo "++ Creating ${archive_name}" + tar -czf "${OS_LOCAL_RELEASEPATH}/${archive_name}" -C "${release_binpath}" . + rm -rf "${release_binpath}" done ) } @@ -287,6 +323,33 @@ os::build::make_openshift_binary_symlinks() { fi } +# os::build::detect_local_release_tars verifies there is only one core and one +# image binaries release tar in OS_LOCAL_RELEASEPATH for the given platform specified by +# argument 1, 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_CORE_RELEASE_TAR +# OS_IMAGE_RELEASE_TAR +os::build::detect_local_release_tars() { + local platform="$1" + + local core=$(find ${OS_LOCAL_RELEASEPATH} -type f -maxdepth 1 -name openshift-origin-core*-${platform}-*) + if [[ $(echo "${core}" | wc -l) -ne 1 ]]; then + echo "There should be exactly one ${platform} core tar in $OS_LOCAL_RELEASEPATH" + exit 2 + fi + + local image=$(find ${OS_LOCAL_RELEASEPATH} -type f -maxdepth 1 -name openshift-origin-image*-${platform}-*) + if [[ $(echo "${image}" | wc -l) -ne 1 ]]; then + echo "There should be exactly one ${platform} image tar in $OS_LOCAL_RELEASEPATH" + exit 3 + fi + + export OS_CORE_RELEASE_TAR="${core}" + export OS_IMAGE_RELEASE_TAR="${image}" +} + # os::build::get_version_vars loads the standard version variables as # ENV vars os::build::get_version_vars() { diff --git a/images/pod/pod.go b/images/pod/pod.go index 7de52e4c562e..fa5f5851b076 100644 --- a/images/pod/pod.go +++ b/images/pod/pod.go @@ -1,4 +1,3 @@ -// +build linux package main import (