From 6fa7f5b3ae9e9a5db895b2c50aac9e746546d649 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Thu, 24 Jan 2019 10:51:14 -0700 Subject: [PATCH] Clean up build scripts Switch binaries to armhf suffix to be more clean on the on architecture --- Dockerfile.dapper | 2 +- Makefile | 5 +++- main.go | 1 + pkg/deploy/zz_generated_bindata.go | 2 +- scripts/build | 2 +- scripts/ci | 4 ++- scripts/dev-server.sh | 2 +- scripts/download | 9 +++++++ scripts/{entry => entry.sh} | 0 scripts/package-cli | 19 ++++++++------- scripts/package-image | 2 +- scripts/release | 3 --- scripts/release-arm | 3 +++ scripts/release.sh | 39 ++++++++++++++++++++++++++++++ scripts/validate | 19 ++++++++++++--- scripts/{version => version.sh} | 0 16 files changed, 90 insertions(+), 22 deletions(-) create mode 100755 scripts/download rename scripts/{entry => entry.sh} (100%) delete mode 100755 scripts/release create mode 100755 scripts/release-arm create mode 100755 scripts/release.sh rename scripts/{version => version.sh} (100%) diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 0e018939ba..21d22fdc07 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -26,6 +26,6 @@ ENV CROSS true ENV STATIC_BUILD true WORKDIR ${DAPPER_SOURCE} -ENTRYPOINT ["./scripts/entry"] +ENTRYPOINT ["./scripts/entry.sh"] CMD ["ci"] diff --git a/Makefile b/Makefile index d7d72a16d5..6c7e7513c7 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -TARGETS := $(shell ls scripts) +TARGETS := $(shell ls scripts | grep -v \\.sh) .dapper: @echo Downloading dapper @@ -18,6 +18,9 @@ trash-keep: .dapper deps: trash +release: + ./scripts/release.sh + .DEFAULT_GOAL := ci .PHONY: $(TARGETS) diff --git a/main.go b/main.go index f423e1fbff..d3f96157e2 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,6 @@ //go:generate go run types/codegen/cleanup/main.go //go:generate go run types/codegen/main.go +//go:generate go fmt pkg/deploy/zz_generated_bindata.go package main diff --git a/pkg/deploy/zz_generated_bindata.go b/pkg/deploy/zz_generated_bindata.go index e334b3a378..37741ed2fd 100644 --- a/pkg/deploy/zz_generated_bindata.go +++ b/pkg/deploy/zz_generated_bindata.go @@ -182,6 +182,7 @@ type bintree struct { Func func() (*asset, error) Children map[string]*bintree } + var _bintree = &bintree{nil, map[string]*bintree{ "coredns.yaml": &bintree{corednsYaml, map[string]*bintree{}}, }} @@ -232,4 +233,3 @@ func _filePath(dir, name string) string { cannonicalName := strings.Replace(name, "\\", "/", -1) return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) } - diff --git a/scripts/build b/scripts/build index 9fe5509c6a..b45045ef89 100755 --- a/scripts/build +++ b/scripts/build @@ -1,7 +1,7 @@ #!/bin/bash set -e -x -source $(dirname $0)/version +source $(dirname $0)/version.sh cd $(dirname $0)/.. diff --git a/scripts/ci b/scripts/ci index 74dcc397db..1d12c4c2a1 100755 --- a/scripts/ci +++ b/scripts/ci @@ -3,6 +3,8 @@ set -e cd $(dirname $0) -./validate +if [ -z "SKIP_VALIDATE" ]; then + ./validate +fi ./build ./package diff --git a/scripts/dev-server.sh b/scripts/dev-server.sh index 59a427ad75..255922f72b 100755 --- a/scripts/dev-server.sh +++ b/scripts/dev-server.sh @@ -5,4 +5,4 @@ mkdir -p $(dirname $0)/../bin cd $(dirname $0)/../bin echo Running -go run -tags "apparmor" ../cmd/server/main.go --debug server --disable-agent +go run -tags "apparmor" ../main.go --debug server --disable-agent diff --git a/scripts/download b/scripts/download new file mode 100755 index 0000000000..1c90eb7355 --- /dev/null +++ b/scripts/download @@ -0,0 +1,9 @@ +#!/bin/bash + +ROOT_VERSION=v0.0.1 + +source $(dirname $0)/version.sh + +cd $(dirname $0)/.. + +curl --compressed -sfL https://github.com/ibuildthecloud/k3s-root/releases/download/${ROOT_VERSION}/k3s-root-${ARCH}.tar | tar xf - diff --git a/scripts/entry b/scripts/entry.sh similarity index 100% rename from scripts/entry rename to scripts/entry.sh diff --git a/scripts/package-cli b/scripts/package-cli index 372efb58ff..28b5098754 100755 --- a/scripts/package-cli +++ b/scripts/package-cli @@ -1,13 +1,11 @@ #!/bin/bash set -e -x -ROOT_VERSION=v0.0.1 - -source $(dirname $0)/version +source $(dirname $0)/version.sh cd $(dirname $0)/.. -curl --compressed -sfL https://github.com/ibuildthecloud/k3s-root/releases/download/${ROOT_VERSION}/k3s-root-${ARCH}.tar | tar xf - +./scripts/download rm -rf bin/kubectl bin/k3s-agent bin/k3s-server bin/kubectl bin/k3s build/data ln -s containerd bin/k3s-agent @@ -21,6 +19,7 @@ for i in bridge flannel host-local loopback portmap; do done +rm -rf build/data mkdir -p build/data tar cvzf ./build/data.tar.gz --exclude ./bin/hyperkube ./bin @@ -28,14 +27,16 @@ HASH=$(sha256sum ./build/data.tar.gz | awk '{print $1}') cp ./build/data.tar.gz ./build/data/${HASH}.tgz +BIN_SUFFIX="-${ARCH}" if [ ${ARCH} = amd64 ]; then - cp -f ./bin/hyperkube dist/hyperkube - CMD_NAME=dist/k3s -else - cp -f ./bin/hyperkube dist/hyperkube-${ARCH} - CMD_NAME=dist/k3s-${ARCH} + BIN_SUFFIX="" +elif [ ${ARCH} = arm ]; then + BIN_SUFFIX="-armhf" fi +cp -f ./bin/hyperkube dist/hyperkube${BIN_SUFFIX} +CMD_NAME=dist/k3s${BIN_SUFFIX} + go generate LDFLAGS="-X github.com/rancher/k3s/version.Version=$VERSION -w -s" STATIC="-extldflags '-static'" diff --git a/scripts/package-image b/scripts/package-image index bb28b9a12d..03dfda2fb1 100755 --- a/scripts/package-image +++ b/scripts/package-image @@ -1,7 +1,7 @@ #!/bin/bash set -e -source $(dirname $0)/version +source $(dirname $0)/version.sh cd $(dirname $0)/../package diff --git a/scripts/release b/scripts/release deleted file mode 100755 index 7af0df35fc..0000000000 --- a/scripts/release +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -exec $(dirname $0)/ci diff --git a/scripts/release-arm b/scripts/release-arm new file mode 100755 index 0000000000..4ff105e692 --- /dev/null +++ b/scripts/release-arm @@ -0,0 +1,3 @@ +#!/bin/bash + +SKIP_VALIDATE=true $(dirname $0)/ci diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000000..0df2489836 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,39 @@ +#!/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/validate b/scripts/validate index 40e5d952ea..4ecfda2ea8 100755 --- a/scripts/validate +++ b/scripts/validate @@ -7,8 +7,14 @@ echo Running validation PACKAGES="$(go list ./...)" -#echo Running: go vet -#go vet ${PACKAGES} +if [ ! -e build/data ];then + mkdir -p build/data +fi + +go generate + +echo Running: go vet +go vet ${PACKAGES} echo Running: gometalinter for i in ${PACKAGES}; do if [ -n "$(gometalinter $i | \ @@ -24,5 +30,12 @@ test -z "$failed" echo Running: go fmt test -z "$(go fmt ${PACKAGES} | \ grep -v 'pkg/data/zz_generated_bindata.go' | \ - grep -v 'pkg/deploy/zz_generated_bindata.go' | \ tee /dev/stderr)" + +. ./scripts/version.sh + +if [ -n "$DIRTY" ]; then + echo Source dir is dirty + git status --porcelain --untracked-files=no + #exit 1 +fi diff --git a/scripts/version b/scripts/version.sh similarity index 100% rename from scripts/version rename to scripts/version.sh