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 multi-arch support including ARM. #241

Merged
merged 1 commit into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 18 additions & 7 deletions .github/workflows/container-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Build container image
run: |
docker build -t aws-efs-csi-driver .
Comment on lines -11 to -13
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need for a separate build step because docker buildx build and push are run at the same step.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The docker buildx build subcommand has a number of flags which determine where the final image will be stored. By default, i.e. if none of the flags are specified, the resulting image will remain captive in docker’s internal build cache. This is unlike the regular docker build command which stores the resulting image in the local docker images list.

--push: This flag tells docker to push the resulting image to a docker registry. This currently is the best way to store multi-architecture images.

https://medium.com/@artur.klauser/building-multi-architecture-docker-images-with-buildx-27d80f7e2408

- name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v3
with:
buildx-version: latest
qemu-version: latest
- name: Push to Github registry
run: |
USER=$(echo $GITHUB_REPOSITORY | cut -d'/' -f1)
Expand All @@ -23,6 +26,7 @@ jobs:
TAG=$BRANCH
fi
docker login docker.pkg.github.com -u $USER -p ${{ secrets.REGISTRY_TOKEN }}
docker build -t aws-efs-csi-driver .
docker tag aws-efs-csi-driver docker.pkg.github.com/$GITHUB_REPOSITORY/$IMAGE:$TAG
docker push docker.pkg.github.com/$GITHUB_REPOSITORY/$IMAGE:$TAG
if [ "$BRANCH" = "master" ]; then
Expand All @@ -40,9 +44,16 @@ jobs:
TAG=$BRANCH
fi
docker login -u ${{ secrets.DOCKERHUB_USER }} -p ${{ secrets.DOCKERHUB_TOKEN }}
docker tag aws-efs-csi-driver $REPO:$TAG
docker push $REPO:$TAG

docker buildx build \
-t $REPO:$TAG \
--platform=linux/amd64,linux/arm64 \
--progress plain \
--push .
Comment on lines +48 to +52
Copy link
Contributor Author

Choose a reason for hiding this comment

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

docker buildx build and push are done as a single step.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The docker buildx build subcommand has a number of flags which determine where the final image will be stored. By default, i.e. if none of the flags are specified, the resulting image will remain captive in docker’s internal build cache. This is unlike the regular docker build command which stores the resulting image in the local docker images list.

--push: This flag tells docker to push the resulting image to a docker registry. This currently is the best way to store multi-architecture images.

https://medium.com/@artur.klauser/building-multi-architecture-docker-images-with-buildx-27d80f7e2408

if [ "$BRANCH" = "master" ]; then
docker tag aws-efs-csi-driver $REPO:master
docker push $REPO:master
docker buildx build \
-t $REPO:master \
--platform=linux/amd64,linux/arm64 \
--progress plain \
--push .
fi
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.13.4-stretch as builder
# Hard-coded platform to `linux/amd64` because
# 1) go mod download is super slow with arm64 on x86 host since it requires QEMU simulation at software level.
# 2) a better approach with `--platform={BUILDPLATFORM}` is only supported by docker buildx not docker build.
FROM --platform=linux/amd64 golang:1.13.4-stretch as builder
WORKDIR /go/src/github.com/kubernetes-sigs/aws-efs-csi-driver

ARG TARGETOS
ARG TARGETARCH
RUN echo "TARGETOS:$TARGETOS, TARGETARCH:$TARGETARCH"
RUN echo "I am running on $(uname -s)/$(uname -m)"

# Cache go modules
ENV GOPROXY=direct
COPY go.mod .
Expand All @@ -27,7 +35,7 @@ ADD . .
ARG client_source=k8s
ENV EFS_CLIENT_SOURCE=$client_source

RUN make aws-efs-csi-driver
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} make aws-efs-csi-driver

FROM amazonlinux:2.0.20200602.0
RUN yum install amazon-efs-utils-1.26-3.amzn2.noarch -y
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ VERSION=v1.0.0-dirty
GIT_COMMIT?=$(shell git rev-parse HEAD)
BUILD_DATE?=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
EFS_CLIENT_SOURCE?=k8s
IMAGE_PLATFORMS?=linux/arm64,linux/amd64
LDFLAGS?="-X ${PKG}/pkg/driver.driverVersion=${VERSION} \
-X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} \
-X ${PKG}/pkg/driver.buildDate=${BUILD_DATE} \
Expand All @@ -32,6 +33,7 @@ GOPATH=$(shell go env GOPATH)
.PHONY: aws-efs-csi-driver
aws-efs-csi-driver:
mkdir -p bin
@echo GOARCH:${GOARCH}
CGO_ENABLED=0 GOOS=linux go build -ldflags ${LDFLAGS} -o bin/aws-efs-csi-driver ./cmd/

build-darwin:
Expand Down Expand Up @@ -60,6 +62,14 @@ test-e2e:
image:
docker build -t $(IMAGE):master .

.PHONY: image-multi-arch--push
image-multi-arch-push:
docker buildx build \
-t $(IMAGE):master \
--platform=$(IMAGE_PLATFORMS) \
--progress plain \
--push .

.PHONY: push
push: image
docker push $(IMAGE):master
Expand Down
1 change: 0 additions & 1 deletion deploy/kubernetes/base/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ spec:
spec:
nodeSelector:
kubernetes.io/os: linux
kubernetes.io/arch: amd64
hostNetwork: true
priorityClassName: system-node-critical
tolerations:
Expand Down