From 4e1f7802db08570702ebbbc0bfa4b82e3b800a78 Mon Sep 17 00:00:00 2001 From: Ben Moss Date: Thu, 1 Nov 2018 16:14:18 -0400 Subject: [PATCH] Split build.sh into two OS-specific scripts --- .travis.yml | 2 +- CONTRIBUTING.md | 4 ++-- build.sh | 47 ---------------------------------------------- build_linux.sh | 32 +++++++++++++++++++++++++++++++ build_windows.sh | 24 +++++++++++++++++++++++ scripts/release.sh | 15 +++++++++++++-- test.sh | 2 +- 7 files changed, 73 insertions(+), 53 deletions(-) delete mode 100755 build.sh create mode 100755 build_linux.sh create mode 100755 build_windows.sh diff --git a/.travis.yml b/.travis.yml index faa133e0..74371f87 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ script: if [ "${TARGET}" == "amd64" ]; then GOARCH="${TARGET}" ./test.sh else - GOARCH="${TARGET}" ./build.sh + GOARCH="${TARGET}" ./build_linux.sh fi notifications: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6254ad02..6bd67e4c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,8 +31,8 @@ are very busy and read the mailing lists. ## Building -Each plugin is compiled simply with `go build`. A script, `build.sh`, -is supplied which will build all the plugins in the repo. +Each plugin is compiled simply with `go build`. Two scripts, `build_linux.sh` and `build_windows.sh`, +are supplied which will build all the plugins for their respective OS. ## Contribution workflow diff --git a/build.sh b/build.sh deleted file mode 100755 index c3ce336d..00000000 --- a/build.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env bash -set -e -cd $(dirname "$0") - -if [ "$(uname)" == "Darwin" ]; then - export GOOS="${GOOS:-linux}" -fi - -ORG_PATH="github.com/containernetworking" -export REPO_PATH="${ORG_PATH}/plugins" - -if [ ! -h gopath/src/${REPO_PATH} ]; then - mkdir -p gopath/src/${ORG_PATH} - ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255 -fi - -export GOPATH=${PWD}/gopath -export GO="${GO:-go}" - -mkdir -p "${PWD}/bin" - -echo "Building plugins ${GOOS}" -if [[ $GOOS == "windows" ]]; then - PLUGINS=$(cat plugins/windows_only.txt) - if [ "$GOARCH" == "amd64" ]; then - for d in $PLUGINS; do - if [ -d "$d" ]; then - plugin="$(basename "$d").exe" - echo " $plugin" - $GO build -o "${PWD}/bin/$plugin" "$@" "$REPO_PATH"/$d - fi - done - else - echo "Could not build windows plugins when GOARCH != amd64" - fi -else - PLUGINS="plugins/meta/* plugins/main/* plugins/ipam/* plugins/sample" - for d in $PLUGINS; do - if [ -d "$d" ]; then - plugin="$(basename "$d")" - if [ $plugin != "windows" ]; then - echo " $plugin" - $GO build -o "${PWD}/bin/$plugin" "$@" "$REPO_PATH"/$d - fi - fi - done -fi diff --git a/build_linux.sh b/build_linux.sh new file mode 100755 index 00000000..ddae34b4 --- /dev/null +++ b/build_linux.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -e +cd $(dirname "$0") + +if [ "$(uname)" == "Darwin" ]; then + export GOOS="${GOOS:-linux}" +fi + +ORG_PATH="github.com/containernetworking" +export REPO_PATH="${ORG_PATH}/plugins" + +if [ ! -h gopath/src/${REPO_PATH} ]; then + mkdir -p gopath/src/${ORG_PATH} + ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255 +fi + +export GOPATH=${PWD}/gopath +export GO="${GO:-go}" + +mkdir -p "${PWD}/bin" + +echo "Building plugins ${GOOS}" +PLUGINS="plugins/meta/* plugins/main/* plugins/ipam/* plugins/sample" +for d in $PLUGINS; do + if [ -d "$d" ]; then + plugin="$(basename "$d")" + if [ $plugin != "windows" ]; then + echo " $plugin" + $GO build -o "${PWD}/bin/$plugin" "$@" "$REPO_PATH"/$d + fi + fi +done diff --git a/build_windows.sh b/build_windows.sh new file mode 100755 index 00000000..02b946f5 --- /dev/null +++ b/build_windows.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -e +cd $(dirname "$0") + +ORG_PATH="github.com/containernetworking" +export REPO_PATH="${ORG_PATH}/plugins" + +if [ ! -h gopath/src/${REPO_PATH} ]; then + mkdir -p gopath/src/${ORG_PATH} + ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255 +fi + +export GOPATH=${PWD}/gopath +export GO="${GO:-go}" +export GOOS=windows + +PLUGINS=$(cat plugins/windows_only.txt) +for d in $PLUGINS; do + if [ -d "$d" ]; then + plugin="$(basename "$d").exe" + echo " $plugin" + $GO build -o "${PWD}/bin/$plugin" "$@" "$REPO_PATH"/$d + fi +done diff --git a/scripts/release.sh b/scripts/release.sh index 0956e9b8..bd59ba0e 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -19,15 +19,26 @@ docker run -v ${SRC_DIR}:/go/src/github.com/containernetworking/plugins --rm gol /bin/sh -xe -c "\ apk --no-cache add bash tar; cd /go/src/github.com/containernetworking/plugins; umask 0022; + for arch in amd64 arm arm64 ppc64le s390x; do \ rm -f ${OUTPUT_DIR}/*; \ - CGO_ENABLED=0 GOARCH=\$arch ./build.sh ${BUILDFLAGS}; \ + CGO_ENABLED=0 GOARCH=\$arch ./build_linux.sh ${BUILDFLAGS}; \ for format in tgz; do \ - FILENAME=cni-plugins-\$arch-${TAG}.\$format; \ + FILENAME=cni-plugins-linux-\$arch-${TAG}.\$format; \ FILEPATH=${RELEASE_DIR}/\$FILENAME; \ tar -C ${OUTPUT_DIR} --owner=0 --group=0 -caf \$FILEPATH .; \ done; \ done; + + rm -rf ${OUTPUT_DIR}/*; \ + CGO_ENABLED=0 GOARCH=amd64 ./build_windows.sh ${BUILDFLAGS}; \ + for format in tgz; do \ + FILENAME=cni-plugins-windows-amd64-${TAG}.\$format; \ + FILEPATH=${RELEASE_DIR}/\$FILENAME; \ + tar -C ${OUTPUT_DIR} --owner=0 --group=0 -caf \$FILEPATH .; \ + done; + + cd ${RELEASE_DIR}; for f in *.tgz; do sha1sum \$f > \$f.sha1; done; for f in *.tgz; do sha256sum \$f > \$f.sha256; done; diff --git a/test.sh b/test.sh index 0c48852d..34b64f80 100755 --- a/test.sh +++ b/test.sh @@ -6,7 +6,7 @@ # set -e -source ./build.sh +source ./build_linux.sh echo "Running tests"