Hosting anvil app on a server: how to deal with dependencies?

What I’m trying to do:
Launch an anvil app on a server.

What I’ve tried and what’s not working:
It depends on a m3 package. I’ve downloaded m3 from github.
It starts the server, but then it shows that dependencies are not found.

Code Sample:
Example of a config file

app: "M3_App_1" #directory name
origin: "https://test.domain.com"
dep-id:
  "dep_123: "m3" #from anvil.yaml

Does anybody have a working example of a config file?
Any help is appreciated?

EDIT: Don’t listen to me review the next post by meredydd.

Your dep-id map should use the app_id not the dep_id value.

the map should look something like:
"4UK6WHQ6UX7AKELK": "m3"

It looks like you are using the dep_id which is not going to work.
"dep_lin1x4oec0ytd": "m3"

2 Likes

Actually, the dep ID is the correct thing to use! (It’s easy to get confused by older apps, which use the app ID as the dep ID.) Let me explain why, then I’ll get to the practical problem at the bottom, I promise!

Why dep_ids?

Anvil uses “dep IDs” to abstract out the identity of dependencies, so that the same app source code can depend on different apps in different circumstances.

For example, let’s imagine you want to contribute to anvil-extras. You fork the repo on GitHub, check out your fork into Anvil, create a new branch, and add a new feature to anvil-extras. Now you want to test it with one of your apps before you submit a pull request.

If your app’s source code were hard-wired to the app ID of the official anvil-extras instance, you’d be out of luck! But it actually uses an opaque dep ID in the source code, with a record in our database connecting that dep ID to the app ID. So you can go into your dependency config and remap that dependency: ie, point that dependency ID to your own development version of anvil-extras. Now your app will load your dev app, and you can play with your new features.

The dep IDs in your source code are unchanged: if you’re using GitHub to collaborate with someone else who’s using the official anvil-extras, their app will still load the official app, even though the source code is bit-for-bit identical to yours. This is because the connection between dep ID and app ID lives outside the source repository.

When you set dependency IDs in the App Server, it works the same way. The source code contains opaque dep IDs; your config needs to tell the App Server how map those dep IDs into directories where it can find other Anvil apps.

Backward compatibility, source of all my problems

It wasn’t always this way – when we first launched Anvil, apps referred to their dependencies by their app ID. Literally, if you used an anvil-extras component Slider on your form, the designer data (aka form YAML) would contain something like form:C6ZZPAPN4YYF5NVJ:Slider (where C6ZZPAPN4YYF5NVJ is the app ID of the “official” anvil-extras). This obviously didn’t work with the scenario above, so we invented the dep ID system instead.

But for apps that already existed, and had app IDs baked into their designer data, we just used the original app ID as the new dep ID. So if you took that old app and remapped it to point at your own development version of anvil-extras, the dep ID would still be C6ZZPAPN4YYF5NVJ. This works perfectly, but gets a bit confusing if you want to use the app server and need to get under the hood. Then you have to tangle with…all of this.

So what’s the actual problem here?

So, if that’s not @augustas.volbekas’s problem, what is? My guess is that @augustas.volbekas’s config file isn’t using the right dep IDs. To find the correct dep ID, open up anvil.yaml and look for the dependencies section. You should find the section for the M3 dependency, which contains a dep_id. Use that instead of dep_123 in your config file, and all will be well!

6 Likes

You might be interested in the amoni project which attempts to make this all as easy as possible.

1 Like

Thank you @meredydd, I got it to work eventually, your explanation helped a lot.

Thank you @owen.campbell, I’ll check out the tool, seems like a life saver.

1 Like

Hi, struggling with the same problem - deploying my app on a Hetzner VPS and using the m3 dependency. Where I (and ChatGPT) get confused is the tree structure I should have on the server and where in that structure to place the dependency. Can you share your structure. I’ve read the answers about parents etc… but they don’t click in my brain. 2nd question: What is your config file (apparently not a yaml) and where does that one sit.
Thanks a million