From 74c3a66c5fbd9d034cde7a457edd365051161e5d Mon Sep 17 00:00:00 2001 From: Manuel Buil Date: Wed, 10 Nov 2021 16:14:24 +0100 Subject: [PATCH] Automate the release Signed-off-by: Manuel Buil --- .github/workflows/release.yml | 168 ++++++++++++++++++++++++++++++++++ Dockerfile.arm64 | 2 +- Makefile | 2 +- 3 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..105612826a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,168 @@ +on: + release: + types: [published] + +env: + GO_VERSION: "1.15.15" + LINUX_ARCHES: "amd64 arm arm64 s390x ppc64le" + REPOSITORY: flannelcni/flannel + +jobs: + build-and-push-images: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Go 1.x + uses: actions/setup-go@v2 + 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@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REPOSITORY }} + flavor: latest=false + tags: | + type=ref,event=tag + + - name: Log in to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push Docker image for amd64 + if: github.repository_owner == 'flannel-io' + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile.amd64 + push: true + tags: ${{ steps.meta.outputs.tags }}-amd64 + + - name: Build and push Docker image for arm + if: github.repository_owner == 'flannel-io' + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile.arm + push: true + tags: ${{ steps.meta.outputs.tags }}-arm + + - name: Build and push Docker image for arm64 + if: github.repository_owner == 'flannel-io' + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile.arm64 + push: true + tags: ${{ steps.meta.outputs.tags }}-arm64 + + - name: Build and push Docker image for s390x + if: github.repository_owner == 'flannel-io' + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile.s390x + push: true + tags: ${{ steps.meta.outputs.tags }}-s390x + + - name: Build and push Docker image for ppc64le + if: github.repository_owner == 'flannel-io' + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile.ppc64le + push: true + tags: ${{ steps.meta.outputs.tags }}-ppc64le + + build-and-push-multi-arch-image: + needs: [build-and-push-images] + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Go 1.x + uses: actions/setup-go@v2 + 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@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REPOSITORY }} + flavor: latest=false + tags: | + type=ref,event=tag + + - name: Log in to Docker Hub + uses: docker/login-action@v1 + with: + 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 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 + 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 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 diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 index c3e0f13898..b826c8279b 100644 --- a/Dockerfile.arm64 +++ b/Dockerfile.arm64 @@ -2,7 +2,7 @@ FROM arm64v8/alpine:3.13 ENV FLANNEL_ARCH=arm64 -ADD dist/qemu-aarch64-static /usr/bin/qemu-aarch64-static +ADD dist/qemu-arm64-static /usr/bin/qemu-arm64-static RUN apk add --no-cache iproute2 net-tools ca-certificates iptables strongswan && update-ca-certificates RUN apk add wireguard-tools --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community COPY dist/flanneld-$FLANNEL_ARCH /opt/bin/flanneld diff --git a/Makefile b/Makefile index fe1f78a443..c04816006a 100644 --- a/Makefile +++ b/Makefile @@ -141,7 +141,7 @@ endif # 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-aarch64-static dist/qemu-arm-static #release-tests +release: tar.gz dist/qemu-s390x-static dist/qemu-ppc64le-static dist/qemu-arm64-static dist/qemu-arm-static #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