diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index fe8f10ee..00000000 --- a/.drone.yml +++ /dev/null @@ -1,176 +0,0 @@ ---- -kind: pipeline -name: amd64 - -platform: - os: linux - arch: amd64 - -steps: - - name: build - image: rancher/dapper:v0.5.8 - commands: - - dapper ci - volumes: - - name: docker - path: /var/run/docker.sock - - - name: docker-publish-master - image: plugins/docker - settings: - build_args: - - ARCH=amd64 - - VERSION=${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:8}-head - dockerfile: package/Dockerfile - password: - from_secret: docker_password - repo: "rancher/support-bundle-kit" - tag: "${DRONE_BRANCH}-head-amd64" - username: - from_secret: docker_username - when: - ref: - include: - - "refs/heads/master" - - "refs/heads/release/v*" - event: - - push - - - name: docker-publish - image: plugins/docker - settings: - build_args: - - ARCH=amd64 - dockerfile: package/Dockerfile - password: - from_secret: docker_password - repo: "rancher/support-bundle-kit" - tag: "${DRONE_TAG}-amd64" - username: - from_secret: docker_username - when: - instance: - - drone-publish.rancher.io - ref: - - refs/tags/* - event: - - tag - -volumes: - - name: docker - host: - path: /var/run/docker.sock ---- -kind: pipeline -name: arm64 - -platform: - os: linux - arch: arm64 - -steps: - - name: build - image: rancher/dapper:v0.5.8 - commands: - - dapper ci - volumes: - - name: docker - path: /var/run/docker.sock - - - name: docker-publish-master - image: plugins/docker - settings: - build_args: - - ARCH=arm64 - - VERSION=${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:8}-head - dockerfile: package/Dockerfile - password: - from_secret: docker_password - repo: "rancher/support-bundle-kit" - tag: "${DRONE_BRANCH}-head-arm64" - username: - from_secret: docker_username - when: - ref: - include: - - "refs/heads/master" - - "refs/heads/release/v*" - event: - - push - - - name: docker-publish - image: plugins/docker - settings: - build_args: - - ARCH=arm64 - dockerfile: package/Dockerfile - password: - from_secret: docker_password - repo: "rancher/support-bundle-kit" - tag: "${DRONE_TAG}-arm64" - username: - from_secret: docker_username - when: - instance: - - drone-publish.rancher.io - ref: - - refs/tags/* - event: - - tag - -volumes: - - name: docker - host: - path: /var/run/docker.sock ---- -kind: pipeline -name: manifest - -platform: - os: linux - arch: amd64 - -steps: -- name: manifest-master - image: plugins/manifest:1 - settings: - username: - from_secret: docker_username - password: - from_secret: docker_password - platforms: - - linux/amd64 - - linux/arm64 - target: "rancher/support-bundle-kit:${DRONE_BRANCH}-head" - template: "rancher/support-bundle-kit:${DRONE_BRANCH}-head-ARCH" - when: - ref: - include: - - "refs/heads/master" - - "refs/heads/release/v*" - event: - - push - -- name: manifest-tag - image: plugins/manifest:1 - settings: - username: - from_secret: docker_username - password: - from_secret: docker_password - platforms: - - linux/amd64 - - linux/arm64 - target: "rancher/support-bundle-kit:${DRONE_TAG}" - template: "rancher/support-bundle-kit:${DRONE_TAG}-ARCH" - when: - instance: - - drone-publish.rancher.io - ref: - - refs/tags/* - event: - - tag - -depends_on: -- amd64 -- arm64 diff --git a/.github/workflows/template-build.yml b/.github/workflows/template-build.yml index 5220017d..58b99ed8 100644 --- a/.github/workflows/template-build.yml +++ b/.github/workflows/template-build.yml @@ -14,30 +14,10 @@ jobs: permissions: contents: read id-token: write - container: - image: rancher/dapper:v0.5.8 - strategy: - fail-fast: false - matrix: - platform: - - linux/amd64 - - linux/arm64 steps: - # Git is not in Dapper container image. Add it manually for dirty check. - - name: Add Git - run: apk add -U git - - name: Checkout code uses: actions/checkout@v4 - - name: Get Arch - id: get-arch - run: | - arch=$(echo ${{ matrix.platform }} | cut -c 7-) - echo "ARCH=$arch" >> "$GITHUB_OUTPUT" - - - - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -45,7 +25,7 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Run dapper - run: dapper ci + run: make ci - name: Read some Secrets uses: rancher-eio/read-vault-secrets@main @@ -67,43 +47,9 @@ jobs: with: provenance: false context: . - platforms: ${{ matrix.platform }} + platforms: linux/amd64,linux/arm64 file: package/Dockerfile push: ${{ inputs.push }} - tags: rancher/support-bundle-kit:${{ inputs.release-tag-name }}-${{ steps.get-arch.outputs.ARCH }} + tags: rancher/support-bundle-kit:${{ inputs.release-tag-name }} build-args: | - ARCH=${{ steps.get-arch.outputs.ARCH }} - VERSION=${{ github.ref_name }}-${{ github.sha }}-head - - manifest: - if: ${{ inputs.push == true }} - runs-on: ubuntu-latest - permissions: - contents: read - id-token: write - needs: - - dapper-build - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Read some Secrets - uses: rancher-eio/read-vault-secrets@main - with: - secrets: | - secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ; - secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_PASSWORD - - - name: Login to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ env.DOCKER_USERNAME }} - password: ${{ env.DOCKER_PASSWORD }} - - - name: Create Manifest arm64 and amd64 - run: > - docker manifest create rancher/support-bundle-kit:${{ inputs.release-tag-name }} rancher/support-bundle-kit:${{ inputs.release-tag-name }}-amd64 rancher/support-bundle-kit:${{ inputs.release-tag-name }}-arm64 - working-directory: package - - - name: Push Manifest - run: docker manifest push rancher/support-bundle-kit:${{ inputs.release-tag-name }} \ No newline at end of file + VERSION=${{ github.ref_name }}-${{ github.sha }}-head \ No newline at end of file diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 3aec7f7b..0df9b228 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -10,10 +10,15 @@ RUN zypper -n install ca-certificates awk lsb-release rsync docker containerd ## install golangci RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$(go env GOPATH)/bin" v1.55.2; +# The docker version in dapper is too old to have buildx. Install it manually. +RUN curl -sSfL https://github.com/docker/buildx/releases/download/v0.13.1/buildx-v0.13.1.linux-${ARCH} -o buildx-v0.13.1.linux-${ARCH} && \ + chmod +x buildx-v0.13.1.linux-${ARCH} && \ + mv buildx-v0.13.1.linux-${ARCH} /usr/local/bin/buildx + # -- for dapper ENV DAPPER_RUN_ARGS --privileged --network host -v /run/containerd/containerd.sock:/run/containerd/containerd.sock ENV GO111MODULE off -ENV DAPPER_ENV REPO TAG DRONE_TAG CROSS GOPROXY +ENV DAPPER_ENV REPO TAG DRONE_TAG ENV DAPPER_DOCKER_SOCKET true ENV DAPPER_SOURCE /go/src/github.com/rancher/support-bundle-kit/ ENV DAPPER_OUTPUT ./bin ./dist diff --git a/package/Dockerfile b/package/Dockerfile index 1c17a1d5..818690aa 100644 --- a/package/Dockerfile +++ b/package/Dockerfile @@ -1,10 +1,16 @@ FROM registry.suse.com/bci/bci-base:15.5 +ARG TARGETPLATFORM +RUN if [ "$TARGETPLATFORM" != "linux/amd64" ] && [ "$TARGETPLATFORM" != "linux/arm64" ]; then \ + echo "Error: Unsupported TARGETPLATFORM: $TARGETPLATFORM" && \ + exit 1; \ + fi + RUN zypper -n rm container-suseconnect && \ zypper -n install zip curl which tar && \ zypper -n clean -a && rm -rf /tmp/* /var/tmp/* /usr/share/doc/packages/* -ARG ARCH=amd64 +ENV ARCH=${TARGETPLATFORM#linux/} ENV TINI_VERSION v0.19.0 ENV TINI_URL_amd64=https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini \ TINI_URL_arm64=https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-arm64 \ @@ -20,7 +26,7 @@ RUN chmod +x /usr/bin/entrypoint.sh ADD hack/support-bundle-collector.sh /usr/bin RUN chmod +x /usr/bin/support-bundle-collector.sh -ADD bin/support-bundle-kit /usr/bin +ADD bin/support-bundle-kit-${ARCH} /usr/bin/support-bundle-kit RUN chmod +x /usr/bin/support-bundle-kit ADD hack/collector-* /usr/bin/ diff --git a/scripts/build b/scripts/build index 961c77c9..4e18d007 100755 --- a/scripts/build +++ b/scripts/build @@ -10,11 +10,9 @@ fi LINKFLAGS="-X github.com/rancher/support-bundle-kit/cmd.AppVersion=$VERSION -X github.com/rancher/support-bundle-kit/cmd.GitCommit=$COMMIT" -CGO_ENABLED=0 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/support-bundle-kit -if [ "$CROSS" = "true" ] && [ "$ARCH" = "amd64" ]; then - GOOS=darwin go build -ldflags "$LINKFLAGS" -o bin/support-bundle-kit-darwin - GOOS=windows go build -ldflags "$LINKFLAGS" -o bin/support-bundle-kit-windows -fi + +CGO_ENABLED=0 GOARCH=amd64 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/support-bundle-kit-amd64 +CGO_ENABLED=0 GOARCH=arm64 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/support-bundle-kit-arm64 # non-go scripts cp hack/* bin diff --git a/scripts/package b/scripts/package index c488a6dc..54e510b3 100755 --- a/scripts/package +++ b/scripts/package @@ -7,24 +7,24 @@ cd $(dirname $0)/.. mkdir -p dist/artifacts cp bin/* dist/artifacts -mv dist/artifacts/support-bundle-kit dist/artifacts/support-bundle-kit${SUFFIX} - -case $(uname -m) in - aarch64 | arm64) - ARCH=arm64 - ;; - x86_64) - ARCH=amd64 - ;; - s390x) - ARCH=s390x - ;; - *) - echo "$(uname -a): unsupported architecture" - exit 1 -esac IMAGE=${REPO}/support-bundle-kit:${TAG} +DOCKERFILE=package/Dockerfile + +docker run --privileged --rm tonistiigi/binfmt --install all +buildx create --platform linux/amd64,linux/arm64 --use +buildx ls + +# In old docker version, it doesn't support multiple values in --platform with --load. +# So we only load image with current platform. +# Ref: https://github.com/docker/buildx/issues/59#issuecomment-616050491 + +# build +buildx build --platform linux/amd64,linux/arm64 \ + -f ${DOCKERFILE} -t ${IMAGE} . + +# test +buildx build --load \ + -f ${DOCKERFILE} -t ${IMAGE} . -docker build --build-arg ARCH=${ARCH} --no-cache -f package/Dockerfile -t ${IMAGE} . echo Built ${IMAGE} diff --git a/scripts/version b/scripts/version index 1646092e..7d73eeb4 100755 --- a/scripts/version +++ b/scripts/version @@ -13,13 +13,8 @@ else VERSION="${COMMIT}${DIRTY}" fi -if [ -z "$ARCH" ]; then - ARCH=$(go env GOHOSTARCH) -fi - -SUFFIX="-${ARCH}" -TAG=${TAG:-${VERSION}${SUFFIX}} +TAG=${TAG:-${VERSION}} REPO=${REPO:-rancher} if echo $TAG | grep -q dirty; then