diff --git a/.Dockerignore b/.Dockerignore new file mode 100644 index 0000000..588953d --- /dev/null +++ b/.Dockerignore @@ -0,0 +1,8 @@ +# ignore git files +.git* + +# ignore hidden files +.* + +# ignore directories +docs/ diff --git a/.docker_platforms b/.docker_platforms new file mode 100644 index 0000000..3859731 --- /dev/null +++ b/.docker_platforms @@ -0,0 +1 @@ +linux/amd64,linux/arm64/v8,linux/arm/v7 \ No newline at end of file diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index f9864d3..82f176d 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -49,7 +49,7 @@ jobs: run: | echo "Installing Requirements" python --version - python -m pip --no-python-version-warning --disable-pip-version-check install --upgrade pip==20.3.4 setuptools + python -m pip --no-python-version-warning --disable-pip-version-check install --upgrade pip setuptools # install dev requirements python -m pip install --upgrade -r requirements-dev.txt @@ -62,7 +62,7 @@ jobs: env: BUILD_VERSION: ${{ needs.check_changelog.outputs.next_version }} run: | - python scripts/build_plist.py + python ./scripts/build_plist.py - name: Test Plex Plugin working-directory: PlexyGlass.bundle diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml new file mode 100644 index 0000000..f4a5069 --- /dev/null +++ b/.github/workflows/ci-docker.yml @@ -0,0 +1,192 @@ +--- +# This action is centrally managed in https://github.com//.github/ +# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in +# the above-mentioned repo. + +name: CI Docker + +on: + pull_request: + branches: [master, nightly] + types: [opened, synchronize, reopened] + push: + branches: [master, nightly] + workflow_dispatch: + +jobs: + check_dockerfile: + name: Check Dockerfile + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Check + id: check + run: | + if [ -f "./Dockerfile" ] + then + FOUND=true + else + FOUND=false + fi + + echo "::set-output name=dockerfile::${FOUND}" + + outputs: + dockerfile: ${{ steps.check.outputs.dockerfile }} + + lint_dockerfile: + name: Lint Dockerfile + needs: [check_dockerfile] + if: ${{ needs.check_dockerfile.outputs.dockerfile == 'true' }} + runs-on: ubuntu-latest + steps: + - name: Lint Dockerfile + uses: actions/checkout@v3 + + - uses: hadolint/hadolint-action@v2.1.0 + with: + dockerfile: ./Dockerfile + + check_changelog: + name: Check Changelog + needs: [check_dockerfile] + if: ${{ needs.check_dockerfile.outputs.dockerfile == 'true' }} + runs-on: ubuntu-latest + steps: + - name: Checkout + if: ${{ github.ref == 'refs/heads/master' || github.base_ref == 'master' }} + uses: actions/checkout@v3 + + - name: Verify Changelog + id: verify_changelog + if: ${{ github.ref == 'refs/heads/master' || github.base_ref == 'master' }} + # base_ref for pull request check, ref for push + uses: LizardByte/.github/actions/verify_changelog@master + with: + token: ${{ secrets.GITHUB_TOKEN }} + outputs: + next_version: ${{ steps.verify_changelog.outputs.changelog_parser_version }} + + docker: + name: Docker + needs: [check_dockerfile, check_changelog] + if: ${{ needs.check_dockerfile.outputs.dockerfile == 'true' }} + runs-on: ubuntu-latest + permissions: + packages: write + contents: write + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Prepare + id: prepare + env: + NEXT_VERSION: ${{ needs.check_changelog.outputs.next_version }} + run: | + # get branch name + BRANCH=${GITHUB_HEAD_REF} + + if [ -z "$BRANCH" ] + then + echo "This is a PUSH event" + BRANCH=${{ github.ref_name }} + fi + + # determine to push image to dockerhub and ghcr or not + if [[ $GITHUB_EVENT_NAME == "push" ]]; then + PUSH=true + else + PUSH=false + fi + + # setup the tags + REPOSITORY=${{ github.repository }} + BASE_TAG=$(echo $REPOSITORY | tr '[:upper:]' '[:lower:]') + COMMIT=${{ github.sha }} + + TAGS="${BASE_TAG}:${COMMIT:0:7},ghcr.io/${BASE_TAG}:${COMMIT:0:7}" + + if [[ $GITHUB_REF == refs/heads/master ]]; then + TAGS="${TAGS},${BASE_TAG}:latest,ghcr.io/${BASE_TAG}:latest" + TAGS="${TAGS},${BASE_TAG}:master,ghcr.io/${BASE_TAG}:master" + elif [[ $GITHUB_REF == refs/heads/nightly ]]; then + TAGS="${TAGS},${BASE_TAG}:nightly,ghcr.io/${BASE_TAG}:nightly" + else + TAGS="${TAGS},${BASE_TAG}:test,ghcr.io/${BASE_TAG}:test" + fi + + if [[ ${NEXT_VERSION} != "" ]]; then + TAGS="${TAGS},${BASE_TAG}:${NEXT_VERSION},ghcr.io/${BASE_TAG}:${NEXT_VERSION}" + fi + + # read the platforms from `.docker_platforms` + PLATFORMS=$(<.docker_platforms) + + echo ::set-output name=branch::${BRANCH} + echo ::set-output name=build_date::$(date -u +'%Y-%m-%dT%H:%M:%SZ') + echo ::set-output name=commit::${COMMIT} + echo ::set-output name=platforms::${PLATFORMS} + echo ::set-output name=push::${PUSH} + echo ::set-output name=tags::${TAGS} + + - name: Set Up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + id: buildx + + - name: Cache Docker Layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Log in to Docker Hub + if: ${{ steps.prepare.outputs.push == 'true' }} # PRs do not have access to secrets + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Log in to the Container registry + if: ${{ steps.prepare.outputs.push == 'true' }} # PRs do not have access to secrets + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ secrets.GH_BOT_NAME }} + password: ${{ secrets.GH_BOT_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: ./ + file: ./Dockerfile + push: ${{ steps.prepare.outputs.push }} + platforms: ${{ steps.prepare.outputs.platforms }} + build-args: | + BRANCH=${{ steps.prepare.outputs.branch }} + BUILD_DATE=${{ steps.prepare.outputs.build_date }} + BUILD_VERSION=${{ needs.check_changelog.outputs.next_version }} + COMMIT=${{ steps.prepare.outputs.commit }} + tags: ${{ steps.prepare.outputs.tags }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Update Docker Hub Description + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} + uses: peter-evans/dockerhub-description@v3 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_PASSWORD }} # token is not currently supported + repository: ${{ env.BASE_TAG }} + short-description: ${{ github.event.repository.description }} + readme-filepath: ./DOCKER_README.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 66b965b..4a3cfdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [0.0.2] - 2022-09-11 +### Added +- Add docker-mod for linuxserver plex image +- ## [0.0.1] - 2022-09-09 ### Added - Initial Release diff --git a/DOCKER_README.md b/DOCKER_README.md new file mode 100644 index 0000000..0d27636 --- /dev/null +++ b/DOCKER_README.md @@ -0,0 +1,11 @@ +# Docker + +This is a docker mod for Plex which adds [PlexyGlass](https://github.com/LizardByte/PlexyGlass) to Plex as a plugin, +to be downloaded/updated during container start. + +In plex docker arguments, set an environment variable `DOCKER_MODS=lizardbyte/plexyglass:latest` + +If adding multiple mods, enter them in an array separated by `|`, such as +`DOCKER_MODS=lizardbyte/plexyglass:latest|linuxserver/mods:other-plex-mod` + +For more information about linuxserver docker-mods, see [here](https://linuxserver.github.io/docker-mods/). diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e464b30 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# buildstage +FROM python:2.7.18-alpine3.11 as buildstage + +# build args +ARG BUILD_VERSION +ARG COMMIT +ARG GITHUB_SHA=$COMMIT +# note: BUILD_VERSION may be blank, COMMIT is also available +# note: build_plist.py uses BUILD_VERSION and GITHUB_SHA + +# setup build directory +RUN mkdir /build +WORKDIR /build/ + +# copy repo +COPY . . + +RUN python # update pip \ + -m pip --no-python-version-warning --disable-pip-version-check install --upgrade pip==20.3.4 setuptools \ + && python -m pip install --upgrade -r requirements-dev.txt # install dev requirements \ + && python ./scripts/install_requirements.py # install plugin requirements \ + && python ./scripts/build_plist.py # build plist \ + && rm -r ./scripts/ # remove scripts dir + +# single layer deployed image +FROM scratch + +# variables +ARG PLUGIN_NAME="PlexyGlass.bundle" +ARG PLUGIN_DIR="/config/Library/Application Support/Plex Media Server/Plug-ins" + +# add files from buildstage +COPY --from=buildstage /build/ $PLUGIN_DIR/$PLUGIN_NAME diff --git a/docs/source/about/docker.rst b/docs/source/about/docker.rst new file mode 100644 index 0000000..0673f24 --- /dev/null +++ b/docs/source/about/docker.rst @@ -0,0 +1,3 @@ +:github_url: https://github.com/LizardByte/PlexyGlass/tree/nightly/DOCKER_README.md + +.. mdinclude:: ../../../DOCKER_README.md diff --git a/docs/source/conf.py b/docs/source/conf.py index 5b61f42..b9ae1e6 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -75,7 +75,7 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - # 'm2r2', # enable markdown files + 'm2r2', # enable markdown files 'numpydoc', # this automatically loads `sphinx.ext.autosummary` as well 'sphinx.ext.autodoc', # autodocument modules 'sphinx.ext.autosectionlabel', @@ -92,7 +92,7 @@ exclude_patterns = ['toc.rst'] # Extensions to include. -source_suffix = ['.rst'] +source_suffix = ['.rst', '.md'] # Change default contents file master_doc = 'index' diff --git a/docs/source/toc.rst b/docs/source/toc.rst index 06f7dee..0e0bd68 100644 --- a/docs/source/toc.rst +++ b/docs/source/toc.rst @@ -4,6 +4,7 @@ about/overview about/installation + about/docker about/usage .. toctree:: diff --git a/requirements-dev.txt b/requirements-dev.txt index 8a332c3..3087b14 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,6 @@ # development environment requirements, these should not be distributed flake8==3.9.2;python_version<"3" +m2r2==0.3.2;python_version<"3" numpydoc==0.9.2;python_version<"3" pathlib2==2.3.7.post1;python_version<"3" git+https://github.com/LizardByte/plexhints.git#egg=plexhints # type hinting library for plex development