Skip to content

Commit

Permalink
Merge pull request #1503 from manuelbuil/automate-release
Browse files Browse the repository at this point in the history
Automate the release using github actions
  • Loading branch information
rajatchopra authored Nov 30, 2021
2 parents f0f9b52 + 74c3a66 commit c0f6c85
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 2 deletions.
168 changes: 168 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Dockerfile.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c0f6c85

Please sign in to comment.