Switching Storage roots based on Environment or Project

We are trying to modify our configuration so that we can select which Storage Root we want to use on a per project basis. The schema can remain identical but the roots need to change. We haven’t had any luck so far.

We have attempted:

  • having just one storage root and overriding the value with an env var in the roots.yml. When launching DCCs however, the apps e.g. tk-maya are still initialised with the storage root as defined in the Shotgun Storages, so files are created and published to those roots.

  • having two storage roots, and setting the default value based on an environment variable, however this doesn’t work either as the env vars are not evaluated when this file is parsed.

  • having two storage roots, and using filters based on a value set in the project info, but I haven’t been able to storage roots to be filtered this way - only the schemas.

  • specifying the root in our templates using an environment variable, but again this isn’t evaluated, so it only seems to accept an explicit naming of the root.

Are we missing something obvious here?

I have seen this thread to which the answer is no, but I’m not sure if our case is exactly the same. We do not need the env var kept in the root for delayed evaluation. It just needs to be set at the point of checking out the project/config.

Thanks,
Joe

Do you need that for existing projects or for new project only? If for new, just select proper root during proejct configuration. But if you need to change existing project i think that you should modify roots.yml provide there correct id and pathes. Beside this you need to create correct shotgun storage entity (‘LocalStorage’).

2 Likes

Just for new projects should be fine, However I’m unsure how you select a root during project configuration - can you elaborate on that a bit? Thanks

Sure, you should modify root.yml file and provide there valid id and pathes just like on your Shotgun site. Look at Site Preferences → File Management, there you should have all your roots. Because hooks can ask shotgun for root path. If you have problem with getting correct shotgun_storage_id, just use python console in shotgun desktop:

storage_name = 'your storage name"
storage_id = sg.find('LocalStorage', [['code', 'is', storage_id]], ['windows_path'])
print(storage_id)

Ah I see what you’re saying, but we maintain our roots.yml file in a repo that is shared across all projects. We’re trying to avoid having to maintain different branches for different projects/roots, so having a different roots.yml file per-project isn’t (currently) an option.

Hence, we were trying to have all the possible storage roots listed in the roots.yml file, then set which one is to be used through the environment or a project setting within the Shotgun db.

Well if the configuration really is per project (i.e. you never need to switch roots mid-project), then branches would be much simpler than implementing dynamic switching, so I would go with @Kemot 's suggestion.