Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerize cake #30

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
96 changes: 96 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -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 <account>/<repo>
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 }}
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.