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 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 }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..02edcce --- /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 +CMD ["/usr/bin/cake-cli"] \ No newline at end of file diff --git a/README.md b/README.md index 4ff3f21..db48680 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 --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 + --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 --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 +``` + + ## 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`.