diff --git a/.github/workflows/cmd.yml b/.github/workflows/cmd.yml index 5eb184b..3cbd94b 100644 --- a/.github/workflows/cmd.yml +++ b/.github/workflows/cmd.yml @@ -11,6 +11,14 @@ defaults: on: push: + branches: + - main + paths-ignore: + - "docs/**" + - "**.md" + - "**.mdx" + - "**.png" + - "**.jpg" tags: - "v*.*.*" @@ -35,10 +43,69 @@ jobs: run: make build env: VERSION: "${{ github.ref_name }}" + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + path: ${{ github.workspace }}/.dist/* - name: Release + if: ${{ startsWith(github.ref, 'refs/tags/') }} uses: softprops/action-gh-release@v2 with: fail_on_unmatched_files: true tag_name: "${{ github.ref_name }}" prerelease: ${{ contains(github.ref, 'rc') }} files: ${{ github.workspace }}/.dist/* + + publish: + needs: + - build + permissions: + contents: write + actions: read + id-token: write + timeout-minutes: 15 + runs-on: ubuntu-22.04 + env: + PACKAGE_REGISTRY: "gpustack" + PACKAGE_IMAGE: "gguf-parser" + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 1 + persist-credentials: false + - name: Setup QEMU + uses: docker/setup-qemu-action@v3 + with: + image: tonistiigi/binfmt:qemu-v7.0.0 + platforms: "arm64" + - name: Setup Buildx + uses: docker/setup-buildx-action@v3 + - name: Login DockerHub + if: ${{ github.event_name != 'pull_request' }} + uses: docker/login-action@v3 + with: + username: ${{ secrets.CI_DOCKERHUB_USERNAME }} + password: ${{ secrets.CI_DOCKERHUB_PASSWORD }} + - name: Download Artifact + uses: actions/download-artifact@v4 + with: + path: ${{ github.workspace }}/.dist + merge-multiple: true + - name: Get Metadata + id: metadata + uses: docker/metadata-action@v5 + with: + images: "${{ env.PACKAGE_REGISTRY }}/${{ env.PACKAGE_IMAGE }}" + - name: Package + uses: docker/build-push-action@v6 + id: package + with: + push: true + file: ${{ github.workspace }}/Dockerfile + context: ${{ github.workspace }} + platforms: "linux/amd64,linux/arm64" + tags: ${{ steps.metadata.outputs.tags }} + labels: ${{ steps.metadata.outputs.labels }} + provenance: true + sbom: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6c75ce8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM scratch +ARG TARGETOS +ARG TARGETARCH +COPY .dist/gguf-parser-${TARGETOS}-${TARGETARCH} /bin/gguf-parser +ENTRYPOINT ["/bin/gguf-parser"] diff --git a/Makefile b/Makefile index 76fa2d5..c9b074d 100644 --- a/Makefile +++ b/Makefile @@ -101,3 +101,31 @@ gguf-parser: ci: deps generate test lint build: gguf-parser + +PACKAGE_PUBLISH ?= false +PACKAGE_REGISTRY ?= "gpustack" +PACKAGE_IMAGE ?= "gguf-parser" +package: build + @echo "+++ $@ +++" + + if [[ -z $$(command -v docker) ]]; then \ + echo "Docker is not installed."; \ + exit 1; \ + fi; \ + platform="linux/amd64,linux/arm64"; \ + image="$(PACKAGE_IMAGE):$(VERSION)"; \ + if [[ -n "$(PACKAGE_REGISTRY)" ]]; then \ + image="$(PACKAGE_REGISTRY)/$$image"; \ + fi; \ + if [[ "$(PACKAGE_PUBLISH)" == "true" ]]; then \ + if [[ -z $$(docker buildx inspect --builder "gguf-parser") ]]; then \ + docker run --rm --privileged tonistiigi/binfmt:qemu-v7.0.0 --install $$platform; \ + docker buildx create --name "gguf-parser" --driver "docker-container" --buildkitd-flags "--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host" --use --bootstrap; \ + fi; \ + docker buildx build --progress=plain --platform=$$platform --builder="gguf-parser" --output="type=image,name=$$image,push=true" "$(SRCDIR)"; \ + else \ + platform="linux/$(GOARCH)"; \ + docker buildx build --progress=plain --platform=$$platform --output="type=docker,name=$$image" "$(SRCDIR)"; \ + fi + + @echo "--- $@ ---"