From d456b327ce799ce3b62fb9c79f444b25ed52017a Mon Sep 17 00:00:00 2001 From: xiaoyao9184 <6614349+xiaoyao9184@users.noreply.github.com> Date: Fri, 8 Nov 2024 20:00:29 +0800 Subject: [PATCH 1/5] support docker build --- .dockerignore | 19 ++++ .github/workflows/docker-image-tag-commit.yml | 86 +++++++++++++++ .../workflows/docker-image-tag-version.yml | 100 ++++++++++++++++++ docker/build@pypi/dockerfile | 20 ++++ docker/build@source/dockerfile | 17 +++ 5 files changed, 242 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker-image-tag-commit.yml create mode 100644 .github/workflows/docker-image-tag-version.yml create mode 100644 docker/build@pypi/dockerfile create mode 100644 docker/build@source/dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9c35ae7 --- /dev/null +++ b/.dockerignore @@ -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 \ No newline at end of file diff --git a/.github/workflows/docker-image-tag-commit.yml b/.github/workflows/docker-image-tag-commit.yml new file mode 100644 index 0000000..a179de7 --- /dev/null +++ b/.github/workflows/docker-image-tag-commit.yml @@ -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 }} diff --git a/.github/workflows/docker-image-tag-version.yml b/.github/workflows/docker-image-tag-version.yml new file mode 100644 index 0000000..a05f69a --- /dev/null +++ b/.github/workflows/docker-image-tag-version.yml @@ -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 }} diff --git a/docker/build@pypi/dockerfile b/docker/build@pypi/dockerfile new file mode 100644 index 0000000..94e0839 --- /dev/null +++ b/docker/build@pypi/dockerfile @@ -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"] diff --git a/docker/build@source/dockerfile b/docker/build@source/dockerfile new file mode 100644 index 0000000..5bf8b65 --- /dev/null +++ b/docker/build@source/dockerfile @@ -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"] From 4fffc75d6a3ee097ec8f14ab748d93cf862502a0 Mon Sep 17 00:00:00 2001 From: xiaoyao9184 <6614349+xiaoyao9184@users.noreply.github.com> Date: Fri, 8 Nov 2024 21:58:19 +0800 Subject: [PATCH 2/5] docker compose example --- docker/up/configs.toml | 77 ++++++++++++++++++++++++++++++++++++ docker/up/docker-compose.yml | 13 ++++++ docker/up/mirrors/.gitignore | 2 + docker/up/repos/.gitignore | 2 + 4 files changed, 94 insertions(+) create mode 100644 docker/up/configs.toml create mode 100644 docker/up/docker-compose.yml create mode 100644 docker/up/mirrors/.gitignore create mode 100644 docker/up/repos/.gitignore diff --git a/docker/up/configs.toml b/docker/up/configs.toml new file mode 100644 index 0000000..4fb5221 --- /dev/null +++ b/docker/up/configs.toml @@ -0,0 +1,77 @@ +[basic] +host = "0.0.0.0" +port = 8090 +ssl-key = "" +ssl-cert = "" +repos-path = "/data/repos" +cache-size-limit = "" +cache-clean-strategy = "LRU" +hf-scheme = "https" +hf-netloc = "huggingface.co" +hf-lfs-netloc = "cdn-lfs.huggingface.co" +mirror-scheme = "http" +mirror-netloc = "localhost:8090" +mirror-lfs-netloc = "localhost:8090" +mirrors-path = ["/data/mirrors"] + + +[accessibility] +offline = false + + +[[accessibility.proxy]] +repo = "*" +allow = true + +[[accessibility.proxy]] +repo = "*/*" +allow = true + +[[accessibility.proxy]] +repo = "vikp/surya_det3" +allow = false + +# [[accessibility.proxy]] +# repo = "vikp/surya_layout3" +# allow = true + +# [[accessibility.proxy]] +# repo = "vikp/surya_order" +# allow = true + +# [[accessibility.proxy]] +# repo = "vikp/surya_rec2" +# allow = true + +# [[accessibility.proxy]] +# repo = "vikp/surya_tablerec" +# allow = true + + +[[accessibility.cache]] +repo = "*" +allow = true + +[[accessibility.cache]] +repo = "*/*" +allow = true + +[[accessibility.cache]] +repo = "vikp/surya_det3" +allow = false + +# [[accessibility.cache]] +# repo = "vikp/surya_layout3" +# allow = true + +# [[accessibility.cache]] +# repo = "vikp/surya_order" +# allow = true + +# [[accessibility.cache]] +# repo = "vikp/surya_rec2" +# allow = true + +# [[accessibility.cache]] +# repo = "vikp/surya_tablerec" +# allow = true diff --git a/docker/up/docker-compose.yml b/docker/up/docker-compose.yml new file mode 100644 index 0000000..1046021 --- /dev/null +++ b/docker/up/docker-compose.yml @@ -0,0 +1,13 @@ + + +services: + olah: + image: xiaoyao9184/olah:lastet + container_name: olah + command: -c /app/configs.toml + ports: + - 8090:8090 + volumes: + - ./configs.toml:/app/configs.toml + - ./mirrors:/data/mirrors + - ./repos:/data/repos diff --git a/docker/up/mirrors/.gitignore b/docker/up/mirrors/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/docker/up/mirrors/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/docker/up/repos/.gitignore b/docker/up/repos/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/docker/up/repos/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file From ffcb9e5a92458f81910b7edb69c3bdd856c85d42 Mon Sep 17 00:00:00 2001 From: xiaoyao9184 <6614349+xiaoyao9184@users.noreply.github.com> Date: Fri, 8 Nov 2024 21:59:55 +0800 Subject: [PATCH 3/5] conda env file --- environment.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 environment.yml diff --git a/environment.yml b/environment.yml new file mode 100644 index 0000000..44cc2bf --- /dev/null +++ b/environment.yml @@ -0,0 +1,8 @@ +name: olah +channels: + - conda-forge +dependencies: + - python=3.12 + + - pip: + - -e . From 695d44ac8e1718cbfae5ea6d6322597624fb2a3a Mon Sep 17 00:00:00 2001 From: xiaoyao9184 <6614349+xiaoyao9184@users.noreply.github.com> Date: Fri, 8 Nov 2024 22:00:54 +0800 Subject: [PATCH 4/5] vscode task for docker and conda --- .gitignore | 3 ++- .vscode/tasks.json | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 .vscode/tasks.json diff --git a/.gitignore b/.gitignore index 87e4e38..d760c09 100644 --- a/.gitignore +++ b/.gitignore @@ -163,4 +163,5 @@ cython_debug/ /model_dir/ /dataset_dir/ /repos/ -/logs/ \ No newline at end of file +/logs/ +/cache/ diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..923a14f --- /dev/null +++ b/.vscode/tasks.json @@ -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" + ] + } + ] +} \ No newline at end of file From 9a5a996371541d5404485df61766a599e89b8125 Mon Sep 17 00:00:00 2001 From: xiaoyao9184 <6614349+xiaoyao9184@users.noreply.github.com> Date: Fri, 8 Nov 2024 22:01:15 +0800 Subject: [PATCH 5/5] vscode lanuch for debug --- .vscode/launch.json | 14 ++++++++++++++ assets/full_configs.toml | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..fab1c26 --- /dev/null +++ b/.vscode/launch.json @@ -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 + } + ] +} \ No newline at end of file diff --git a/assets/full_configs.toml b/assets/full_configs.toml index 6c0a679..910fe7a 100644 --- a/assets/full_configs.toml +++ b/assets/full_configs.toml @@ -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 @@ -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