Skip to content

Commit

Permalink
Merge pull request #34 from xiaoyao9184/main
Browse files Browse the repository at this point in the history
support docker image
  • Loading branch information
jstzwj authored Nov 25, 2024
2 parents db028a3 + 9a5a996 commit 994aea9
Show file tree
Hide file tree
Showing 14 changed files with 431 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.git/
.github/
.vscode/
assets/
benchmark/
cache/
docker/
docs/
dist/
logs/
mirrors_dir/
olah.egg-info/
playground/
scripts/
tests/
repos/
.dockerignore
.gitignore
environment.yml
86 changes: 86 additions & 0 deletions .github/workflows/docker-image-tag-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@

name: Docker Image Build/Publish tag with commit

on:
push:
branches:
- 'dev'
paths:
- docker/build@source/dockerfile
- .github/workflows/docker-image-tag-commit.yml
workflow_dispatch:
inputs:
commit_id:
description: olah commit id(like 'main' 'db028a3b')
required: true
default: main

jobs:
build-and-push-docker-image:
name: Build Docker image and push to repositories
runs-on: ubuntu-latest

strategy:
matrix:
BRANCH_CHECKOUT:
- ${{ github.event.inputs.commit_id || 'main' }}
platforms:
- linux/amd64,linux/arm64

steps:
- name: Checkout code
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

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout commit
run: |
git checkout ${{ matrix.BRANCH_CHECKOUT }}
- name: Set env git short head
working-directory: ./olah
run: echo "COMMIT_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV

- name: Meta data image
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.DOCKERHUB_USERNAME }}/olah
ghcr.io/${{ github.repository_owner }}/olah
tags: |
type=raw,value=${{ matrix.BRANCH_CHECKOUT }}
type=raw,value=${{ env.COMMIT_SHORT }}
flavor: |
latest=false
- name: Build push image
id: build
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/build@source/dockerfile
platforms: ${{ matrix.platforms }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Print image digest
run: echo ${{ steps.build.outputs.digest }}
100 changes: 100 additions & 0 deletions .github/workflows/docker-image-tag-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@

name: Docker Image Build/Publish tag with version

on:
push:
tags:
- "v*"
branches:
- 'main'
paths:
- docker/build@pypi/dockerfile
- .github/workflows/docker-image-tag-version.yml
workflow_dispatch:
inputs:
olah_version:
description: olah version of pypi
required: true
default: 0.3.3

jobs:
build-and-push-docker-image:
name: Build Docker image and push to repositories
runs-on: ubuntu-latest

strategy:
matrix:
platform:
- linux/amd64,linux/arm64

steps:
- name: Set OLAH_SOURCE/OLAH_TAG variable for push or workflow_dispatch
id: set_olah_source
run: |
if [[ "${{ github.event_name }}" == "push" ]]; then
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
TAG_NAME=${GITHUB_REF##*/}
VERSION=${TAG_NAME#v}
OLAH_SOURCE="https://github.com/${{ github.repository_owner }}/${{ github.repository }}/releases/download/${TAG_NAME}/olah-${VERSION}-py3-none-any.whl"
OLAH_TAG="${VERSION}"
elif [[ "${{ github.ref }}" == refs/heads/main ]]; then
OLAH_SOURCE="olah"
OLAH_TAG="lastet"
fi
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
OLAH_SOURCE="olah==${{ github.event.inputs.olah_version }}"
OLAH_TAG="${{ github.event.inputs.olah_version }}"
fi
echo "OLAH_SOURCE=$OLAH_SOURCE" >> $GITHUB_ENV
echo "OLAH_TAG=$OLAH_TAG" >> $GITHUB_ENV
- name: Checkout code
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

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Meta data image
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.DOCKERHUB_USERNAME }}/olah
ghcr.io/${{ github.repository_owner }}/olah
tags: |
type=raw,value=${{ env.OLAH_TAG }}
type=raw,value=lastet
flavor: |
latest=false
- name: Build push image
id: build
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/build@pypi/dockerfile
build-args: |
OLAH_SOURCE=${{ env.OLAH_SOURCE }}
platforms: ${{ matrix.platform }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Print image digest
run: echo ${{ steps.build.outputs.digest }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,5 @@ cython_debug/
/model_dir/
/dataset_dir/
/repos/
/logs/
/logs/
/cache/
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "debugpy: server",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/olah/server.py",
"console": "integratedTerminal",
"args": ["-c", "${workspaceFolder}/assets/full_configs.toml"],
"justMyCode": false
}
]
}
53 changes: 53 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "docker: compose up",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/docker/up/"
},
"command": "docker compose -p olah up",
},
{
"label": "docker: build main",
"type": "shell",
"command": "docker build -t xiaoyao9184/olah:main -f ./docker/build@source/dockerfile .",
},
{
"label": "docker: build 0.3.3",
"type": "shell",
"command": "docker build -t xiaoyao9184/olah:0.3.3 -f ./docker/build@pypi/dockerfile .",
},
{
"label": "huggingface-cli: download cais/mmlu",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}",
"env": {
"HF_ENDPOINT": "http://localhost:8090",
"HF_HUB_ETAG_TIMEOUT": "100",
"HF_HUB_DOWNLOAD_TIMEOUT": "100"
}
},
"command": "huggingface-cli download cais/mmlu --repo-type dataset --revision main --cache-dir ./cache/huggingface/hub"
},
{
"label": "conda: run olah-cli",
"type": "shell",
"command": [
"conda run --no-capture-output -n olah olah-cli -c ./assets/full_configs.toml"
],
"problemMatcher": []
},
{
"label": "conda: create env",
"type": "shell",
"command": [
"conda env create -f ./environment.yml"
]
}
]
}
18 changes: 18 additions & 0 deletions assets/full_configs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ mirrors-path = ["./mirrors_dir"]
[accessibility]
offline = false

# allow other or will be in whitelist mode.
[[accessibility.proxy]]
repo = "*"
allow = true

[[accessibility.proxy]]
repo = "*/*"
allow = true

[[accessibility.proxy]]
repo = "cais/mmlu"
allow = true
Expand All @@ -34,6 +43,15 @@ repo = "mistralai/Mistral.*"
allow = false
use_re = true

# allow other or will be in whitelist mode.
[[accessibility.cache]]
repo = "*"
allow = true

[[accessibility.cache]]
repo = "*/*"
allow = true

[[accessibility.cache]]
repo = "cais/mmlu"
allow = true
Expand Down
20 changes: 20 additions & 0 deletions docker/build@pypi/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ARG OLAH_SOURCE=olah==0.3.3

FROM python:3.12

ARG OLAH_SOURCE

WORKDIR /app

RUN pip3 install --upgrade pip

RUN pip install --no-cache-dir ${OLAH_SOURCE}

EXPOSE 8090

VOLUME /data/repos
VOLUME /data/mirrors

ENTRYPOINT [ "olah-cli" ]

CMD ["--repos-path", "/repos"]
17 changes: 17 additions & 0 deletions docker/build@source/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.12

WORKDIR /app

RUN pip3 install --upgrade pip

COPY . /app
RUN pip3 install --no-cache-dir -e .

EXPOSE 8090

VOLUME /data/repos
VOLUME /data/mirrors

ENTRYPOINT [ "olah-cli" ]

CMD ["--repos-path", "/repos"]
Loading

0 comments on commit 994aea9

Please sign in to comment.