From c824f6eed2bf9f396c9f0b8df93f4a8bcb772bcc Mon Sep 17 00:00:00 2001 From: Gabriele De Rosa Date: Sun, 15 Sep 2024 23:29:02 +0200 Subject: [PATCH 1/6] chore: add dockerfile --- Dockerfile | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3dd2ee2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM rust:bullseye as builder +RUN apt-get update && apt-get install -y libssl-dev ca-certificates cmake git +WORKDIR /app +ADD . /app +RUN cargo build --release + +FROM debian:bullseye +RUN apt-get update && apt-get install -y libssl-dev ca-certificates +COPY --from=builder /app/target/release/cake-cli /usr/bin/cake-cli +COPY --from=builder /app/target/release/cake-split-model /usr/bin/cake-split-model +ENTRYPOINT ["/usr/bin/cake-cli"] \ No newline at end of file From 2474c46b5444c69a5db3e527afdeb71e1655d09f Mon Sep 17 00:00:00 2001 From: Gabriele De Rosa Date: Sun, 15 Sep 2024 23:29:26 +0200 Subject: [PATCH 2/6] chore: copy .gitignore to .dockerignore --- .dockerignore | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5994a40 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,76 @@ +/target +/cake-data +/cake-ios/bindings +/cake-ios-worker-app/Cake.xcframework +/cake-ios-worker-app/Cake\ Worker/Cake.swift + +.DS_Store + +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## Obj-C/Swift specific +*.hmap + +## App packaging +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +# Package.pins +# Package.resolved +# *.xcodeproj +# +# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata +# hence it is not needed unless you have added a package configuration file to your project +# .swiftpm + +.build/ + +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# Pods/ +# +# Add this line if you want to avoid checking in source code from the Xcode workspace +# *.xcworkspace + +# Carthage +# +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build/ + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. +# Instead, use fastlane to re-generate the screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/#source-control + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots/**/*.png +fastlane/test_output + +.idea +/models +/*.sh +.vscode/ +/images From 39cb78e079158097e4d9898fef36056568ee8f4c Mon Sep 17 00:00:00 2001 From: Gabriele De Rosa Date: Sun, 15 Sep 2024 23:47:58 +0200 Subject: [PATCH 3/6] chore: auto-build docker image w/ github actions --- .github/workflows/docker-publish.yml | 96 ++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..79177ad --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,96 @@ +name: Build & Push Docker Image + +on: + # Run build on push for main branch and tagged versions. + push: + # Publish `main` image. + branches: + - main + # Publish `v1.2.3` tags as releases. + tags: + - v* + # Run build test for any PRs. + pull_request: + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # Use github.repository for / + IMAGE_NAME: ${{ github.repository }} + + +jobs: + + # Try to build image. + build: + name: Test Image Build + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Build image + run: | + if [ -f docker-build.yml ]; then + docker compose --file docker-build.yml build + else + docker build . --file Dockerfile + fi + + # Build image and push it to GitHub Packages. + push: + + # Ensure build job passes before pushing image. + needs: build + + name: Build & Push to GitHub Registry + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout + 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 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}}.{{minor}}.{{patch}} + type=raw,value=main,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64,linux/arm64,linux/arm/v7 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} From f8bd3e0e4f988abab65de011c4213296585c0d50 Mon Sep 17 00:00:00 2001 From: Gabriele De Rosa Date: Mon, 16 Sep 2024 13:06:43 +0200 Subject: [PATCH 4/6] fix: use docker cmd to allow also cake-split-model --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3dd2ee2..02edcce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,4 @@ FROM debian:bullseye RUN apt-get update && apt-get install -y libssl-dev ca-certificates COPY --from=builder /app/target/release/cake-cli /usr/bin/cake-cli COPY --from=builder /app/target/release/cake-split-model /usr/bin/cake-split-model -ENTRYPOINT ["/usr/bin/cake-cli"] \ No newline at end of file +CMD ["/usr/bin/cake-cli"] \ No newline at end of file From 11febec4eaddeaac28346a8b3f5b1af82b019a5a Mon Sep 17 00:00:00 2001 From: Gabriele De Rosa Date: Mon, 16 Sep 2024 13:26:08 +0200 Subject: [PATCH 5/6] docs: update README.md w/ new docker commands --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index 4ff3f21..8a6de40 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,37 @@ curl http://master-ip:8080/api/v1/image \ More control arguments could be found [inside the codes](./cake-core/src/lib.rs). +## Using w/ Docker +Splitting the Model: + +```sh +docker run --rm -v /path/to/data:/data ghcr.io/evilsocket/cake \ + cake-split-model --model-path /data/Meta-Llama-3-8B \ # source model to split + --topology /data/topology.yml \ # topology file + --output /data/output-folder-name # output folder +``` + +Run a worker node: + +```sh +docker run --rm -p 10128:10128 -v /path/to/data:/data ghcr.io/evilsocket/cake \ + cake-cli --model /data/Meta-Llama-3-8B \ # model path + --mode worker \ # run as worker + --name worker0 \ # worker name in topology file + --topology /data/topology.yml \ # topology + --address 0.0.0.0:10128 # bind address +``` + +Run a master node with an OpenAI compatible REST API: + +```sh +docker run --rm -p 8080:8080 -v /path/to/data:/data ghcr.io/evilsocket/cake \ + cake-cli --model /data/Meta-Llama-3-8B \ # model path + --api 0.0.0.0:8080 \ # API bind address + --topology /data/topology.yml # topology file +``` + + ## License Released under the GPL 3 license. To see the licenses of the project dependencies, install cargo license with `cargo install cargo-license` and then run `cargo license`. From a4ac80d366f4366e2f4fc02838ef34499dedff07 Mon Sep 17 00:00:00 2001 From: Gabriele De Rosa Date: Mon, 16 Sep 2024 22:21:41 +0200 Subject: [PATCH 6/6] docs: use network host to make setup easier --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8a6de40..db48680 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,7 @@ docker run --rm -v /path/to/data:/data ghcr.io/evilsocket/cake \ Run a worker node: ```sh -docker run --rm -p 10128:10128 -v /path/to/data:/data ghcr.io/evilsocket/cake \ +docker run --rm --network host -v /path/to/data:/data ghcr.io/evilsocket/cake \ cake-cli --model /data/Meta-Llama-3-8B \ # model path --mode worker \ # run as worker --name worker0 \ # worker name in topology file @@ -235,7 +235,7 @@ docker run --rm -p 10128:10128 -v /path/to/data:/data ghcr.io/evilsocket/cake \ Run a master node with an OpenAI compatible REST API: ```sh -docker run --rm -p 8080:8080 -v /path/to/data:/data ghcr.io/evilsocket/cake \ +docker run --rm --network host -v /path/to/data:/data ghcr.io/evilsocket/cake \ cake-cli --model /data/Meta-Llama-3-8B \ # model path --api 0.0.0.0:8080 \ # API bind address --topology /data/topology.yml # topology file