diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 28acfaa..e033cbc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,5 @@ +name: release flannel cni-plugin + on: # You must provide a tag either via the action input or the git ref (i.e push / create a tag). # If you do not provide a tag the action will fail. @@ -13,158 +15,39 @@ on: release: types: - created - push: - tags: - - v1.* env: GO_VERSION: "1.20.5" - LINUX_ARCHES: "amd64 386 arm arm64 s390x mips64le ppc64le" REPOSITORY: flannel/flannel-cni-plugin jobs: - setup-go: + build-and-release: runs-on: ubuntu-latest - permissions: - contents: read - packages: write - strategy: - fail-fast: false - matrix: - go: [ "1.20.5" ] - outputs: - GOPATH: ${{ steps.setup-go.outputs.GOPATH }} - GOROOT: ${{ steps.setup-go.outputs.GOROOT }} - GOCACHE: ${{ steps.setup-go.outputs.GOCACHE }} - GOMODCACHE: ${{ steps.setup-go.outputs.GOMODCACHE }} - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 1 - - uses: actions/setup-go@v3 - id: setup-go - with: - go-version: ${{ matrix.go }} - - name: go mod vendor and tidy - run: make vendor - - uses: actions/cache@v3 - id: cache-go - with: - path: | - {{ outputs.GOPATH }} - {{ outputs.GOMODCACHE }} - {{ outputs.GOCACHE }} - {{ outputs.GOROOT }} - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - build: - needs: setup-go - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - go: [ "1.20.5" ] steps: - uses: actions/checkout@v3 with: fetch-depth: 1 - uses: actions/setup-go@v3 - id: setup-go - if: steps.cache-go.outputs.cache-hit != 'true' with: - go-version: ${{ matrix.go }} + go-version: ${{ env.GO_VERSION }} - name: go mod vendor and tidy - if: steps.cache-go.outputs.cache-hit != 'true' run: make vendor - name: build all binaries for release - if: steps.cache-binaries.outputs.cache-hit != 'true' run: make build_all - # - uses: dominikh/staticcheck-action@v1.0.0 - # with: - # version: "2021.1.2" - # install-go: false - # cache-key: ${{ matrix.go }} - - - name: Cache build binaries - id: cache-binaries - uses: actions/cache@v3 - env: - cache-name: binaries - with: - path: dist - key: ${{ runner.os }}-binaries-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-binaries-${{ env.cache-name }} - ${{ runner.os }}-binaries- - ${{ runner.os }}- - - - test: - needs: [setup-go, build] - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - go: [ "1.20.5" ] - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 1 - - uses: actions/setup-go@v3 - if: steps.cache-go.outputs.cache-hit != 'true' - id: setup-go - with: - go-version: ${{ matrix.go }} - - name: run tests run: make test_linux - name: run go vet run: go vet - package: - needs: [setup-go, build, test] - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - strategy: - fail-fast: true - matrix: - go: [ "1.20.5" ] - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 1 - - uses: actions/setup-go@v3 - id: setup-go - if: steps.cache-go.outputs.cache-hit != 'true' - with: - go-version: ${{ matrix.go }} - - name: create packages for release if: success() run: make release - - name: Cache build tarfiles - id: cache-tarfiles - uses: actions/cache@v3 - env: - cache-name: tarfiles - with: - path: release - key: ${{ runner.os }}-tarfiles-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-tarfiles-${{ env.cache-name }} - ${{ runner.os }}-tarfiles- - ${{ runner.os }}- - - uses: actions/upload-artifact@v3 id: upload-tarfiles with: @@ -177,73 +60,17 @@ jobs: name: flannel-cni-plugin-binaries path: dist/ - release: - needs: [setup-go, build, test, package] - runs-on: ubuntu-latest - strategy: - fail-fast: true - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 1 - - - uses: actions/download-artifact@v3 - with: - name: flannel-cni-plugin-tarfiles - path: ~/release/ - - - uses: actions/download-artifact@v3 - id: download-binaries - with: - name: flannel-cni-plugin-binaries - path: ~/release/ - - - uses: ncipollo/release-action@v1 - id: release-artifacts - if: success() - with: - artifacts: "~/release/*" -# prerelease: true - generateReleaseNotes: true - allowUpdates: true - commit: ${{ github.sha }} - tag: ${{ github.ref_name }} - omitBodyDuringUpdate: true - omitNameDuringUpdate: true - omitPrereleaseDuringUpdate: true - # bodyFile: "body.md" - # token: ${{ secrets.GITHUB_TOKEN }} - - build-and-push-images: - needs: [setup-go, build, test, package, release] + needs: [build-and-release] runs-on: ubuntu-latest permissions: contents: read packages: write - strategy: - fail-fast: true - matrix: - go: [ "1.20.5" ] steps: - name: Checkout repository uses: actions/checkout@v3 if: success() - - uses: actions/setup-go@v3 - id: setup-go - with: - go-version: ${{ matrix.go }} - - - name: go mod vendor - run: go mod vendor - - - name: build linux - run: make build_all_linux_for_images - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 @@ -262,124 +89,12 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build and push Docker image for amd64 - if: github.repository_owner == 'flannel-io' && success() - uses: docker/build-push-action@v4 - 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@v4 + - name: Build and push Docker image + # if: github.repository_owner == 'flannel-io' && success() + uses: docker/build-push-action@v5 with: context: . - file: Dockerfile.arm + file: Dockerfile.image 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@v4 - 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@v4 - 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@v4 - with: - context: . - file: Dockerfile.ppc64le - push: true - tags: ${{ steps.meta.outputs.tags }}-ppc64le - - - name: Build and push Docker image for mips64le - if: github.repository_owner == 'flannel-io' - uses: docker/build-push-action@v4 - with: - context: . - file: Dockerfile.mips64le - push: true - tags: ${{ steps.meta.outputs.tags }}-mips64le - - - build-and-push-multi-arch-image: - needs: [setup-go, build, test, package, release, build-and-push-images] - runs-on: ubuntu-latest - strategy: - fail-fast: true - matrix: - go: [ "1.20.5" ] - steps: - - name: Checkout repository - uses: actions/checkout@v3 - if: success() - - - uses: actions/setup-go@v3 - id: setup-go - with: - go-version: ${{ matrix.go }} - - - name: go mod vendor - run: go mod vendor - - - name: build linux - if: success() - run: make build_all_linux_for_images - - - 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: Create manifest for multi-arch image - if: github.repository_owner == 'flannel-io' && success() && ${{ steps.meta.outputs.tags }} - 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 }}-mips64le - 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 }}-mips64le ${{ 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 }}-mips64le --arch mips64le - 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 + platforms: linux/amd64,linux/arm64,linux/arm,linux/s390x,linux/ppc64le,linux/riscv64 + tags: ${{ steps.meta.outputs.tags }} diff --git a/Dockerfile b/Dockerfile index 7261152..258ca4a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,7 +42,7 @@ RUN go mod vendor && go mod tidy # for ARCH IN ${ALL_ARCH}; do RUN \ - for arch in amd64 386 arm arm64 s390x mips64le ppc64le riscv64; do \ + for arch in amd64 386 arm arm64 s390x ppc64le riscv64; do \ GOARCH=${arch} ./scripts/build_flannel.sh; \ for format in tgz; do \ FILENAME=cni-plugin-flannel-linux-${arch}-${TAG}.${format}; \ @@ -60,7 +60,7 @@ RUN \ done RUN \ - for arch in amd64 386 arm arm64 s390x mips64le ppc64le riscv64; do \ + for arch in amd64 386 arm arm64 s390x ppc64le riscv64; do \ GOARCH=${arch} ./scripts/check_static.sh >> static-check.log; \ done diff --git a/Dockerfile.amd64 b/Dockerfile.amd64 deleted file mode 100644 index c3c574c..0000000 --- a/Dockerfile.amd64 +++ /dev/null @@ -1,2 +0,0 @@ -FROM alpine:3.13 -COPY dist/flannel-amd64 /flannel diff --git a/Dockerfile.arm b/Dockerfile.arm deleted file mode 100644 index 3d6954f..0000000 --- a/Dockerfile.arm +++ /dev/null @@ -1,2 +0,0 @@ -FROM arm32v6/alpine:3.13 -COPY dist/flannel-arm /flannel diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 deleted file mode 100644 index 4bb52b8..0000000 --- a/Dockerfile.arm64 +++ /dev/null @@ -1,2 +0,0 @@ -FROM arm64v8/alpine:3.13 -COPY dist/flannel-arm64 /flannel diff --git a/Dockerfile.image b/Dockerfile.image new file mode 100644 index 0000000..0b9a1bd --- /dev/null +++ b/Dockerfile.image @@ -0,0 +1,22 @@ +FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx + +FROM --platform=$BUILDPLATFORM golang:alpine AS build +# copy xx scripts to your build stage +COPY --from=xx / / +ARG TARGETPLATFORM +ARG BUILDPLATFORM +RUN apk --no-cache add bash +COPY go.mod go.sum *.go /build/ +COPY scripts /build/scripts +WORKDIR /build +RUN xx-info env +RUN go mod tidy && go mod vendor +RUN export GOOS=$(xx-info os) &&\ + export GOARCH=$(xx-info arch) &&\ + ./scripts/build_flannel.sh &&\ + mv ./dist/flannel-${GOARCH} /flannel + +FROM alpine:20230901 +ARG GOARCH +COPY --from=build /flannel /flannel + diff --git a/Dockerfile.linux b/Dockerfile.linux deleted file mode 100644 index bb71487..0000000 --- a/Dockerfile.linux +++ /dev/null @@ -1,7 +0,0 @@ -FROM golang:1.20.5 - -COPY . /go/src -WORKDIR /go/src -RUN go mod vendor && go mod tidy -RUN make build_linux - diff --git a/Dockerfile.mips64le b/Dockerfile.mips64le deleted file mode 100644 index 15cbd8b..0000000 --- a/Dockerfile.mips64le +++ /dev/null @@ -1,2 +0,0 @@ -FROM mips64le/debian:stable-20211220-slim -COPY dist/flannel-mips64le /flannel \ No newline at end of file diff --git a/Dockerfile.ppc64le b/Dockerfile.ppc64le deleted file mode 100644 index 0d18e4c..0000000 --- a/Dockerfile.ppc64le +++ /dev/null @@ -1,2 +0,0 @@ -FROM ppc64le/alpine:3.13 -COPY dist/flannel-ppc64le /flannel diff --git a/Dockerfile.riscv64 b/Dockerfile.riscv64 deleted file mode 100644 index 787e1ba..0000000 --- a/Dockerfile.riscv64 +++ /dev/null @@ -1,2 +0,0 @@ -FROM riscv64/alpine:edge -COPY dist/flannel-riscv64 /flannel diff --git a/Dockerfile.s390x b/Dockerfile.s390x deleted file mode 100644 index 8cb2ab3..0000000 --- a/Dockerfile.s390x +++ /dev/null @@ -1,2 +0,0 @@ -FROM s390x/alpine -COPY dist/flannel-s390x /flannel diff --git a/Dockerfile.windows b/Dockerfile.windows deleted file mode 100644 index 9d9493e..0000000 --- a/Dockerfile.windows +++ /dev/null @@ -1,6 +0,0 @@ -FROM golang:1.20.5 - -COPY . /go/src -WORKDIR /go/src -RUN go mod vendor && go mod tidy -RUN make build_windows diff --git a/Makefile b/Makefile index effff7b..7225049 100644 --- a/Makefile +++ b/Makefile @@ -32,22 +32,9 @@ build_all_linux: vendor GOOS=linux GOARCH=arm scripts/build_flannel.sh GOOS=linux GOARCH=arm64 scripts/build_flannel.sh GOOS=linux GOARCH=s390x scripts/build_flannel.sh - GOOS=linux GOARCH=mips64le scripts/build_flannel.sh GOOS=linux GOARCH=ppc64le scripts/build_flannel.sh GOOS=linux GOARCH=riscv64 scripts/build_flannel.sh - -build_all_linux_for_images: vendor - GOOS=linux GOARCH=amd64 scripts/build_flannel_for_images.sh - GOOS=linux GOARCH=386 scripts/build_flannel_for_images.sh - GOOS=linux GOARCH=arm scripts/build_flannel_for_images.sh - GOOS=linux GOARCH=arm64 scripts/build_flannel_for_images.sh - GOOS=linux GOARCH=s390x scripts/build_flannel_for_images.sh - GOOS=linux GOARCH=mips64le scripts/build_flannel_for_images.sh - GOOS=linux GOARCH=ppc64le scripts/build_flannel_for_images.sh - GOOS=linux GOARCH=riscv64 scripts/build_flannel_for_images.sh - - vendor: go mod tidy go mod vendor diff --git a/scripts/build_flannel_for_images.sh b/scripts/build_flannel_for_images.sh deleted file mode 100755 index ced90bb..0000000 --- a/scripts/build_flannel_for_images.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env bash -set -ex - -cd $(dirname $0)/.. - -source ./scripts/version.sh - -if [ -z "${GODEBUG}" ]; then - EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -w" - DEBUG_GO_GCFLAGS="" - DEBUG_TAGS="" -else - DEBUG_GO_GCFLAGS='-gcflags=all=-N -l' -fi - -BUILDTAGS="netgo osusergo no_stage static_build" -GO_BUILDTAGS="${GO_BUILDTAGS} ${BUILDTAGS} ${DEBUG_TAGS}" -PKG="github.com/flannel-io/cni-plugin" -VENDOR_PREFIX="${PKG}/vendor/" - -VERSION_FLAGS=" - -X main.Version=${VERSION} - -X main.Commit=${COMMIT:0:8} - -X main.Program=${PROG:-flannel} - -X main.buildDate=${BUILD_DATE} -" -# STATIC_FLAGS='-linkmode external -extldflags "-static"' -#STATIC_FLAGS='-extldflags "-static -Wl,--fatal-warnings"' -# shellcheck disable=SC2089 -STATIC_FLAGS='-extldflags "-static"' - -GO_LDFLAGS="${STATIC_FLAGS} ${EXTRA_LDFLAGS}" - -mkdir -p "${PWD}/dist" - -if [ -z ${CGO_ENABLED} ]; then - CGO_ENABLED=${CGO_ENABLED} -else - CGO_ENABLED=0 -fi - -echo "Building flannel for ${GOOS} in ${GOARCH}" -echo "${DEBUG_GO_GCFLAGS}" - -if [ "${GOOS}" = "linux" ]; then - go build \ - -tags "${GO_BUILDTAGS}" \ - ${GO_GCFLAGS} ${GO_BUILD_FLAGS} \ - -o "${PWD}/dist/${PROG}-${GOARCH}" \ - -ldflags "${GO_LDFLAGS} ${VERSION_FLAGS}" \ - ${GO_TAGS} -elif [ "${GOOS}" = "windows" ]; then - go build \ - -tags "${GO_BUILDTAGS}" \ - ${GO_GCFLAGS} ${GO_BUILD_FLAGS} \ - -o "${PWD}/dist/${PROG}-${GOARCH}.exe" \ - -ldflags "${VERSION_FLAGS} ${GO_LDFLAGS}" -else - echo "GOOS:${GOOS} is not yet supported" - echo "Please file a new GitHub issue requesting support for GOOS:${GOOS}" - echo "https://github.com/flannel-io/cni-plugin/issues" - exit 1 -fi diff --git a/scripts/package.sh b/scripts/package.sh index d617d87..a082f2f 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -9,7 +9,7 @@ mkdir -p dist umask 0022 # linux archives -for arch in amd64 386 arm arm64 s390x mips64le ppc64le riscv64; do +for arch in amd64 386 arm arm64 s390x ppc64le riscv64; do echo $arch for format in tgz; do FILENAME=cni-plugin-flannel-linux-$arch-"${TAG}".$format @@ -25,7 +25,7 @@ tar -C "${OUTPUT_DIR}" --owner=0 --group=0 -caf "$FILEPATH" flannel-amd64.exe cd "${SRC_DIR}" # linux -for arch in amd64 386 arm arm64 s390x mips64le ppc64le riscv64; do +for arch in amd64 386 arm arm64 s390x ppc64le riscv64; do GOOS=${GOOS:-$("${GO}" env GOOS)} RELEASE_DIR=release \ OUTPUT_DIR=dist \ diff --git a/scripts/release.sh b/scripts/release.sh index 8a00989..e2aeff8 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -30,7 +30,7 @@ $DOCKER run -ti -v "${SRC_DIR}":z -e TAG="${TAG}" --rm golang:"${GOLANG_VERSION} go mod vendor && go mod tidy - for arch in amd64 386 arm arm64 s390x mips64le ppc64le riscv64; do \ + for arch in amd64 386 arm arm64 s390x ppc64le riscv64; do \ echo \$arch;\ GOARCH=\$arch ./scripts/build_flannel.sh; \ for format in tgz; do \ @@ -47,7 +47,7 @@ $DOCKER run -ti -v "${SRC_DIR}":z -e TAG="${TAG}" --rm golang:"${GOLANG_VERSION} tar -C ${OUTPUT_DIR} --owner=0 --group=0 -caf \$FILEPATH . ; \ done; - for arch in amd64 386 arm arm64 s390x mips64le ppc64le riscv64; do \ + for arch in amd64 386 arm arm64 s390x ppc64le riscv64; do \ GOARCH=\$arch ./scripts/check_static.sh >> static-check.log; \ done;