What is a (the?) way to track requirements for a web or app with Racket?

53 views
Skip to first unread message

Marc Kaufmann

unread,
Sep 16, 2019, 4:42:04 AM9/16/19
to Racket Users
Hi,

this is surely answered somewhere, but I have not made much progress. If you know python, what I want to do is essentially

$ pip install requirements.txt

where requirements.txt has a list (one per line) of packages and their versions to install (usually installed into a virtual environment). I am pretty certain that I can do this with raco setup or raco pkg or raco ... but I can't figure out how to do it. Essentially I want to avoid having to run

raco pkg install forms
raco pkg install ...
raco pkg install ...

which is what I currently do. What is the most vanilla way of doing this? Most of the threads I found were about bundling whole apps or packages, which I would think is different from what I want, although I am not sure. I guess I could do this via Ansible, which is how I do most of these things, but it seems there should be a better way (and Ansible won't know if something is already installed or not, just dumbly run the command).

Also, if anyone knows of a good blog/tutorial on this kind of sysadmin/devops/deploy side of things in Racket, I'd love to know about it. 

Cheers,
Marc

Bogdan Popa

unread,
Sep 16, 2019, 5:04:58 AM9/16/19
to Marc Kaufmann, Racket Users

Marc Kaufmann writes:

> this is surely answered somewhere, but I have not made much progress. If
> you know python, what I want to do is essentially
>
> $ pip install requirements.txt
>

Although it's not exactly the same thing, I use `info.rkt'[1][2]
(similar to `setup.py') for this purpose and each one of
my web apps is its own package.

Here's an example of what that ends up looking like:

https://github.com/Bogdanp/koyo/blob/master/koyo-lib/blueprints/standard/app-name-here/info.rkt

and

https://github.com/Bogdanp/koyo/tree/master/koyo-lib/blueprints/standard#first-time-setup

For deployment, I leverage `raco exe' and `raco distribute' to create
self-contained distributions that I can ship to my server.

[1]: https://docs.racket-lang.org/pkg/metadata.html
[2]: https://docs.racket-lang.org/raco/setup-info.html

Marc Kaufmann

unread,
Sep 16, 2019, 5:22:25 AM9/16/19
to Bogdan Popa, Racket Users
So the easiest to do is to create such an info.rkt file and call `raco pkg install app-name/` -- and that should work even if I don't do the `raco exe` and `raco distribute`?

Alex Harsanyi

unread,
Sep 16, 2019, 5:22:30 AM9/16/19
to Racket Users


On Monday, September 16, 2019 at 5:04:58 PM UTC+8, Bogdan Popa wrote:

Marc Kaufmann writes:

> this is surely answered somewhere, but I have not made much progress. If
> you know python, what I want to do is essentially
>
> $ pip install requirements.txt
>

Although it's not exactly the same thing, I use `info.rkt'[1][2]
(similar to `setup.py') for this purpose and each one of
my web apps is its own package.

Does this mean that the application itself is available as a package and you can require files from inside the application from another program?  More importantly, can you have two copies of the application installed on your system, for example for development purposes?

Bogdan Popa

unread,
Sep 16, 2019, 5:42:06 AM9/16/19
to Alex Harsanyi, Racket Users

Alex Harsanyi writes:

>> Although it's not exactly the same thing, I use `info.rkt'[1][2]
>> (similar to `setup.py') for this purpose and each one of
>> my web apps is its own package.
>>
>
> Does this mean that the application itself is available as a package and
> you can require files from inside the application from another program?

Yes. In fact, I leverage this property to keep my apps' tests in a
separate package. My e-commerce site, for example, is composed of two
packages: `matchacha' and `matchacha-tests'.

This means I don't have to ship my tests and their dependencies to the
server and it also has the added benefit that compilation times are
improved. The latter is important in development since my development
server watches the FS and it recompiles any files that change before it
restarts the server.

> More importantly, can you have two copies of the application installed on
> your system, for example for development purposes?

On my local machine, I only have the application installed once and it
is linked to my local git checkout. I think that if you try to install
the same package under multiple names, `raco pkg' will complain. I
can't imagine wanting to have the same application installed multiple
times for development, though, so I don't think I fully grasp your
question.

On my production server, I run the binaries as two separate systemd
services: one for production and another one[1] that I use to test
releases before they go out. Since I only ship distributions to the
production server, I don't need to install any packages. In fact, I
don't even have Racket installed on the production server.

[1]: https://sandbox.matchacha.ro/

Bogdan Popa

unread,
Sep 16, 2019, 6:04:43 AM9/16/19
to Marc Kaufmann, Racket Users

Marc Kaufmann writes:

> So the easiest to do is to create such an info.rkt file and call `raco pkg
> install app-name/` -- and that should work even if I don't do the `raco
> exe` and `raco distribute`?

Yes, that's right. `raco exe' and `raco distribute' are not required.

I realize now that I should've mentioned a couple caveats to treating
apps as packages like this. I often need to tell Racket to recompile my
package after I make certain changes because the interpreter doesn't try
to recompile stale dependent modules of changed modules on the fly (if
`a.rkt' depends on `b.rkt' and you change `b.rkt', without recompiling
`a.rkt', the interpreter won't do it for you). This means you can run
into errors along the lines of "instantiate-linket: mismatch". When
that happens, you can either remove all the compiled bytecode from your
project

$ find app-name-here/ -type d -name compiled -exec rm -rf \{\} \;

or tell Racket to recompile all the modules in your package's collection

$ raco setup --avoid-main --tidy --check-pkg-deps --unused-pkg-deps app-name-here

I usually do the latter, because large projects can take a very long
time to compile/load from scratch. That said, that also comes with its
own downside in the form of worse error reporting. `errortrace' can no
longer peer into the source code since it's been compiled which leads to
some pretty terse error reports.

Darren Newton

unread,
Sep 17, 2019, 8:21:04 AM9/17/19
to Racket Users
I've found Greg Hendershott's Makefiles to be super helpful with this https://www.greghendershott.com/2017/04/racket-makefiles.html

I use that article as a base and then make mods, such as this https://github.com/DarrenN/cuttlefish/blob/master/Makefile
Reply all
Reply to author
Forward
0 new messages