Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Arm Multi-arch Make Logic #36

Merged
merged 4 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Dockerfile-arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2017, 2019 the Velero contributors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright boilerplate should have 2020 as the year.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Year has been updated.

#
# 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
WORKDIR /go/src/github.com/vmware-tanzu/velero-plugin-for-aws
# copy vendor in separately so the layer can be cached if the contents don't change
COPY vendor vendor
COPY velero-plugin-for-aws 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
#RUN mkdir /plugins
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove commented steps in the Dockerfiles.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment removed from both dockerfiles.

COPY --from=build /go/bin/velero-plugin-for-aws /plugins/
USER nobody:nogroup
ENTRYPOINT ["/bin/bash", "-c", "cp /plugins/* /target/."]
27 changes: 27 additions & 0 deletions Dockerfile-arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2017, 2019 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 link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please switch this to golang 1.14?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be done on the other dockerfile too.
Going to clean this in a follow-up PR

WORKDIR /go/src/github.com/vmware-tanzu/velero-plugin-for-aws
# copy vendor in separately so the layer can be cached if the contents don't change
COPY vendor vendor
COPY velero-plugin-for-aws 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 link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the more recent ubuntu:focal instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be done on the other dockerfile too.
Going to clean this in a follow-up PR

#RUN mkdir /plugins
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should ppv64le be uncommented?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ppc64le needs to be removed entirely; it's not supported by Velero itself.


# 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,18 +76,37 @@ test:
# ci is a convenience target for CI builds.
ci: test


# container builds a Docker image containing the binary.
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.
push:
@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 @@ -80,4 +80,4 @@ unset GIT_HTTP_USER_AGENT

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