Skip to content

Commit

Permalink
feat: docker build
Browse files Browse the repository at this point in the history
Signed-off-by: thxCode <[email protected]>
  • Loading branch information
thxCode committed Jul 30, 2024
1 parent bbeb559 commit 60e193f
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/cmd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ defaults:

on:
push:
branches:
- main
paths-ignore:
- "docs/**"
- "**.md"
- "**.mdx"
- "**.png"
- "**.jpg"
tags:
- "v*.*.*"

Expand All @@ -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
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch
ARG TARGETOS
ARG TARGETARCH
COPY .dist/gguf-parser-${TARGETOS}-${TARGETARCH} /bin/gguf-parser
ENTRYPOINT ["/bin/gguf-parser"]
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 "--- $@ ---"

0 comments on commit 60e193f

Please sign in to comment.