diff --git a/.github/workflows/buildTests.yaml b/.github/workflows/buildTests.yaml index eb6ccd1..d223e70 100644 --- a/.github/workflows/buildTests.yaml +++ b/.github/workflows/buildTests.yaml @@ -27,8 +27,8 @@ jobs: for arch in ${LINUX_ARCHES}; do echo "Building for arch $arch" ARCH=$arch make build_linux - file bin/flannel-$arch - rm bin/* + file dist/flannel-$arch + rm dist/* done - name: build windows diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..6914209 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,165 @@ +on: + release: + types: [published] + +env: + GO_VERSION: "1.15.15" + LINUX_ARCHES: "amd64 386 arm arm64 s390x mips64le ppc64le" + REPOSITORY: flannelcni/flannel-cni-plugin + +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 build_linux + file dist/flannel-$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 == 'flannelcni' + 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 == 'flannelcni' + 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 == 'flannelcni' + 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 == 'flannelcni' + 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 == 'flannelcni' + 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 build_linux + file dist/flannel-$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 manifest for multi-arch image + if: github.repository_owner == 'flannelcni' + 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 }} diff --git a/scripts/build_flannel.sh b/scripts/build_flannel.sh index 1bc8256..10836a4 100755 --- a/scripts/build_flannel.sh +++ b/scripts/build_flannel.sh @@ -6,12 +6,12 @@ export GOOS="${GOOS:-linux}" export GOARCH="${GOARCH:-amd64}" export GOFLAGS="${GOFLAGS} -mod=vendor" -mkdir -p "${PWD}/bin" +mkdir -p "${PWD}/dist" echo "Building flannel for ${GOOS} in ${GOARCH}" if [ "$GOOS" == "linux" ]; then - go build -o "${PWD}/bin/flannel-${GOARCH}" "$@" . + go build -o "${PWD}/dist/flannel-${GOARCH}" "$@" . else - go build -o "${PWD}/bin/flannel.exe" "$@" . + go build -o "${PWD}/dist/flannel.exe" "$@" . fi diff --git a/scripts/test_linux.sh b/scripts/test_linux.sh index c4df4b1..23a5d46 100755 --- a/scripts/test_linux.sh +++ b/scripts/test_linux.sh @@ -18,14 +18,14 @@ make build_linux echo "Running tests" function download_cnis { - pushd bin/ + pushd dist/ curl -L https://github.com/containernetworking/plugins/releases/download/$CNI_VERSION/cni-plugins-linux-amd64-$CNI_VERSION.tgz | tar -xz popd } function testrun { download_cnis - sudo -E bash -c "umask 0; PATH=${GOPATH}/bin:$(pwd)/bin:${PATH} go test $@" + sudo -E bash -c "umask 0; PATH=${GOPATH}/dist:$(pwd)/dist:${PATH} go test $@" } COVERALLS=${COVERALLS:-""}