Skip to content

Commit

Permalink
Added Arm Multi-arch Make Logic (#36)
Browse files Browse the repository at this point in the history
* Added Arm Multi-arch Make Logic

- Added file Dockerfile-arm for building arm 32bit builds
- Added file Dockerfile-arm64 for building arm 64bit builds
- modified Makefile to try and have similar logic to the multi-arch Makefile in the base velero project adding targets all-containers, all-push, manifest, etc. Original targets should continue to work as is.
- updated hack/docker-push to use the new targets to build multi-arch images

Signed-off-by: Chris Lynch <[email protected]>

* Updates to keep arm64 and arm dockerfiles in line with original docker file after 1.1 update

Signed-off-by: Chris Lynch <[email protected]>

* Making changes to dockerfiles requested by review

Signed-off-by: Chris Lynch <[email protected]>
  • Loading branch information
firethestars authored Jul 8, 2020
1 parent a7f2cf1 commit 46c18b3
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 3 deletions.
24 changes: 24 additions & 0 deletions Dockerfile-arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2020 the Velero contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.13-buster AS build
COPY . /go/src/velero-plugin-for-aws
WORKDIR /go/src/velero-plugin-for-aws
RUN GOARCH=arm CGO_ENABLED=0 GOOS=linux go build -v -o /go/bin/velero-plugin-for-aws ./velero-plugin-for-aws


FROM arm32v7/ubuntu:bionic
COPY --from=build /go/bin/velero-plugin-for-aws /plugins/
USER nobody:nogroup
ENTRYPOINT ["/bin/bash", "-c", "cp /plugins/* /target/."]
24 changes: 24 additions & 0 deletions Dockerfile-arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2020 the Velero contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.13-buster AS build
COPY . /go/src/velero-plugin-for-aws
WORKDIR /go/src/velero-plugin-for-aws
RUN GOARCH=arm64 CGO_ENABLED=0 GOOS=linux go build -v -o /go/bin/velero-plugin-for-aws ./velero-plugin-for-aws


FROM arm64v8/ubuntu:bionic
COPY --from=build /go/bin/velero-plugin-for-aws /plugins/
USER nobody:nogroup
ENTRYPOINT ["/bin/bash", "-c", "cp /plugins/* /target/."]
55 changes: 53 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ PKG := github.com/vmware-tanzu/velero-plugin-for-aws
BIN := velero-plugin-for-aws

REGISTRY ?= velero
IMAGE ?= $(REGISTRY)/velero-plugin-for-aws
VERSION ?= master

CONTAINER_PLATFORMS ?= amd64 arm arm64 # ppc64le

# Which architecture to build.
# if the 'local' rule is being run, detect the GOOS/GOARCH from 'go env'
# if it wasn't specified by the caller.
Expand All @@ -28,6 +29,37 @@ GOOS ?= linux
local: GOARCH ?= $(shell go env GOARCH)
GOARCH ?= amd64

# Set default base image dynamically for each arch
ifeq ($(GOARCH),amd64)
DOCKERFILE ?= Dockerfile
endif
ifeq ($(GOARCH),arm)
DOCKERFILE ?= Dockerfile-arm
endif
ifeq ($(GOARCH),arm64)
DOCKERFILE ?= Dockerfile-arm64
endif


MULTIARCH_IMAGE = $(REGISTRY)/$(BIN)
IMAGE ?= $(REGISTRY)/$(BIN)-$(GOARCH)

# If you want to build all containers, see the 'all-containers' rule.
# If you want to build AND push all containers, see the 'all-push' rule.

container-%:
@$(MAKE) --no-print-directory GOARCH=$* container

push-%:
@$(MAKE) --no-print-directory GOARCH=$* push

all-containers: $(addprefix container-, $(CONTAINER_PLATFORMS))

all-push: $(addprefix push-, $(CONTAINER_PLATFORMS))

all-manifests:
@$(MAKE) manifest

# local builds the binary using 'go build' in the local environment.
local: build-dirs
GOOS=$(GOOS) \
Expand All @@ -44,20 +76,39 @@ test:
# ci is a convenience target for CI builds.
ci: verify-modules test


# container builds a Docker image containing the binary.
.PHONY: container
container:
docker build -t $(IMAGE):$(VERSION) .
docker build -t $(IMAGE):$(VERSION) -f $(DOCKERFILE) .
@echo "container: $(IMAGE):$(VERSION)"


# push pushes the Docker image to its registry.
.PHONY: push
push: container
@docker push $(IMAGE):$(VERSION)
@echo "pushed: $(IMAGE):$(VERSION)"
ifeq ($(TAG_LATEST), true)
docker tag $(IMAGE):$(VERSION) $(IMAGE):latest
docker push $(IMAGE):latest
@echo "pushed: $(IMAGE):latest"
endif


manifest:
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create $(MULTIARCH_IMAGE):$(VERSION) \
$(foreach arch, $(CONTAINER_PLATFORMS), $(MULTIARCH_IMAGE)-$(arch):$(VERSION))
@DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push --purge $(MULTIARCH_IMAGE):$(VERSION)
@echo "pushed: $(MULTIARCH_IMAGE):$(VERSION)"
ifeq ($(TAG_LATEST), true)
@DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create $(MULTIARCH_IMAGE):latest \
$(foreach arch, $(CONTAINER_PLATFORMS), $(MULTIARCH_IMAGE)-$(arch):latest)
@DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push --purge $(MULTIARCH_IMAGE):latest
@echo "pushed: $(MULTIARCH_IMAGE):latest)"
endif


# build-dirs creates the necessary directories for a build in the local environment.
build-dirs:
@mkdir -p _output
Expand Down
2 changes: 1 addition & 1 deletion hack/docker-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ echo "TAG_LATEST: $TAG_LATEST"

echo "Building and pushing container images."

VERSION="$VERSION" TAG_LATEST="$TAG_LATEST" make container push
VERSION="$VERSION" TAG_LATEST="$TAG_LATEST" make all-containers all-push manifest

0 comments on commit 46c18b3

Please sign in to comment.