From af408da20ab3c73f956b4fb01470b8e267323806 Mon Sep 17 00:00:00 2001 From: Adam Kaplan Date: Fri, 9 Oct 2020 13:56:15 -0400 Subject: [PATCH] Use volume mount in release build - Use bind mount instead of tar stream to add source code to the release container. - Update release Dockerfile to declare volume for the s2i source. Command updated to remove tar stream in - Add sti-version-defs file to .gitignore --- .gitignore | 3 +++ hack/build-release.sh | 21 +++++++-------------- images/release/Dockerfile | 9 +++++---- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index f55f51fda..2dc923f12 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ .vscode/ cmd/s2i/debug *~ + +# Version definition file used in release build +sti-version-defs diff --git a/hack/build-release.sh b/hack/build-release.sh index 868ced67d..fcd420dac 100755 --- a/hack/build-release.sh +++ b/hack/build-release.sh @@ -6,9 +6,10 @@ set -o errexit set -o nounset set -o pipefail +set -e STARTTIME=$(date +%s) -S2I_ROOT=$(dirname "${BASH_SOURCE}")/.. +S2I_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. source "${S2I_ROOT}/hack/common.sh" source "${S2I_ROOT}/hack/util.sh" s2i::log::install_errexit @@ -22,29 +23,21 @@ cd "${S2I_ROOT}" echo "++ Building openshift/sti-release" $buildCmd build -q --tag openshift/sti-release "${S2I_ROOT}/images/release" -context="${S2I_ROOT}/_output/buildenv-context" - # Clean existing output. rm -rf "${S2I_LOCAL_RELEASEPATH}" -rm -rf "${context}" -mkdir -p "${context}" mkdir -p "${S2I_LOCAL_RELEASEPATH}" # Generate version definitions. # You can commit a specific version by specifying S2I_GIT_COMMIT="" prior to build s2i::build::get_version_vars -s2i::build::save_version_vars "${context}/sti-version-defs" +s2i::build::save_version_vars "${S2I_ROOT}/sti-version-defs" echo "++ Building release ${S2I_GIT_VERSION}" -# Create the input archive. -git archive --format=tar -o "${context}/archive.tar" "${S2I_GIT_COMMIT}" -tar -rf "${context}/archive.tar" -C "${context}" sti-version-defs -gzip -f "${context}/archive.tar" - # Perform the build and release in podman or docker. -cat "${context}/archive.tar.gz" | $buildCmd run -i --cidfile="${context}/cid" -e RELEASE_LDFLAGS="-w -s" openshift/sti-release -$buildCmd cp $(cat ${context}/cid):/go/src/github.com/openshift/source-to-image/_output/local/releases "${S2I_OUTPUT}" +$buildCmd run --rm -it -e RELEASE_LDFLAGS="-w -s" \ + -v "${S2I_ROOT}":/go/src/github.com/openshift/source-to-image:z \ + openshift/sti-release echo "${S2I_GIT_COMMIT}" > "${S2I_LOCAL_RELEASEPATH}/.commit" -ret=$?; ENDTIME=$(date +%s); echo "$0 took $(($ENDTIME - $STARTTIME)) seconds"; exit "$ret" +ret=$?; ENDTIME=$(date +%s); echo "$0 took $((ENDTIME - STARTTIME)) seconds"; exit "$ret" diff --git a/images/release/Dockerfile b/images/release/Dockerfile index 313ff08d7..7d292dfa0 100644 --- a/images/release/Dockerfile +++ b/images/release/Dockerfile @@ -15,9 +15,10 @@ ENV PATH=$PATH:$GOROOT/bin:$GOPATH/bin RUN yum install -y gcc zip && \ yum clean all && \ curl https://storage.googleapis.com/golang/go$VERSION.linux-amd64.tar.gz | tar -C /usr/local -xzf - && \ - touch /sti-build-image + touch /sti-build-image && \ + mkdir -p /go/src/github.com/openshift/source-to-image WORKDIR /go/src/github.com/openshift/source-to-image - -# Expect a tar with the source of STI (and /sti-version-defs in the root) -CMD tar mxzf - && hack/build-cross.sh +VOLUME ["/go/src/github.com/openshift/source-to-image"] +# Expect source to be mounted in +CMD ["./hack/build-cross.sh"]