Skip to content

Commit

Permalink
Merge pull request #1835 from thomasferrandiz/update-multi-arch
Browse files Browse the repository at this point in the history
add multi-arch dockerfile and remove mips64le architecture
  • Loading branch information
thomasferrandiz authored Dec 21, 2023
2 parents c051105 + 1d7c5d8 commit aa4fc2b
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 485 deletions.
63 changes: 19 additions & 44 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ on: [push, pull_request]

env:
GO_VERSION: "1.20"
LINUX_ARCHES: "amd64 arm arm64 s390x ppc64le mips64le riscv64"
LINUX_ARCHES: "amd64 arm arm64 s390x ppc64le riscv64"
REPOSITORY: flannel/flannel

jobs:
build-images:
Expand All @@ -14,6 +15,9 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: set tag
run: echo "GIT_TAG=$(git describe --tags --always)" >> $GITHUB_ENV

- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
Expand All @@ -37,51 +41,22 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build Docker image for amd64
uses: docker/build-push-action@v4
with:
context: .
file: images/Dockerfile.amd64
push: false

- name: Build Docker image for arm
uses: docker/build-push-action@v4
with:
context: .
file: images/Dockerfile.arm
push: false

- name: Build Docker image for arm64
uses: docker/build-push-action@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
context: .
file: images/Dockerfile.arm64
push: false

- name: Build Docker image for s390x
uses: docker/build-push-action@v4
with:
context: .
file: images/Dockerfile.s390x
push: false

- name: Build Docker image for ppc64le
uses: docker/build-push-action@v4
with:
context: .
file: images/Dockerfile.ppc64le
push: false

- name: Build Docker image for mips64le
uses: docker/build-push-action@v4
with:
context: .
file: images/Dockerfile.mips64le
push: false
images: ${{ env.REPOSITORY }}
flavor: latest=false
tags: |
type=ref, event=branch
- name: Build Docker image for riscv64
uses: docker/build-push-action@v4
- name: Build and push Docker image
# if: github.repository_owner == 'flannel-io' && success()
uses: docker/build-push-action@v5
with:
context: .
file: images/Dockerfile.riscv64
file: images/Dockerfile
push: false
platforms: linux/amd64,linux/arm64,linux/arm,linux/s390x,linux/ppc64le,linux/riscv64
tags: ${{ steps.meta.outputs.tags }}
build-args: TAG=${{ env.GIT_TAG }}
126 changes: 15 additions & 111 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
name: release flannel and upload docker images

on:
release:
types: [published]

env:
GO_VERSION: "1.20"
LINUX_ARCHES: "amd64 arm arm64 s390x ppc64le mips64le riscv64"
LINUX_ARCHES: "amd64 arm arm64 s390x ppc64le riscv64"
REPOSITORY: flannel/flannel

jobs:
Expand All @@ -18,93 +20,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: go mod vendor
run: go mod vendor

- name: build linux
run: |
set -e
for arch in ${LINUX_ARCHES}; do
echo "Building for arch $arch"
ARCH=$arch make dist/flanneld-$arch
file dist/flanneld-$arch
done
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REPOSITORY }}
flavor: latest=false
tags: |
type=ref,event=tag
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image for amd64
if: github.repository_owner == 'flannel-io'
run: |
docker build -f images/Dockerfile.amd64 -t ${{ steps.meta.outputs.tags }}-amd64 .
docker push ${{ steps.meta.outputs.tags }}-amd64
- name: Build and push Docker image for arm
if: github.repository_owner == 'flannel-io'
run: |
docker build -f images/Dockerfile.arm -t ${{ steps.meta.outputs.tags }}-arm .
docker push ${{ steps.meta.outputs.tags }}-arm
- name: Build and push Docker image for arm64
if: github.repository_owner == 'flannel-io'
run: |
docker build -f images/Dockerfile.arm64 -t ${{ steps.meta.outputs.tags }}-arm64 .
docker push ${{ steps.meta.outputs.tags }}-arm64
- name: Build and push Docker image for s390x
if: github.repository_owner == 'flannel-io'
run: |
docker build -f images/Dockerfile.s390x -t ${{ steps.meta.outputs.tags }}-s390x .
docker push ${{ steps.meta.outputs.tags }}-s390x
- name: Build and push Docker image for ppc64le
if: github.repository_owner == 'flannel-io'
run: |
docker build -f images/Dockerfile.ppc64le -t ${{ steps.meta.outputs.tags }}-ppc64le .
docker push ${{ steps.meta.outputs.tags }}-ppc64le
- name: Build and push Docker image for mips64le
if: github.repository_owner == 'flannel-io'
run: |
docker build -f images/Dockerfile.mips64le -t ${{ steps.meta.outputs.tags }}-mips64le .
docker push ${{ steps.meta.outputs.tags }}-mips64le
- name: Build and push Docker image for riscv64
if: github.repository_owner == 'flannel-io'
run: |
docker build -f images/Dockerfile.riscv64 -t ${{ steps.meta.outputs.tags }}-riscv64 .
docker push ${{ steps.meta.outputs.tags }}-riscv64
build-and-push-multi-arch-image:
needs: [build-and-push-images]
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: set tag
run: echo "GIT_TAG=$(git describe --tags --always)" >> $GITHUB_ENV

- name: Set up Go 1.x
uses: actions/setup-go@v4
Expand Down Expand Up @@ -144,29 +61,16 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Create and push manifest for multi-arch image
if: github.repository_owner == 'flannel-io'
run: |
# get artifacts from previous steps and integrate into one multi-arch manifest
docker pull ${{ steps.meta.outputs.tags }}-amd64
docker pull ${{ steps.meta.outputs.tags }}-arm64
docker pull ${{ steps.meta.outputs.tags }}-arm
docker pull ${{ steps.meta.outputs.tags }}-ppc64le
docker pull ${{ steps.meta.outputs.tags }}-s390x
docker pull ${{ steps.meta.outputs.tags }}-mips64le
docker pull ${{ steps.meta.outputs.tags }}-riscv64
docker manifest create ${{ steps.meta.outputs.tags }} ${{ steps.meta.outputs.tags }}-amd64 ${{ steps.meta.outputs.tags }}-arm64 ${{ steps.meta.outputs.tags }}-arm ${{ steps.meta.outputs.tags }}-ppc64le ${{ steps.meta.outputs.tags }}-s390x ${{ steps.meta.outputs.tags }}-mips64le ${{ steps.meta.outputs.tags }}-riscv64
docker manifest annotate ${{ steps.meta.outputs.tags }} ${{ steps.meta.outputs.tags }}-amd64 --arch amd64
docker manifest annotate ${{ steps.meta.outputs.tags }} ${{ steps.meta.outputs.tags }}-arm64 --arch arm64
docker manifest annotate ${{ steps.meta.outputs.tags }} ${{ steps.meta.outputs.tags }}-arm --arch arm
docker manifest annotate ${{ steps.meta.outputs.tags }} ${{ steps.meta.outputs.tags }}-ppc64le --arch ppc64le
docker manifest annotate ${{ steps.meta.outputs.tags }} ${{ steps.meta.outputs.tags }}-s390x --arch s390x
docker manifest annotate ${{ steps.meta.outputs.tags }} ${{ steps.meta.outputs.tags }}-mips64le --arch mips64le
docker manifest annotate ${{ steps.meta.outputs.tags }} ${{ steps.meta.outputs.tags }}-riscv64 --arch riscv64
docker manifest push ${{ steps.meta.outputs.tags }}
docker pull ${{ steps.meta.outputs.tags }}
docker tag ${{ steps.meta.outputs.tags }} ${{ env.REPOSITORY }}:latest
docker push ${{ env.REPOSITORY }}:latest
- name: Build and push Docker image
if: github.repository_owner == 'flannel-io' && success()
uses: docker/build-push-action@v5
with:
context: .
file: images/Dockerfile
push: true
platforms: linux/amd64,linux/arm64,linux/arm,linux/s390x,linux/ppc64le,linux/riscv64
tags: ${{ steps.meta.outputs.tags }}
build-args: TAG=${{ env.GIT_TAG }}

build-and-push-artifacts:
environment:
Expand Down
24 changes: 8 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dist/flanneld.exe: $(shell find . -type f -name '*.go')

# This will build flannel natively using golang image
dist/flanneld-$(ARCH): deps dist/qemu-$(ARCH)-static
# valid values for ARCH are [amd64 arm arm64 ppc64le s390x mips64le riscv64]
# valid values for ARCH are [amd64 arm arm64 ppc64le s390x riscv64]
docker run --rm -e CGO_ENABLED=$(CGO_ENABLED) -e GOARCH=$(ARCH) -e GOCACHE=/go \
-u $(shell id -u):$(shell id -g) \
-v $(CURDIR)/dist/qemu-$(ARCH)-static:/usr/bin/qemu-$(ARCH)-static \
Expand All @@ -60,12 +60,12 @@ dist/flanneld-$(ARCH): deps dist/qemu-$(ARCH)-static
## Create a docker image on disk for a specific arch and tag
image: dist/flanneld-$(TAG)-$(ARCH).docker
dist/flanneld-$(TAG)-$(ARCH).docker: dist/flanneld-$(ARCH)
docker build -f images/Dockerfile.$(ARCH) -t $(REGISTRY):$(TAG)-$(ARCH) .
docker build -f images/Dockerfile --platform=$(ARCH) --build-arg TAG=$(TAG) -t $(REGISTRY):$(TAG)-$(ARCH) .
docker save -o dist/flanneld-$(TAG)-$(ARCH).docker $(REGISTRY):$(TAG)-$(ARCH)

# amd64 gets an image with the suffix too (i.e. it's the default)
# amd64 gets an image without the suffix too (i.e. it's the default)
ifeq ($(ARCH),amd64)
docker build -f images/Dockerfile.$(ARCH) -t $(REGISTRY):$(TAG) .
docker build -f images/Dockerfile --platform=$(ARCH) --build-arg TAG=$(TAG) -t $(REGISTRY):$(TAG) .
endif

### TESTING
Expand Down Expand Up @@ -144,7 +144,7 @@ dist/flanneld-e2e-$(TAG)-$(ARCH).docker:
ifneq ($(ARCH),amd64)
$(MAKE) dist/qemu-$(ARCH)-static
endif
# valid values for ARCH are [amd64 arm arm64 ppc64le s390x mips64le riscv64]
# valid values for ARCH are [amd64 arm arm64 ppc64le s390x riscv64]
docker run --rm -e GOARM=$(GOARM) -e CGO_ENABLED=$(CGO_ENABLED) -e GOCACHE=/go \
-u $(shell id -u):$(shell id -g) \
-v $(CURDIR):/go/src/github.com/flannel-io/flannel:ro \
Expand All @@ -153,17 +153,16 @@ endif
cd /go/src/github.com/flannel-io/flannel && \
make -e dist/flanneld && \
mv dist/flanneld dist/flanneld-$(ARCH)'
docker build -f images/Dockerfile.$(ARCH) -t $(REGISTRY):$(TAG)-$(ARCH) .
docker build -f images/Dockerfile --platform=$(ARCH) --build-arg TAG=$(TAG) -t $(REGISTRY):$(TAG)-$(ARCH) .

# Make a release after creating a tag
# To build cross platform Docker images, the qemu-static binaries are needed. On ubuntu "apt-get install qemu-user-static"
release: tar.gz dist/qemu-s390x-static dist/qemu-ppc64le-static dist/qemu-arm64-static dist/qemu-arm-static dist/qemu-mips64le-static dist/qemu-riscv64-static release-chart release-helm #release-tests
release: tar.gz dist/qemu-s390x-static dist/qemu-ppc64le-static dist/qemu-arm64-static dist/qemu-arm-static dist/qemu-riscv64-static release-chart release-helm #release-tests
ARCH=amd64 make dist/flanneld-$(TAG)-amd64.docker
ARCH=arm make dist/flanneld-$(TAG)-arm.docker
ARCH=arm64 make dist/flanneld-$(TAG)-arm64.docker
ARCH=ppc64le make dist/flanneld-$(TAG)-ppc64le.docker
ARCH=s390x make dist/flanneld-$(TAG)-s390x.docker
ARCH=mips64le make dist/flanneld-$(TAG)-mips64le.docker
ARCH=riscv64 make dist/flanneld-$(TAG)-riscv64.docker
@echo "Everything should be built for $(TAG)"
@echo "Add all flanneld-* and *.tar.gz files from dist/ to the Github release"
Expand All @@ -188,13 +187,11 @@ dist/qemu-%-static:
wget -O dist/qemu-amd64-static https://github.com/multiarch/qemu-user-static/releases/download/$(QEMU_VERSION)/qemu-x86_64-static; \
elif [ "$(@F)" = "qemu-arm64-static" ]; then \
wget -O dist/qemu-arm64-static https://github.com/multiarch/qemu-user-static/releases/download/$(QEMU_VERSION)/qemu-aarch64-static; \
elif [ "$(@F)" = "qemu-mips64le-static" ]; then \
wget -O dist/qemu-mips64le-static https://github.com/multiarch/qemu-user-static/releases/download/$(QEMU_VERSION)/qemu-mips64el-static; \
else \
wget -O dist/$(@F) https://github.com/multiarch/qemu-user-static/releases/download/$(QEMU_VERSION)/$(@F); \
fi

## Build a .tar.gz for the amd64 ppc64le arm arm64 mips64le riscv64 flanneld binary
## Build a .tar.gz for the amd64 ppc64le arm arm64 riscv64 flanneld binary
tar.gz:
ARCH=amd64 make dist/flanneld-amd64
tar --transform='flags=r;s|-amd64||' -zcvf dist/flannel-$(TAG)-linux-amd64.tar.gz -C dist flanneld-amd64 mk-docker-opts.sh ../README.md
Expand All @@ -214,9 +211,6 @@ tar.gz:
ARCH=s390x make dist/flanneld-s390x
tar --transform='flags=r;s|-s390x||' -zcvf dist/flannel-$(TAG)-linux-s390x.tar.gz -C dist flanneld-s390x mk-docker-opts.sh ../README.md
tar -tvf dist/flannel-$(TAG)-linux-s390x.tar.gz
ARCH=mips64le make dist/flanneld-mips64le
tar --transform='flags=r;s|-mips64le||' -zcvf dist/flannel-$(TAG)-linux-mips64le.tar.gz -C dist flanneld-mips64le mk-docker-opts.sh ../README.md
tar -tvf dist/flannel-$(TAG)-linux-mips64le.tar.gz
ARCH=riscv64 make dist/flanneld-riscv64
tar --transform='flags=r;s|-riscv64||' -zcvf dist/flannel-$(TAG)-linux-riscv64.tar.gz -C dist flanneld-riscv64 mk-docker-opts.sh ../README.md
tar -tvf dist/flannel-$(TAG)-linux-riscv64.tar.gz
Expand Down Expand Up @@ -254,7 +248,6 @@ docker-push-all:
ARCH=arm64 make docker-push docker-manifest-amend
ARCH=ppc64le make docker-push docker-manifest-amend
ARCH=s390x make docker-push docker-manifest-amend
ARCH=mips64le make docker-push docker-manifest-amend
ARCH=riscv64 make docker-push docker-manifest-amend
make docker-manifest-push

Expand All @@ -264,7 +257,6 @@ flannel-git:
ARCH=arm64 REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-arm64.docker docker-push docker-manifest-amend
ARCH=ppc64le REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-ppc64le.docker docker-push docker-manifest-amend
ARCH=s390x REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-s390x.docker docker-push docker-manifest-amend
ARCH=mips64le REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-mips64le.docker docker-push docker-manifest-amend
ARCH=riscv64 REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-riscv64.docker docker-push docker-manifest-amend
REGISTRY=quay.io/coreos/flannel-git make docker-manifest-push

Expand Down
Loading

0 comments on commit aa4fc2b

Please sign in to comment.