diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..c94a49c71 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,239 @@ +name: build +on: + push: + branches: + - master + - v* + tags: + - v* + pull_request: +jobs: + build-amd64-binaries: + name: Build AMD64 binaries + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + # Build binaries + - name: Run make ci + run: make ci + + - uses: codecov/codecov-action@v4 + with: + files: ./coverage.out + flags: unittests + token: ${{ secrets.CODECOV_TOKEN }} + + - name: Upload binaries + uses: actions/upload-artifact@v4 + with: + name: binaries_amd64_artifact + path: ./bin/* + + build-arm64-binaries: + name: Build ARM64 binaries + runs-on: oracle-aarch64-4cpu-16gb + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install make + run: sudo apt-get install make + + # Build binaries + - name: Run make build + run: make build + + - name: Upload binaries + uses: actions/upload-artifact@v4 + with: + name: binaries_arm64_artifact + path: ./bin/* + + build-push-amd64-images: + name: Build and push AMD64 images + runs-on: ubuntu-latest + needs: build-amd64-binaries + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - 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: Download binaries + uses: actions/download-artifact@v4 + with: + name: binaries_amd64_artifact + path: ./bin/ + + - name: Add executable permission + run: | + chmod +x ./bin/* + + - name: Copy bin folder to package + run: | + cp -r ./bin ./package/ + + - name: Login to Docker Hub + uses: docker/login-action@v3 + if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }} + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + # longhornio/longhorn-engine image + - name: docker-build-longhorn-engine + uses: docker/build-push-action@v5 + with: + context: . + push: false + platforms: linux/amd64 + tags: longhornio/longhorn-engine:${{ env.branch }}-head-amd64 + file: package/Dockerfile + build-args: | + ARCH=amd64 + - name: docker-publish-longhorn-engine + if: ${{ startsWith(github.ref, 'refs/heads/') }} + uses: docker/build-push-action@v5 + with: + context: . + push: true + platforms: linux/amd64 + tags: longhornio/longhorn-engine:${{ env.branch }}-head-amd64 + file: package/Dockerfile + build-args: | + ARCH=amd64 + - name: docker-publish-longhorn-engine-with-tag + if: ${{ startsWith(github.ref, 'refs/tags/') }} + uses: docker/build-push-action@v5 + with: + context: . + push: true + platforms: linux/amd64 + tags: longhornio/longhorn-engine:${{ github.ref_name }}-amd64 + file: package/Dockerfile + build-args: | + ARCH=amd64 + + build-push-arm64-images: + name: Build and push ARM64 images + runs-on: oracle-aarch64-4cpu-16gb + needs: build-arm64-binaries + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install make + run: sudo apt-get install make + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Declare branch and sha_short + run: | + echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV" + - name: Download binaries + uses: actions/download-artifact@v4 + with: + name: binaries_arm64_artifact + path: ./bin/ + + - name: Add executable permission + run: | + chmod +x ./bin/* + + - name: Copy bin folder to package + run: | + cp -r ./bin ./package/ + + - name: Login to Docker Hub + if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }} + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + # longhornio/longhorn-engine image + - name: docker-build-longhorn-engine + uses: docker/build-push-action@v5 + with: + context: . + push: false + platforms: linux/arm64 + tags: longhornio/longhorn-engine:${{ env.branch }}-head-arm64 + file: package/Dockerfile + build-args: | + ARCH=arm64 + - name: docker-publish-longhorn-engine + if: ${{ startsWith(github.ref, 'refs/heads/') }} + uses: docker/build-push-action@v5 + with: + context: . + push: true + platforms: linux/arm64 + tags: longhornio/longhorn-engine:${{ env.branch }}-head-arm64 + file: package/Dockerfile + build-args: | + ARCH=arm64 + - name: docker-publish-longhorn-engine-with-tag + if: ${{ startsWith(github.ref, 'refs/tags/') }} + uses: docker/build-push-action@v5 + with: + context: . + push: true + platforms: linux/arm64 + tags: longhornio/longhorn-engine:${{ github.ref_name }}-arm64 + file: package/Dockerfile + build-args: | + ARCH=arm64 + + manifest-image: + name: Manifest images + runs-on: ubuntu-latest + needs: [build-push-amd64-images, build-push-arm64-images] + if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Declare branch and sha_short + run: | + echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV" + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + # longhornio/longhorn-engine image + - name: docker-pull-longhorn-engine + if: ${{ startsWith(github.ref, 'refs/heads/') }} + run: | + docker pull --platform linux/amd64 longhornio/longhorn-engine:${{ env.branch }}-head-amd64 + docker pull --platform linux/arm64 longhornio/longhorn-engine:${{ env.branch }}-head-arm64 + docker buildx imagetools create -t longhornio/longhorn-engine:${{ env.branch }}-head \ + longhornio/longhorn-engine:${{ env.branch }}-head-amd64 \ + longhornio/longhorn-engine:${{ env.branch }}-head-arm64 + - name: docker-pull-longhorn-engine-with-tag + if: ${{ startsWith(github.ref, 'refs/tags/') }} + run: | + docker pull --platform linux/amd64 longhornio/longhorn-engine:${{ github.ref_name }}-amd64 + docker pull --platform linux/arm64 longhornio/longhorn-engine:${{ github.ref_name }}-arm64 + docker buildx imagetools create -t longhornio/longhorn-engine:${{ github.ref_name }} \ + longhornio/longhorn-engine:${{ github.ref_name }}-amd64 \ + longhornio/longhorn-engine:${{ github.ref_name }}-arm64 diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 598ce048c..a3488db85 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -1,6 +1,6 @@ FROM registry.suse.com/bci/bci-base:15.6 -ARG DAPPER_HOST_ARCH=amd64 +ARG DAPPER_HOST_ARCH ARG http_proxy ARG https_proxy ENV HOST_ARCH=${DAPPER_HOST_ARCH} ARCH=${DAPPER_HOST_ARCH} @@ -30,7 +30,7 @@ RUN zypper -n install cmake wget curl git less file gcc python311 python311-pip bash-completion librdmacm1 librdmacm-utils libibverbs xsltproc docbook-xsl-stylesheets \ perl-Config-General libaio-devel glibc-devel-static glibc-devel sg3_utils iptables libltdl7 \ libdevmapper1_03 iproute2 jq unzip zlib-devel zlib-devel-static \ - rpm-build rdma-core-devel gcc-c++ docker && \ + rpm-build rdma-core-devel gcc-c++ docker open-iscsi && \ rm -rf /var/cache/zypp/* # needed for ${!var} substitution @@ -118,7 +118,8 @@ RUN cd /go/src/github.com/longhorn && \ git clone https://github.com/longhorn/longhorn-instance-manager.git && \ cd longhorn-instance-manager && \ go build -o ./longhorn-instance-manager -tags netgo -ldflags "-linkmode external -extldflags -static" && \ - install longhorn-instance-manager /usr/local/bin + install longhorn-instance-manager /usr/local/bin \ + cp longhorn-instance-manager ./bin VOLUME /tmp ENV TMPDIR /tmp diff --git a/package/Dockerfile b/package/Dockerfile index 742466c4f..7b209b7e6 100644 --- a/package/Dockerfile +++ b/package/Dockerfile @@ -53,7 +53,8 @@ COPY --from=builder \ /usr/sbin/tgtimg \ /usr/local/bin/ -COPY bin/longhorn bin/longhorn-instance-manager /usr/local/bin/ +COPY package/bin/longhorn /usr/local/bin/ +COPY package/bin/longhorn-instance-manager /usr/local/bin/ COPY package/launch-simple-longhorn package/engine-manager package/launch-simple-file /usr/local/bin/ diff --git a/scripts/package b/scripts/package index ec3d88263..3e3a43e8d 100755 --- a/scripts/package +++ b/scripts/package @@ -31,6 +31,7 @@ if [ ! -x ./bin/longhorn ]; then fi cp /usr/local/bin/longhorn-instance-manager ./bin/ +cp -r ./bin ./package/ # update base image to get latest changes grep FROM package/Dockerfile | awk '{print $2}' | while read -r BASE_IMAGE