diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1398b7f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +__pycache__ +config.yaml +cordarr.db +.DS_Store +notes.txt \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..d4b9fe0 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,59 @@ +name: Create and publish a Docker image + +# Run workflow on push events to the main branch. +on: + push: + branches: ['main'] + +# Define the package registry and image name as environment variables. +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +# Create the single job that builds and publishes the Docker image. +jobs: + build-and-push-image: + runs-on: ubuntu-latest + + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + attestations: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest + + + - name: Build and push Docker image + id: push + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: false \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0406189..1398b7f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ __pycache__ config.yaml cordarr.db -.DS_Store \ No newline at end of file +.DS_Store +notes.txt \ No newline at end of file diff --git a/README.md b/README.md index 4f9d21e..8b3289a 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,20 @@ CordArr is a self-hosted Discord bot that allows you to add new movies or shows to your Radarr/Sonarr libraries, and allow users to create temporary Jellyfin accounts on your server. -# Instructions +# Self-hosting + +## Docker +To run Guava in Docker, use the provided [docker-compose.yaml](docker-compose.yaml) file as a template for the container. Use the configuration section below to fill out the necessary information. + +## Bare metal +To run Guava on bare metal, follow the steps below. + +1. Install Python 3 and Pip +2. Clone this repository +3. Install the requirements with `pip install -r requirements.txt` +4. Run the `code/bot.py` file +5. Input information into the newly created config.yaml file. +6. Re-run the `code/bot.py` file. CordArr is built on Python and requires you to install all of the dependencies in the `requirements.txt` file. To do this, you can run the pip install command like `pip install -r requirements.txt` diff --git a/code/utils/config.py b/code/utils/config.py index 491677d..f3fc971 100644 --- a/code/utils/config.py +++ b/code/utils/config.py @@ -2,6 +2,7 @@ import jsonschema import validators import yaml import sys +import os import logging import requests import sqlite3 @@ -103,8 +104,13 @@ def load_config() -> None: If the file does not exist, generate it """ database_setup() + if os.path.exists("/.dockerenv"): + file_path = "/config/config.yaml" + else: + file_path = "config.yaml" + try: - with open("config.yaml", "r") as f: + with open(file_path, "r") as f: contents = f.read() validate_config(contents) diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..582ac23 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,7 @@ +services: + cordarr: + container_name: cordarr + image: ghcr.io/packetparker/cordarr:latest + volumes: + - /path/on/system:/config + - /path/on/system:/data \ No newline at end of file diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..3c80fef --- /dev/null +++ b/dockerfile @@ -0,0 +1,12 @@ +FROM python:3.12-slim + +LABEL org.opencontainers.image.source="https://git.pkrm.dev/parker/cordarr" +LABEL org.opencontainers.image.authors="parker " + +WORKDIR / + +COPY . . +RUN pip install -r requirements.txt + +ENTRYPOINT [ "python" ] +CMD [ "-u", "code/bot.py" ] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index fa63860..8887090 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,8 @@ colorlog==6.8.2 requests==2.32.0 -humanize==4.9.0 wonderwords==2.2.0 - -# validators -# jsonschema -# pyyaml -# discord py \ No newline at end of file +PyYAML==6.0.2 +validators==0.34.0 +jsonschema==4.23.0 +jsonschema-specifications==2024.10.1 +discord.py==2.4.0 \ No newline at end of file