diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..529221b --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,9 @@ +ARG VARIANT="3.10-bullseye" +FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT} + +ARG NODE_VERSION="none" +RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi + +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends python3-venv python-is-python3 micro \ + unzip zip build-essential python3-dev redis-tools diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..2f471a1 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,80 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/python-3 +{ + "name": "Python 3", + "build": { + "dockerfile": "Dockerfile", + "context": "..", + "args": { + // Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6 + // Append -bullseye or -buster to pin to an OS version. + // Use -bullseye variants on local on arm64/Apple Silicon. + "VARIANT": "3.10-bullseye", + // Options + "NODE_VERSION": "lts/*" + } + }, + + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": { + "python.defaultInterpreterPath": "/usr/local/bin/python", + "python.linting.enabled": true, + "python.linting.pylintEnabled": true, + "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8", + "python.formatting.blackPath": "/usr/local/py-utils/bin/black", + "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf", + "python.linting.banditPath": "/usr/local/py-utils/bin/bandit", + "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8", + "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy", + "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle", + "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle", + "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint" + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-python.python", + "ms-python.vscode-pylance", + "eamodio.gitlens", + "nimda.deepdark-material", + "jeff-hykin.better-dockerfile-syntax", + "njpwerner.autodocstring", + "wwm.better-align", + "me-dutour-mathieu.vscode-github-actions", + "github.copilot-nightly", + "visualstudioexptteam.vsco", + "visualstudioexptteam.intellicode-api-usage-examples", + "zainchen.json", + "matangover.mypy", + "ionutvmi.path-autocomplete", + "christian-kohler.path-intellisense", + "donjayamanne.python-extension-pack", + "redhat.vscode-yaml", + "kevinrose.vsc-python-indent", + "bungcip.better-toml", + "rangav.vscode-thunder-client", + "kdcro101.vscode-redis", + "cweijan.vscode-database-client2", + "phu1237.vs-browser", + "philnash.ngrok-for-vscode" + ] + } + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "./.devcontainer/postCreateCommand.sh", + + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode", + "features": { + "docker-from-docker": "latest", + "github-cli": "latest" + } +} diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh new file mode 100644 index 0000000..028de52 --- /dev/null +++ b/.devcontainer/postCreateCommand.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +python3 -m pip install --user pipx + +printf "Installing pipx for the current user...\n" + +python3 -m pip install --user pipx +python3 -m pipx ensurepath +echo 'eval "$(register-python-argcomplete pipx)"' >> ~/.profile +source ~/.profile + +printf "Installing poetry for the current user...\n" + +pipx install poetry + +printf "Starting Redis...\n" + +docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest + +printf "Installing dependencies...\n" + +poetry install --all-extras diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..dd84ea7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/others.md b/.github/ISSUE_TEMPLATE/others.md new file mode 100644 index 0000000..492b87b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/others.md @@ -0,0 +1,20 @@ +--- +name: Others +about: Used for purposes not included in the previous templates +title: "[OTHERS] " +labels: '' +assignees: '' + +--- + +**What:** + +**Why:** + +**When:** + +**Who:** + +**Where:** + +**OBS:** diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..b38df29 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "pip" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/codeql_analysis.yml b/.github/workflows/codeql_analysis.yml new file mode 100644 index 0000000..886b57e --- /dev/null +++ b/.github/workflows/codeql_analysis.yml @@ -0,0 +1,59 @@ +name: "CodeQL" + +on: + push: + branches: [ "dev" ] + pull_request: + branches: [ "dev" ] + schedule: + - cron: '21 13 * * 3' + workflow_dispatch: + +env: + default_branch: dev + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'python' ] + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: ${{ env.default_branch }} + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10.8' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; + then pip install -r requirements.txt; + fi + echo "CODEQL_PYTHON=$(which python)" >> $GITHUB_ENV + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + setup-python-dependencies: false + + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 0000000..35d507c --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,69 @@ +name: Build dev branch + +on: + push: + branches: [ "dev" ] + schedule: + - cron: '24 9 * * 6' + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + IMAGE_TAG: ${{ github.sha }} + +jobs: + security_checks: + runs-on: ubuntu-latest + name: Security check + steps: + - uses: actions/checkout@v2 + - name: Security Checks (PyCharm Security) + uses: tonybaloney/pycharm-security@master + with: + path: . + + build: + needs: security_checks + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout Dockerfile + id: checkout + uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + + - name: Setup QEMU + id: qemu + uses: docker/setup-qemu-action@v1 + with: + image: tonistiigi/binfmt:latest + platforms: all + + - name: Setup Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=${{ startsWith(github.ref, 'refs/heads/main') }} + suffix=-${{ github.sha }} + + - name: Build Docker image + id: build + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64/v8 + push: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/features.yml b/.github/workflows/features.yml new file mode 100644 index 0000000..cc6cb90 --- /dev/null +++ b/.github/workflows/features.yml @@ -0,0 +1,70 @@ +name: Build a feature branch + +on: + workflow_dispatch: + inputs: + branch: + description: 'Branch' + required: true + default: '' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + IMAGE_TAG: ${{ github.sha }} + +jobs: + security_checks: + runs-on: ubuntu-latest + name: Security check + steps: + - uses: actions/checkout@v2 + - name: Security Checks (PyCharm Security) + uses: tonybaloney/pycharm-security@master + with: + path: . + + build: + needs: security_checks + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout Dockerfile + id: checkout + uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + + - name: Setup QEMU + id: qemu + uses: docker/setup-qemu-action@v1 + with: + image: tonistiigi/binfmt:latest + platforms: all + + - name: Setup Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=${{ startsWith(github.ref, 'refs/heads/main') }} + suffix=-${{ github.sha }} + + - name: Build Docker image + id: build + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64/v8 + push: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..9115554 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,65 @@ +name: Build and Publish Docker Image + +on: + push: + branches: [ main ] + schedule: + - cron: '24 9 * * 6' + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + IMAGE_TAG: ${{ github.sha }} + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout Dockerfile + id: checkout + uses: actions/checkout@v2 + + - name: Setup QEMU + id: qemu + uses: docker/setup-qemu-action@v1 + with: + image: tonistiigi/binfmt:latest + platforms: all + + - name: Setup Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to GitHub Container Registry + id: ghcr + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.repository_owner }} + password: ${{ secrets.GH_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=${{ startsWith(github.ref, 'refs/heads/main') }} + suffix=-${{ github.sha }} + + - name: Build and push Docker image + id: build + uses: docker/build-push-action@v2 + with: + build-args: GH_TOKEN=${{ secrets.GH_TOKEN }} + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64/v8 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/pull_requests.yml b/.github/workflows/pull_requests.yml new file mode 100644 index 0000000..c00b953 --- /dev/null +++ b/.github/workflows/pull_requests.yml @@ -0,0 +1,65 @@ +on: + pull_request: + branches: [ "main", "dev" ] + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + IMAGE_TAG: ${{ github.sha }} + +jobs: + security_checks: + runs-on: ubuntu-latest + name: Security check + steps: + - uses: actions/checkout@v2 + - name: Security Checks (PyCharm Security) + uses: tonybaloney/pycharm-security@master + with: + path: . + + build: + needs: security_checks + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout Dockerfile + id: checkout + uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + + - name: Setup QEMU + id: qemu + uses: docker/setup-qemu-action@v1 + with: + image: tonistiigi/binfmt:latest + platforms: all + + - name: Setup Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=${{ startsWith(github.ref, 'refs/heads/main') }} + suffix=-${{ github.sha }} + + - name: Build Docker image + id: build + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64/v8 + push: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..738281a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.analysis.typeCheckingMode": "off" +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0e9ce1a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM python:3.10-slim + +ARG GITHUB_TOKEN +ENV GITHUB_TOKEN $GITHUB_TOKEN + +ARG HYPERCORN_HOST +ENV HYPERCORN_HOST $HYPERCORN_HOST + +ARG HYPERCORN_PORT +ENV HYPERCORN_PORT $HYPERCORN_PORT + +ARG HYPERCORN_LOG_LEVEL +ENV HYPERCORN_LOG_LEVEL $HYPERCORN_LOG_LEVEL + +WORKDIR /usr/src/app + +COPY . . + +RUN apt update && \ + apt-get install build-essential libffi-dev -y \ + && pip install --no-cache-dir -r requirements.txt + +CMD [ "python3", "./run.py" ] diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml new file mode 100644 index 0000000..1a6ffd6 --- /dev/null +++ b/deploy/docker-compose.yml @@ -0,0 +1,33 @@ +version: "3.8" + +services: + redis: + container_name: revanced-releases-api-redis + image: redis-stack-server:latest + environment: + - REDIS_ARGS=--save 60 1 --appendonly yes + volumes: + - /data/redis/revanced-releases-api:/data + networks: + - infra + restart: always + revanced-releases-api: + container_name: revanced-releases-api + image: ghcr.io/alexandreteles/revanced-releases-api:latest + environment: + - GITHUB_TOKEN=YOUR_GITHUB_TOKEN + - REDIS_URL=revanced-releases-api-redis + - REDIS_PORT=6379 + - HYPERCORN_HOST=0.0.0.0 + - HYPERCORN_PORT=8000 + - HYPERCORN_LOG_LEVEL=debug + - SENTRY_DSN=YOUR_SENTRY_DSN + ports: + - 127.0.0.1:7934:8000 + networks: + - infra + restart: unless-stopped + +networks: + infra: + external: true diff --git a/deploy/portainer-stack.yml b/deploy/portainer-stack.yml new file mode 100644 index 0000000..87fd47e --- /dev/null +++ b/deploy/portainer-stack.yml @@ -0,0 +1,34 @@ +--- +version: "3.8" + +services: + redis: + container_name: revanced-releases-api-redis + image: redis-stack-server:latest + environment: + - REDIS_ARGS=--save 60 1 --appendonly yes + volumes: + - /data/redis/revanced-releases-api:/data + networks: + - infra + restart: always + revanced-releases-api: + container_name: revanced-releases-api + image: ghcr.io/alexandreteles/revanced-releases-api:latest + environment: + - GITHUB_TOKEN=YOUR_GITHUB_TOKEN + - REDIS_URL=revanced-releases-api-redis + - REDIS_PORT=6379 + - HYPERCORN_HOST=0.0.0.0 + - HYPERCORN_PORT=8000 + - HYPERCORN_LOG_LEVEL=debug + - SENTRY_DSN=YOUR_SENTRY_DSN + ports: + - 127.0.0.1:7934:8000 + networks: + - infra + restart: unless-stopped + +networks: + infra: + external: true