Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/hello-openshift/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM scratch
MAINTAINER Jessica Forrester <jforrest@redhat.com>
ADD hello_openshift /hello_openshift
ENTRYPOINT ["/hello_openshift"]
ADD bin/hello-openshift /hello-openshift
ENTRYPOINT ["/hello-openshift"]
7 changes: 0 additions & 7 deletions examples/hello-openshift/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions examples/hello-openshift/bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
Binary file removed examples/hello-openshift/hello_openshift
Binary file not shown.
21 changes: 17 additions & 4 deletions hack/build-cross.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 13 additions & 15 deletions hack/build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---"
Expand Down
22 changes: 9 additions & 13 deletions hack/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
119 changes: 91 additions & 28 deletions hack/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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[@]##*/}")
Expand Down Expand Up @@ -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
Expand All @@ -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
)
}
Expand All @@ -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() {
Expand Down
1 change: 0 additions & 1 deletion images/pod/pod.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// +build linux
package main

import (
Expand Down