Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Addon's Library logic with Rez #29

Closed
wants to merge 8 commits into from

Conversation

Minkiu
Copy link
Contributor

@Minkiu Minkiu commented Jun 20, 2023

Replace addons logic with Rez

This Pull Request, modifies the backend in order to leverage Rez to manage AYON addons (they should now include a package.py with the attribute plugin_for="ayon_server".

A loose explantation of the process is:

  1. When we spin the server, we make sure a (meta) package named ayon_server exists in our repo, as of now /addons; and it matches the current ayon-backend version, otherwise we create one, and request a restart, this package has the attribute has_plugins=True
  2. We try to find plug-ins for our ayon_server.
  3. We, as before, attempt to initialize the add-ons defined in the bundles; we can now list all installed packages without actually initializing them, and keep a list of initialized and broken ones.
  4. When installing an addon, we have a rezbuild.py that we fall back for simple addons; there's a bug in rez that makes it mandatory for the package.py to contain the build_command attribute set (tried to add it programmatically, but it won't install the package, due this bug).

All the rest should work as it does now, I really haven't tested the migration of settings between bundles, so that might not be working at the minute.

Reviewing

I tired to keep it tidy and compartemantilized, so there are 4 commits:

  1. Implement the RezRepo class
  2. Refactor AddonLibrary to make use of the RezRepo
  3. Modify all instance of the AddonLibrary in the api folder, to adapt to any required changes
  4. Modify all instances of the AddonLibrary in the ayon_server folder, to adapt to any required changes, this one has some bits that have changed more than simple method renames.

TODO

  • Adapt AYON addons to rez packages (simply add a package.py at the root).
  • Refactor the BaseServerAddon and move some of the attributes to the package.py then, read the info from there.

Testing note

I would suggest making a copy of the docker-compose.yml in the ayon-docker backend and build a new image called ayon-rez that build the new rez dependency; so it does not interfere with your existing deploys; also map the /addons folder to a different one than the one you are currently using.

version: "3.7"

services:
  postgres:
    image: postgres:15
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ayon"]
      interval: 5s
      timeout: 5s
      retries: 5

    expose: [5432]

    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "db:/var/lib/postgresql/data"

    environment:
      - "POSTGRES_USER=ayon"
      - "POSTGRES_PASSWORD=ayon"
      - "POSTGRES_DB=ayon"

  redis:
    image: redis:alpine
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "redis-cli ping | grep PONG"]
      interval: 5s
      timeout: 5s
      retries: 5

    expose: [6379]


  server:
    image: localhost/ayon-rez:latest
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5000/api/info"]
      interval: 10s
      timeout: 2s
      retries: 3

    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started
    # uncomment for older versions of Docker (>4.0.0) and comment out above "depends on" section.
    #depends_on:
      #- postgres
      #- redis

    expose: [5000]
    ports: ["5000:5000"]

    volumes:
      - "./rezrepo:/addons:Z"
      - "./storage:/storage:Z"

      # comment out the following line on Windows
      - "/etc/localtime:/etc/localtime:ro"

      # uncomment the following line if you need to work on the backend code
      - "/home/minkiu/Projects/ynput/ayon-backend:/backend:Z"

volumes:
  db: {}

You can use this PR to generate rez packages out of the OpenPype ones: ynput/OpenPype#6169

@Minkiu Minkiu marked this pull request as draft June 20, 2023 14:31
@Minkiu
Copy link
Contributor Author

Minkiu commented Jun 20, 2023

Marking as draft so we can have a conversation about this.

@Minkiu Minkiu requested a review from antirotor June 20, 2023 14:39
@Minkiu Minkiu force-pushed the feature/use_rez_for_addon_resolving branch 6 times, most recently from 46d4418 to 3a5b917 Compare June 21, 2023 14:39
@BigRoy
Copy link
Contributor

BigRoy commented Jun 27, 2023

Thanks for drafting a prototype! I haven't been involved much with the Ayon backend but just wanted to say that any work on this front in combination with Rez is greatly appreciated.

This PR's Rez integration is solely regarding the addons and modules in the backend, not the running of the actual DCC application and tools, right? So it's not for those that might have a huge ready-to-go Rez repository already with many applications and tools and allow them to launch those through OpenPype for certain hosts. Or am I mistaken?

@antirotor
Copy link
Member

This PR's Rez integration is solely regarding the addons and modules in the backend, not the running of the actual DCC application and tools, right? So it's not for those that might have a huge ready-to-go Rez repository already with many applications and tools and allow them to launch those through OpenPype for certain hosts. Or am I mistaken?

For that we will need to implement alternative to applications addon that will use rez and also we will need to create rez package from ayon-launcher (that will be the new entry point as Igniter in OP is)

@BigRoy
Copy link
Contributor

BigRoy commented Jun 27, 2023

For that we will need to implement alternative to applications addon that will use rez and also we will need to create rez package from ayon-launcher (that will be the new entry point as Igniter in OP is)

Great. Just to confirm, so this particular PR is not intended to do that. Right?

@Minkiu
Copy link
Contributor Author

Minkiu commented Jun 27, 2023

You are right, this is not the PR for that.

And there are other changes happening on the same parts, that I'll need to rebase later, so this won't be merge in the near future I'd say.

@iLLiCiTiT
Copy link
Member

Is with this PR possible to manually add/remove addon to/from server?

@Minkiu
Copy link
Contributor Author

Minkiu commented Jul 3, 2023

No, this PR doesn't implement the adding/removing side of thing, will wait till the bundle changes settle to rebase and piggyback on current implementation to install /remove and hook there Rez

@Minkiu Minkiu force-pushed the feature/use_rez_for_addon_resolving branch from ff7574c to 3c0fcd4 Compare November 22, 2023 16:38
@Minkiu Minkiu force-pushed the feature/use_rez_for_addon_resolving branch from 432038e to 903ab76 Compare December 12, 2023 10:12
@Minkiu Minkiu force-pushed the feature/use_rez_for_addon_resolving branch 2 times, most recently from 3ca86d2 to 25e56b5 Compare January 16, 2024 17:27
@Minkiu Minkiu force-pushed the feature/use_rez_for_addon_resolving branch 4 times, most recently from 6c4fd8e to ef7824b Compare January 29, 2024 12:55
@Minkiu Minkiu force-pushed the feature/use_rez_for_addon_resolving branch 4 times, most recently from cd4f16c to 4cbd4c4 Compare January 29, 2024 17:00
This commit add a new class to the `ayon_server.addons` logic that allows
the server to use Rez (https://github.com/AcademySoftwareFoundation/rez)
as a package manager, including a default `rezbuild.py` for packages that
do not include one, these need to follow the AYON Addon template structure.

THIS BREAKS WITH EXISTING ADDONS present in the `/addons` which are not
rez packages.
@Minkiu Minkiu force-pushed the feature/use_rez_for_addon_resolving branch 4 times, most recently from 72e0e6a to 9a48d6d Compare January 29, 2024 17:19
@Minkiu Minkiu marked this pull request as ready for review January 29, 2024 17:21
@Minkiu
Copy link
Contributor Author

Minkiu commented Jan 29, 2024

I am finally satisfied with the commit history, and managed to catch some bugs, it is now ready to be reviewed, will update the PR to reflect changes.

With the implementation of the `RezRepo` we deprecate the previous
`ServerAddonDefinition` since now we leverage `rez.PackageFamily` to
achieve the same results.

The class has been refactored to use `RezRepo` for discovery, installing
and removing AYON addons.

Some methods have been kept (or reworded) but refactored to provide a more
streamlined set of results, hopefully for consistency when using the
`AddonLibrary`.
Modified all instances where we accessed the AddonLibrary to ensure
we get the same result as previously and that everything works given the
new class.
@Minkiu Minkiu force-pushed the feature/use_rez_for_addon_resolving branch from 9a48d6d to 9ae1706 Compare January 29, 2024 17:38
@Minkiu Minkiu changed the title Proof of Concept for using Rez as an Addon resolver Replace Addon's Library logic with Rez Jan 29, 2024
…Repo`

Modified all modules where the interface with `AddonLibrary` changed or
where it was now necessary to use the `RezRepo`.
@Minkiu Minkiu force-pushed the feature/use_rez_for_addon_resolving branch from 9ae1706 to 2f0d86e Compare January 30, 2024 12:23
@Minkiu Minkiu requested a review from iLLiCiTiT February 1, 2024 16:09
api/system/info.py Outdated Show resolved Hide resolved
Minkiu and others added 4 commits February 14, 2024 15:15
Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
# Copy "server" to "addon"
if server_dir.is_dir():
print(f"Copying `server` directory contents to {DEST_DIR}")
_recursive_copy(server_dir, DEST_DIR)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not what this does, but if there is package.py it does expect to have server code in server subfolder.

Suggested change
_recursive_copy(server_dir, DEST_DIR)
_recursive_copy(server_dir, DEST_DIR / "server")

@martastain martastain added the wontfix This will not be worked on label Apr 12, 2024
@martastain martastain closed this Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants