├── .github └── workflows │ ├── CD-docker_dev.yml │ ├── CD-docker_release.yml │ ├── CI-runpod_dep.yml │ └── CI-test_worker.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── builder ├── requirements.txt └── setup.sh └── src └── handler.py /.github/workflows/CD-docker_dev.yml: -------------------------------------------------------------------------------- 1 | name: CD | Dev Docker Image 2 | 3 | on: 4 | push: 5 | branches-ignore: 6 | - "refs/tags/*" 7 | 8 | jobs: 9 | docker: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Clear Space 13 | run: | 14 | rm -rf /usr/share/dotnet 15 | rm -rf /opt/ghc 16 | rm -rf "/usr/local/share/boost" 17 | rm -rf "$AGENT_TOOLSDIRECTORY" 18 | 19 | - name: Set up QEMU 20 | uses: docker/setup-qemu-action@v2 21 | 22 | - name: Set up Docker Buildx 23 | uses: docker/setup-buildx-action@v2 24 | 25 | - name: Login to Docker Hub 26 | uses: docker/login-action@v2 27 | with: 28 | username: ${{ secrets.DOCKERHUB_USERNAME }} 29 | password: ${{ secrets.DOCKERHUB_TOKEN }} 30 | 31 | - name: Determine Docker tag 32 | id: docker-tag 33 | run: | 34 | if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then 35 | echo "DOCKER_TAG=dev" >> $GITHUB_ENV 36 | else 37 | echo "DOCKER_TAG=${{ github.sha }}" >> $GITHUB_ENV 38 | fi 39 | 40 | - name: Build and push 41 | uses: docker/build-push-action@v4 42 | with: 43 | push: true 44 | tags: ${{ vars.DOCKERHUB_REPO }}/${{ vars.DOCKERHUB_IMG }}:${{ env.DOCKER_TAG }} 45 | -------------------------------------------------------------------------------- /.github/workflows/CD-docker_release.yml: -------------------------------------------------------------------------------- 1 | name: CD | Release Docker Image 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | docker: 9 | runs-on: DO 10 | steps: 11 | - name: Clear Space 12 | run: | 13 | rm -rf /usr/share/dotnet 14 | rm -rf /opt/ghc 15 | rm -rf "/usr/local/share/boost" 16 | rm -rf "$AGENT_TOOLSDIRECTORY" 17 | 18 | - name: Set up QEMU 19 | uses: docker/setup-qemu-action@v2 20 | 21 | - name: Set up Docker Buildx 22 | uses: docker/setup-buildx-action@v2 23 | 24 | - name: Login to Docker Hub 25 | uses: docker/login-action@v2 26 | with: 27 | username: ${{ secrets.DOCKERHUB_USERNAME }} 28 | password: ${{ secrets.DOCKERHUB_TOKEN }} 29 | 30 | - name: Build and push 31 | uses: docker/build-push-action@v4 32 | with: 33 | push: true 34 | tags: ${{ vars.DOCKERHUB_REPO }}/${{ vars.DOCKERHUB_IMG }}:${{ github.event.release.tag_name }} 35 | -------------------------------------------------------------------------------- /.github/workflows/CI-runpod_dep.yml: -------------------------------------------------------------------------------- 1 | name: CI | Update runpod package version 2 | 3 | on: 4 | repository_dispatch: 5 | types: [python-package-release] 6 | 7 | push: 8 | branches: ["main"] 9 | 10 | workflow_dispatch: 11 | 12 | jobs: 13 | check_dep: 14 | runs-on: ubuntu-latest 15 | name: Check python requirements file and update 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v2 19 | 20 | - name: Check for new package version and update 21 | run: | 22 | # Get current version 23 | current_version=$(grep -oP 'runpod==\K[^"]+' ./builder/requirements.txt) 24 | 25 | # Get new version 26 | new_version=$(curl -s https://pypi.org/pypi/runpod/json | jq -r .info.version) 27 | echo "NEW_VERSION_ENV=$new_version" >> $GITHUB_ENV 28 | 29 | if [ -z "$new_version" ]; then 30 | echo "Failed to fetch the new version." 31 | exit 1 32 | fi 33 | 34 | # Check if the version is already up-to-date 35 | if [ "$current_version" = "$new_version" ]; then 36 | echo "The package version is already up-to-date." 37 | exit 0 38 | fi 39 | 40 | # Update requirements.txt 41 | sed -i "s/runpod==.*/runpod==$new_version/" ./builder/requirements.txt 42 | 43 | - name: Create Pull Request 44 | uses: peter-evans/create-pull-request@v3 45 | with: 46 | token: ${{ secrets.GITHUB_TOKEN }} 47 | commit-message: Update package version 48 | title: Update runpod package version 49 | body: The package version has been updated to ${{ env.NEW_VERSION_ENV }} 50 | branch: runpod-package-update 51 | -------------------------------------------------------------------------------- /.github/workflows/CI-test_worker.yml: -------------------------------------------------------------------------------- 1 | name: CI | Test Worker 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | pull_request: 9 | branches: 10 | - main 11 | 12 | workflow_dispatch: 13 | 14 | jobs: 15 | initialize_worker: 16 | runs-on: ubuntu-latest 17 | outputs: 18 | id: ${{ steps.extract_id.outputs.runpod_job_id }} 19 | 20 | steps: 21 | - name: Deploy Worker 22 | id: deploy 23 | uses: fjogeleit/http-request-action@v1 24 | with: 25 | url: "https://api.runpod.ai/v2/${{ vars.RUNNER_24GB }}/run" 26 | method: "POST" 27 | customHeaders: '{"Content-Type": "application/json"}' 28 | bearerToken: ${{ secrets.RUNPOD_API_KEY }} 29 | data: '{"input":{"github_pat": "${{ secrets.GH_PAT }}", "github_org":"${{ secrets.GH_ORG }}"}}' 30 | 31 | - name: Extract Job ID 32 | id: extract_id 33 | run: | 34 | ID=$(echo '${{ steps.deploy.outputs.response }}' | jq -r '.id') 35 | echo "::set-output name=runpod_job_id::$ID" 36 | 37 | run_tests: 38 | needs: initialize_worker 39 | runs-on: runpod 40 | 41 | steps: 42 | - uses: actions/checkout@v3 43 | 44 | - name: Set up Python 3.11 & install dependencies 45 | uses: actions/setup-python@v4 46 | with: 47 | python-version: "3.11" 48 | 49 | - name: Install Dependencies 50 | run: | 51 | python -m pip install --upgrade pip 52 | pip install -r builder/requirements.txt 53 | 54 | - name: Execute Tests 55 | run: | 56 | python src/handler.py --test_input='{"input": "test"}' 57 | 58 | terminate_worker: 59 | if: ${{ always() && !success() }} 60 | needs: initialize_worker 61 | runs-on: ubuntu-latest 62 | 63 | steps: 64 | - name: Shutdown Worker 65 | uses: fjogeleit/http-request-action@v1 66 | with: 67 | url: "https://api.runpod.ai/v2/${{ vars.RUNNER_24GB }}/cancel/${{ needs.initialize_worker.outputs.id }}" 68 | method: "POST" 69 | customHeaders: '{"Content-Type": "application/json"}' 70 | bearerToken: ${{ secrets.RUNPOD_API_KEY }} 71 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | ARG COG_REPO 2 | ARG COG_MODEL 3 | ARG COG_VERSION 4 | 5 | FROM r8.im/${COG_REPO}/${COG_MODEL}@sha256:${COG_VERSION} 6 | 7 | ENV RUNPOD_REQUEST_TIMEOUT=600 8 | 9 | # Install necessary packages and Python 3.10 10 | RUN apt-get update && apt-get upgrade -y && \ 11 | apt-get install -y --no-install-recommends software-properties-common curl git openssh-server && \ 12 | add-apt-repository ppa:deadsnakes/ppa -y && \ 13 | apt-get update && apt-get install -y --no-install-recommends python3.10 python3.10-dev python3.10-distutils && \ 14 | update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1 &&\ 15 | curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \ 16 | python3 get-pip.py 17 | 18 | # Create a virtual environment 19 | RUN python3 -m venv /opt/venv 20 | 21 | # Install runpod within the virtual environment 22 | RUN /opt/venv/bin/pip install runpod 23 | 24 | ADD src/handler.py /rp_handler.py 25 | 26 | CMD ["/opt/venv/bin/python3", "-u", "/rp_handler.py"] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 runpod-workers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |