guild icon
Toit
#How do I add assets to my containers using Jaguar?
Thread channel in help
bitphlipphar
bitphlipphar 01/22/2025 08:05 AM
There does not seem to be a straightforward way to add assets (things like html documents) as additional resources to containers using the Jaguar tooling.
bitphlipphar
bitphlipphar 01/22/2025 08:06 AM
It is possible to add assets to containers using the SDK tooling. It is described here: https://github.com/toitlang/toit?tab=readme-ov-file#adding-container-assets.

If we can find a way to do the same with the Jaguar tooling, it should be possible to have an html document associated with a container - and perhaps serve that document from a web server in the container.
(edited)
bitphlipphar
bitphlipphar 01/22/2025 08:10 AM
Jaguar has a way to add so-called defines for containers. Such defines are accessible from within the container, where they are included in a map available in the jag.defines asset.
bitphlipphar
bitphlipphar 01/22/2025 08:15 AM
So if you do jag run -D mypage.greeting="hello" myapp.toit, you can use the "hello" string from myapp.toit like this:

import system.assets main: jag-defines := assets.decode["jag.defines"] greeting := jag-defines["mypage.greeting"] print "greeting = $greeting"
bitphlipphar
bitphlipphar 01/22/2025 08:17 AM
Wishful thinking: If we could just add more seperate assets when installing or running apps using Jaguar, it would be simple to pass an html document like an argument. Something like jag run --asset file:mypage=mypage.html myapp.toit, perhaps. That could then be used from Toit code like this: assets.decode["mypage"].(edited)
bitphlipphar
bitphlipphar 01/22/2025 08:36 AM
Jaguar supports providing the assets for a program when run or installed using the --assets option. To use this, you first have to produce an assets file using toit tool assets.
bitphlipphar
bitphlipphar 01/22/2025 08:38 AM
First you create the assets file like this:
toit tool assets -e myassets create
and then you add you assets to it like this:
toit tool assets -e myassets add mypage mypage.html
bitphlipphar
bitphlipphar 01/22/2025 08:39 AM
This leaves you with an assets file called myassets that has a single entry (mypage) that contains the content of the mypage.html file.
bitphlipphar
bitphlipphar 01/22/2025 08:39 AM
You can look at the contents like this:
toit tool assets -e myassets list
(edited)
bitphlipphar
bitphlipphar 01/22/2025 08:41 AM
You can now pass your assets to your program by using jag run --assets myassets myapp.toit and you can access your html like this:
import system.assets main: mypage := assets.decode["mypage"] print "html = $mypage"
bitphlipphar
bitphlipphar 01/22/2025 08:42 AM
If you've only installed Jaguar, you can find the toit executable in $HOME/.cache/jaguar/sdk/bin/toit.
11 messages in total