Deploying a redbean app to Fly#
redbean is a fascinating project - it provides a web server in a self-contained executable which you can add assets (or dynamic Lua code) to just by zipping them into the same binary package.
I decided to try running it on Fly. Here’s the recipe that worked for me.
The Dockerfile#
I copied this Dockerfile, unmodified, from https://github.com/kissgyorgy/redbean-docker/blob/master/Dockerfile-multistage by György Kiss:
1FROM alpine:latest as build2
3ARG DOWNLOAD_FILENAME=redbean-original-2.0.8.com4
5RUN apk add --update zip bash6RUN wget https://redbean.dev/${DOWNLOAD_FILENAME} -O redbean.com7RUN chmod +x redbean.com8
9# normalize the binary to ELF10RUN sh /redbean.com --assimilate11
12# Add your files here13COPY assets /assets14WORKDIR /assets15RUN zip -r /redbean.com *16
17# just for debugging purposes18RUN ls -la /redbean.com19RUN zip -sf /redbean.com20
21
22FROM scratch23
24COPY --from=build /redbean.com /25CMD ["/redbean.com", "-vv", "-p", "80"]
It uses a multi-stage build to download redbean, copy in the contents of your assets/
folder, zip those back up and then create a TINY container from scratch
that copies in just that executable.
I made an assets/
folder with something fun in it (a copy of my Datasette Lite app) like this:
1mkdir assets2cd assets3wget https://lite.datasette.io/index.html4wget https://lite.datasette.io/webworker.js
Deploying to Fly#
First I needed to create a new application. I ran this:
1fly apps create redbean-on-fly
Then I needed a fly.toml
file. I created this one (copied from a previous example, but I updated the internal server port and the name):
1app = "redbean-on-fly"2
3kill_signal = "SIGINT"4kill_timeout = 55
6[[services]]7 internal_port = 808 protocol = "tcp"9
10 [services.concurrency]11 hard_limit = 2512 soft_limit = 2013
14 [[services.ports]]15 handlers = ["http"]16 port = "80"17
18 [[services.ports]]19 handlers = ["tls", "http"]20 port = "443"21
22 [[services.tcp_checks]]23 interval = 1000024 timeout = 200025 grace_period = "10s"
Finally, I deployed the app by running this in the same directory as fly.toml
:
1fly deploy
This uploaded the Dockerfile
and assets/
folder to Fly, ran the build there, then deployed the result.