From 10474638d78def323a657ee7e58761e385acee43 Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Tue, 17 Nov 2020 12:21:12 -0800 Subject: [PATCH] Clean up architecture handling * Remove unused release.sh and DAPPER_HOST_ARCH * Reliably use ARCH from version.sh * Export GOARCH and GOARM so that they are used by `go build` Signed-off-by: Brad Davidson --- Dockerfile.dapper | 5 +---- Dockerfile.test.dapper | 19 ++++++++---------- scripts/binary_size_check.sh | 5 ++++- scripts/build | 5 +++-- scripts/release.sh | 39 ------------------------------------ scripts/test | 1 + 6 files changed, 17 insertions(+), 57 deletions(-) delete mode 100755 scripts/release.sh diff --git a/Dockerfile.dapper b/Dockerfile.dapper index fc2ba2d72c..21e9ab0ac7 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -28,10 +28,7 @@ RUN mkdir -p /go/src/golang.org/x && \ go install golang.org/x/tools/cmd/goimports && cd RUN rm -rf /go/src /go/pkg -ARG DAPPER_HOST_ARCH -ENV ARCH $DAPPER_HOST_ARCH - -RUN if [ "${ARCH}" = 'amd64' ]; then \ +RUN if [ "$(go env GOARCH)" = "amd64" ]; then \ curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.30.0; \ fi diff --git a/Dockerfile.test.dapper b/Dockerfile.test.dapper index 421fe312e3..073a33cfbb 100644 --- a/Dockerfile.test.dapper +++ b/Dockerfile.test.dapper @@ -2,19 +2,16 @@ FROM golang:1.15.2-alpine3.12 RUN apk -U --no-cache add bash git gcc musl-dev docker curl jq coreutils python2 openssl -ARG DAPPER_HOST_ARCH -ENV ARCH $DAPPER_HOST_ARCH ENV SONOBUOY_VERSION 0.19.0 -RUN if [ "${ARCH}" == "amd64" ] || [ "${ARCH}" == "arm64" ]; then \ - OS=linux && \ - curl -sL "https://github.com/vmware-tanzu/sonobuoy/releases/download/v${SONOBUOY_VERSION}/sonobuoy_${SONOBUOY_VERSION}_${OS}_${ARCH}.tar.gz" | \ - tar -xzf - -C /usr/local/bin; \ - fi - -RUN curl -sL https://storage.googleapis.com/kubernetes-release/release/$( \ - curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt \ - )/bin/linux/${ARCH}/kubectl -o /usr/local/bin/kubectl && \ +RUN OS=linux; \ + ARCH=$(go env GOARCH); \ + RELEASE=$(curl -fs https://storage.googleapis.com/kubernetes-release/release/stable.txt); \ + if [ "${ARCH}" == "amd64" ] || [ "${ARCH}" == "arm64" ]; then \ + curl -sL "https://github.com/vmware-tanzu/sonobuoy/releases/download/v${SONOBUOY_VERSION}/sonobuoy_${SONOBUOY_VERSION}_${OS}_${ARCH}.tar.gz" | \ + tar -xzf - -C /usr/local/bin; \ + fi; \ + curl -fsL https://storage.googleapis.com/kubernetes-release/release/${RELEASE}/bin/linux/${ARCH}/kubectl -o /usr/local/bin/kubectl; \ chmod a+x /usr/local/bin/kubectl ENV TEST_CLEANUP true diff --git a/scripts/binary_size_check.sh b/scripts/binary_size_check.sh index 5f2268c105..f18fbb7ad3 100755 --- a/scripts/binary_size_check.sh +++ b/scripts/binary_size_check.sh @@ -6,6 +6,8 @@ if [ "${DEBUG}" = 1 ]; then set -x fi +. ./scripts/version.sh + MAX_BINARY_SIZE=61000000 BIN_SUFFIX="-${ARCH}" if [ ${ARCH} = amd64 ]; then @@ -18,8 +20,9 @@ CMD_NAME="dist/artifacts/k3s${BIN_SUFFIX}" SIZE=$(stat -c '%s' ${CMD_NAME}) if [ ${SIZE} -gt ${MAX_BINARY_SIZE} ]; then - echo "k3s binary ${CMD_NAME} size ${SIZE} exceeds acceptable size of ${MAX_BINARY_SIZE}" + echo "k3s binary ${CMD_NAME} size ${SIZE} exceeds max acceptable size of ${MAX_BINARY_SIZE} bytes" exit 1 fi +echo "k3s binary ${CMD_NAME} size ${SIZE} is less than max acceptable size of ${MAX_BINARY_SIZE} bytes" exit 0 diff --git a/scripts/build b/scripts/build index 66416ca627..07a2febf48 100755 --- a/scripts/build +++ b/scripts/build @@ -63,8 +63,9 @@ fi mkdir -p bin -if [ -z "$GOARM" ] && [ "arm" = "$("${GO}" env GOARCH)" ]; then - GOARM=7 +if [ ${ARCH} = armv7l ] || [ ${ARCH} = arm ]; then + export GOARCH="arm" + export GOARM="7" fi rm -f \ diff --git a/scripts/release.sh b/scripts/release.sh deleted file mode 100755 index 0df2489836..0000000000 --- a/scripts/release.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -set -e - -cd $(dirname $0)/.. - -if [ -z "$K3S_ARM64_HOST" ]; then - echo K3S_ARM_HOST must be set - exit 1 -fi - -if [ -z "$K3S_ARM64_HOST_USER" ]; then - echo K3S_ARM_HOST_USER must be set - exit 1 -fi - -if [ -z "$K3S_ARM_HOST" ]; then - K3S_ARM_HOST=${K3S_ARM64_HOST} -fi - -if [ -z "$K3S_ARM_HOST_USER" ]; then - K3S_ARM_HOST_USER=${K3S_ARM64_HOST_USER} -fi - - -rm -rf dist -mkdir -p build -make ci > build/build-amd64.log 2>&1 & -AMD_PID=$! - -DAPPER_HOST_ARCH=arm DOCKER_HOST="ssh://${K3S_ARM_HOST_USER}@${K3S_ARM_HOST}" make release-arm -DAPPER_HOST_ARCH=arm64 DOCKER_HOST="ssh://${K3S_ARM64_HOST_USER}@${K3S_ARM64_HOST}" make release-arm - -echo Waiting for amd64 build to finish -wait -n $AMD_PID || { - cat build/build-amd64.log - exit 1 -} -ls -la dist -echo Done diff --git a/scripts/test b/scripts/test index 795eefc2d7..2a35b9d2e6 100755 --- a/scripts/test +++ b/scripts/test @@ -2,6 +2,7 @@ set -e -x cd $(dirname $0)/.. +. ./scripts/version.sh . ./scripts/test-helpers artifacts=$(pwd)/dist/artifacts