Skip to content

Commit

Permalink
add arm support for sonobuoy (#491)
Browse files Browse the repository at this point in the history
Signed-off-by: Bin Lu <bin.lu@arm.com>
  • Loading branch information
lubinsz authored and liztio committed Jul 26, 2018
1 parent 2729e12 commit 50a6a04
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 13 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.10-alpine
FROM BASEIMAGE
MAINTAINER Timothy St. Clair "tstclair@heptio.com"

RUN apk add --no-cache ca-certificates bash
ADD sonobuoy /sonobuoy
CMD1

ADD BINARY /sonobuoy
ADD scripts/run_master.sh /run_master.sh
ADD scripts/run_single_node_worker.sh /run_single_node_worker.sh
WORKDIR /
Expand Down
82 changes: 72 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
COMMA := $(EMPTY),$(EMPTY)

BINARY = sonobuoy
TARGET = sonobuoy
GOTARGET = github.com/heptio/$(TARGET)
GOPATH = $(shell go env GOPATH)
REGISTRY ?= gcr.io/heptio-images
IMAGE = $(REGISTRY)/$(TARGET)
DIR := ${CURDIR}
DOCKER ?= docker
LINUX_ARCH := amd64 arm64
DOCKERFILE :=
PLATFORMS := $(subst $(SPACE),$(COMMA),$(foreach arch,$(LINUX_ARCH),linux/$(arch)))

GIT_VERSION ?= $(shell git describe --always --dirty)
IMAGE_VERSION ?= $(shell git describe --always --dirty)
Expand All @@ -30,8 +38,6 @@ VERBOSE_FLAG = -v
endif
BUILDMNT = /go/src/$(GOTARGET)
BUILD_IMAGE ?= golang:1.10-alpine
BUILDCMD = CGO_ENABLED=0 go build -o $(TARGET) $(VERBOSE_FLAG) -ldflags "-X github.com/heptio/sonobuoy/pkg/buildinfo.Version=$(GIT_VERSION)"
BUILD = $(BUILDCMD) $(GOTARGET)

TESTARGS ?= $(VERBOSE_FLAG) -timeout 60s
TEST_PKGS ?= $(GOTARGET)/cmd/... $(GOTARGET)/pkg/...
Expand Down Expand Up @@ -71,17 +77,48 @@ lint:
vet:
$(DOCKER_BUILD) '$(VET)'

container: sonobuoy
pre:
go get github.com/estesp/manifest-tool

build_container:
$(DOCKER) build \
-t $(REGISTRY)/$(TARGET):$(IMAGE_VERSION) \
-t $(REGISTRY)/$(TARGET):$(IMAGE_BRANCH) \
-t $(REGISTRY)/$(TARGET):$(GIT_REF) \
-t $(REGISTRY)/$(TARGET):$(IMAGE_VERSION) \
-t $(REGISTRY)/$(TARGET):$(IMAGE_BRANCH) \
-t $(REGISTRY)/$(TARGET):$(GIT_REF) \
-f $(DOCKERFILE) \
.

sonobuoy:
$(DOCKER_BUILD) '$(BUILD)'
container: sonobuoy
for arch in $(LINUX_ARCH); do \
if [ $$arch = amd64 ]; then \
sed -e 's|BASEIMAGE|alpine:3.7|g' \
-e 's|CMD1|RUN apk add --no-cache ca-certificates bash|g' \
-e 's|BINARY|build/linux/amd64/sonobuoy|g' Dockerfile > Dockerfile-$$arch; \
$(MAKE) build_container DOCKERFILE=Dockerfile-$$arch; \
$(MAKE) build_container DOCKERFILE="Dockerfile-$$arch" TARGET="sonobuoy-$$arch"; \
elif [ $$arch = arm64 ]; then \
sed -e 's|BASEIMAGE|arm64v8/ubuntu:16.04|g' \
-e 's|CMD1||g' \
-e 's|BINARY|build/linux/arm64/sonobuoy|g' Dockerfile > Dockerfile-$$arch; \
$(MAKE) build_container DOCKERFILE="Dockerfile-$$arch" TARGET="sonobuoy-$$arch"; \
else \
echo "ARCH unknown"; \
fi \
done

build_sonobuoy:
$(DOCKER_BUILD) 'CGO_ENABLED=0 $(SYSTEM) go build -o $(BINARY) $(VERBOSE_FLAG) -ldflags="-s -w -X github.com/heptio/sonobuoy/pkg/buildinfo.Version=$(GIT_VERSION)" $(GOTARGET)'

push:
sonobuoy:
for arch in $(LINUX_ARCH); do \
mkdir -p build/linux/$$arch; \
echo Building: linux/$$arch; \
$(MAKE) build_sonobuoy SYSTEM="GOOS=linux GOARCH=$$arch" BINARY="build/linux/$$arch/sonobuoy"; \
done
@echo Building: host
make build_sonobuoy

push_images:
$(DOCKER) push $(REGISTRY)/$(TARGET):$(IMAGE_BRANCH)
$(DOCKER) push $(REGISTRY)/$(TARGET):$(GIT_REF)
if git describe --tags --exact-match >/dev/null 2>&1; \
Expand All @@ -91,6 +128,31 @@ push:
$(DOCKER) push $(REGISTRY)/$(TARGET):latest; \
fi

push_manifest:
$(GOPATH)/bin/manifest-tool -username oauth2accesstoken --password "`gcloud auth print-access-token`" push from-args --platforms $(PLATFORMS) --template $(REGISTRY)/$(TARGET)-ARCH:$(VERSION) --target $(REGISTRY)/$(TARGET):$(VERSION)

push: pre container
for arch in $(LINUX_ARCH); do \
$(MAKE) push_images TARGET="sonobuoy-$$arch"; \
done

$(MAKE) push_manifest VERSION=$(IMAGE_BRANCH) TARGET="sonobuoy"
$(MAKE) push_manifest VERSION=$(GIT_REF) TARGET="sonobuoy"

if git describe --tags --exact-match >/dev/null 2>&1; \
then \
$(MAKE) push_manifest VERSION=$(IMAGE_VERSION) TARGET="sonobuoy"; \
$(MAKE) push_manifest VERSION=latest TARGET="sonobuoy"; \
fi

clean_image:
$(DOCKER) rmi -f `$(DOCKER) images $(REGISTRY)/$(TARGET) -a -q` || true

clean:
rm -f $(TARGET)
$(DOCKER) rmi $(REGISTRY)/$(TARGET) || true
rm -f Dockerfile-*
rm -rf build

for arch in $(LINUX_ARCH); do \
$(MAKE) clean_image TARGET=$(TARGET)-$$arch; \
done

0 comments on commit 50a6a04

Please sign in to comment.