diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 06734e42..00000000 --- a/.drone.yml +++ /dev/null @@ -1,127 +0,0 @@ ---- -kind: pipeline -name: amd64 - -platform: - os: linux - arch: amd64 - -steps: -- name: build - image: rancher/dapper:v0.5.8 - commands: - - dapper precheck - volumes: - - name: docker - path: /var/run/docker.sock - -- name: stage-binaries - image: rancher/dapper:v0.5.8 - commands: - - "cp -r ./bin/* ./package/" - when: - event: - - push - - tag - -- name: docker-publish-master - image: plugins/docker - settings: - build_args: - - ARCH=amd64 - context: package/ - custom_dns: 1.1.1.1 - dockerfile: package/Dockerfile - password: - from_secret: docker_password - repo: "rancher/terraform-provider-harvester" - tag: ${DRONE_BRANCH}-head-amd64 - username: - from_secret: docker_username - when: - ref: - include: - - "refs/heads/master" - - "refs/heads/v*" - event: - - push - -- name: docker-publish - image: plugins/docker - settings: - build_args: - - ARCH=amd64 - - "VERSION=${DRONE_TAG}" - context: package/ - custom_dns: 1.1.1.1 - dockerfile: package/Dockerfile - password: - from_secret: docker_password - repo: "rancher/terraform-provider-harvester" - tag: "${DRONE_TAG}-amd64" - username: - from_secret: docker_username - when: - instance: - - drone-publish.rancher.io - ref: - - refs/head/master - - 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 - settings: - username: - from_secret: docker_username - password: - from_secret: docker_password - platforms: - - linux/amd64 - target: "rancher/terraform-provider-harvester:${DRONE_BRANCH}-head" - template: "rancher/terraform-provider-harvester:${DRONE_BRANCH}-head-ARCH" - when: - ref: - include: - - "refs/heads/master" - - "refs/heads/v*" - event: - - push - -- name: manifest - image: plugins/manifest - settings: - username: - from_secret: docker_username - password: - from_secret: docker_password - platforms: - - linux/amd64 - target: "rancher/terraform-provider-harvester:${DRONE_TAG}" - template: "rancher/terraform-provider-harvester:${DRONE_TAG}-ARCH" - when: - instance: - - drone-publish.rancher.io - ref: - - refs/head/master - - refs/tags/* - event: - - tag - -depends_on: -- amd64 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ff6aac73..2a2a668f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,46 +9,66 @@ on: pull_request: jobs: build: - name: Build images + name: Build binaries runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + # Build binaries + - name: Run ci + run: make ci + + - name: Upload binaries + uses: actions/upload-artifact@v4 + with: + name: binaries_artifact + path: ./bin/* + + build_push_image: + name: Build and push images + runs-on: ubuntu-latest + needs: build + if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }} permissions: contents: read id-token: write # for reading credential https://github.com/rancher-eio/read-vault-secrets - container: - image: rancher/dapper:v0.6.0 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: Declare branch - run: | - echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV" - # For multi-platform support - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + - name: Download binaries + uses: actions/download-artifact@v4 + with: + name: binaries_artifact + path: ./bin/ - # Build binaries - - name: Run dapper ci - run: dapper ci - - name: Copy bin folder to package + - name: Add executable permission + run: | + chmod +x ./bin/* + + - name: Copy binaries to package run: | cp -r ./bin/* ./package/ - name: Read Secrets - if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }} uses: rancher-eio/read-vault-secrets@main with: secrets: | secret/data/github/repo/${{ github.repository }}/dockerhub/harvester/credentials username | DOCKER_USERNAME ; secret/data/github/repo/${{ github.repository }}/dockerhub/harvester/credentials password | DOCKER_PASSWORD + # For multi-platform support + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Declare branch + run: | + echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV" + - name: Login to Docker Hub - if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }} uses: docker/login-action@v3 with: username: ${{ env.DOCKER_USERNAME }} @@ -64,6 +84,7 @@ jobs: platforms: linux/amd64,linux/arm64 tags: rancher/terraform-provider-harvester:${{ env.branch }}-head file: package/Dockerfile + - name: docker-publish-with-tag if: ${{ startsWith(github.ref, 'refs/tags/') }} uses: docker/build-push-action@v5 diff --git a/package/Dockerfile b/package/Dockerfile index e5a14b33..a790079f 100644 --- a/package/Dockerfile +++ b/package/Dockerfile @@ -1,3 +1,5 @@ +# syntax=docker/dockerfile:1.7.0 + FROM registry.suse.com/bci/bci-base:15.5 ARG TARGETPLATFORM diff --git a/scripts/package b/scripts/package index 4830d4c2..af8e1ebf 100755 --- a/scripts/package +++ b/scripts/package @@ -33,17 +33,6 @@ DOCKERFILE=Dockerfile rm -rf ./terraform-provider-harvester-* cp ../bin/terraform-provider-harvester-* . -docker run --privileged --rm tonistiigi/binfmt --install all -buildx create --platform linux/arm64,linux/amd64 --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 -buildx build \ - --build-arg PROVIDER_VERSION=${PROVIDER_VERSION} \ - --platform linux/amd64,linux/arm64 \ - -f ${DOCKERFILE} -t ${IMAGE} . buildx build --load \ --build-arg PROVIDER_VERSION=${PROVIDER_VERSION} \ -f ${DOCKERFILE} -t ${IMAGE} .