diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4353d13b..306e241a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,6 +3,9 @@ on: push: branches: - master + - v* + tags: + - v* pull_request: jobs: build: @@ -21,3 +24,88 @@ jobs: files: ./coverage.out flags: unittests token: ${{ secrets.CODECOV_TOKEN }} + + - name: Upload binaries + uses: actions/upload-artifact@v4 + with: + name: binaries_artifact + path: ./bin/* + + # Calculate sha256 and sha12 checksum + - name: Create sha256 checksum + run: mkdir -p checksum && cd bin && for i in *; do sha256sum -b $i > "../checksum/$i.sha256"; done && cd - + + - name: Create sha512 checksum + run: mkdir -p checksum && cd bin && for i in *; do sha512sum -b $i > "../checksum/$i.sha512"; done && cd - + + # Upload binaries to release + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: '{bin/longhornctl*,checksum/longhornctl*}' + tag: ${{ github.ref }} + overwrite: true + file_glob: true + + build_push_image: + name: Build and push image + runs-on: ubuntu-latest + needs: build + if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Download binaries + uses: actions/download-artifact@v4 + with: + name: binaries_artifact + path: ./bin/ + + - name: Add executable permission + run: | + chmod +x ./bin/* + + - name: Copy bin folder to package + run: | + cp -r ./bin ./package/ + + # 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 + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + # longhornio/longhorn-cli image + - name: docker-publish + if: ${{ startsWith(github.ref, 'refs/heads/') }} + uses: docker/build-push-action@v5 + with: + context: ./ + push: true + platforms: linux/amd64,linux/arm64 + tags: longhornio/longhorn-cli:${{ env.branch }}-head + file: package/Dockerfile + sbom: true + + - name: docker-publish-with-tag + if: ${{ startsWith(github.ref, 'refs/tags/') }} + uses: docker/build-push-action@v5 + with: + context: ./ + push: true + platforms: linux/amd64,linux/arm64 + tags: longhornio/longhorn-cli:${{ github.ref_name }} + file: package/Dockerfile + sbom: true \ No newline at end of file diff --git a/dapper/build b/dapper/build index 0c476349..87ca001d 100755 --- a/dapper/build +++ b/dapper/build @@ -9,15 +9,17 @@ LINKFLAGS="-extldflags -static -s" build_app() { local _dir=$1 local _app=$2 + local _os=$3 + local _arch=$4 cd "${ROOT_DIR}/cmd/${_dir}" [ "$(uname)" != "Darwin" ] && LINKFLAGS="-extldflags -static -s" - CGO_ENABLED=0 go build -ldflags \ + CGO_ENABLED=0 GOARCH=${_arch} GOOS=${_os} go build -ldflags \ "-X github.com/longhorn/cli/meta.Version=$VERSION \ -X github.com/longhorn/cli/meta.GitCommit=$GITCOMMIT \ -X github.com/longhorn/cli/meta.BuildDate=$BUILDDATE \ - $LINKFLAGS" -o ${ROOT_DIR}/bin/${_app} + $LINKFLAGS" -o ${ROOT_DIR}/bin/${_app}-${_os}-${_arch} } source "${ROOT_DIR}/dapper/version" @@ -25,5 +27,9 @@ source "${ROOT_DIR}/dapper/version" mkdir -p "${ROOT_DIR}/bin" echo "Making binary at ${ROOT_DIR}/bin" -build_app local longhornctl-local -build_app remote longhornctl +for os in linux; do + for arch in amd64 arm64; do + build_app local longhornctl-local ${os} ${arch} + build_app remote longhornctl ${os} ${arch} + done +done