1. 99
  1. 14

    Congrats. A true hacker project, as it should be. This was an epic entry. Such a joy to read. Keep up.

    1. 7

      Impresses me each time I see updates, but I can’t help but ask this time: isn’t this a huge, massive hack, which can’t guarantee to work for a long long time? Isn’t this difficult for others to recreate, or stumble upon themselves initially? Is it a good idea to employ such a hack?

      Regardless of the doubt, I still think is a very cool path to follow as /u/jart continues to traverse down it. Thank you!

      1. 11

        It’s a gorgeous hack! It’s also a hack you can count on. When I started working on this project several years ago, we talked to the Austin Group (POSIX committee) to get the rules changed to allow redbean to be possible. Earlier versions of the UNIX standard recommended that shell scripts with NUL characters not be run. Thanks to the support of the FreeBSD team, we managed to get that restriction loosened. Here’s the patch I sent to the zsh shell which cites the standard: https://github.com/zsh-users/zsh/commit/326d9c203b3980c0f841bc62b06e37134c6e51ea

        As for the way we interface with the operating systems, as described in my https://justine.lol/ape.html writeup, binary syscall interfaces are usually the most stable. They never ever break on Linux (unlike userland DSOs) and platforms generally can’t break these interfaces without breaking themselves. So long story short, rational self interest is what’s going to ensure your programs have a long future to look forward to, just like the Super Mario Bros ROM. It’s also the reason why your APE programs will just work on all Linux distros, including ones dating back to RHEL5 (CentOS 5).

        1. 6

          Earlier versions of the UNIX standard recommended that shell scripts with binary content not be run.

          A clever hack, but … On a deep visceral level I’m very bothered by the security implications. I’m glad that I went with mksh, which does the safe thing:

          mksh: ./redbean.com: not executable: magic 4D5A
          1. 1

            we talked to the Austin Group (POSIX committee) to get the rules changed


        2. 3

          Amazing project.

          It seems like container images are more useful as a deployable artifact for network services. I can pay to host a container image at tons of hosting services (e.g. ECS) but no hosting service will support a bare executable. This is great for running something locally – no end user is going to install Docker so they can run an image locally.

          How do I update it? Can I copy 2.1 over the 2.0 binary without losing my data?

          I also didn’t see any notes on sqlite and how to manage its persistent data. Can I back it up or replicate it? Is sqlite meant to be completely read-only with a pre-loaded SQL database?

          1. 3

            Are virtual machines in the cloud not a hosting service? The value of redbean is you can just scp it onto any host and run it. Any program that has access to the UNIX system() function can run your redbean. SQLite is supported both for read-only and read-write. For example, its WAL mode is particularly good. You do need a second file for the SQLite database. However, redbean also has a StoreAsset function that lets you programmatically use the zip executable structure itself as a self-modifying object store.

            1. 1

              A VM still needs to be administered. Containers don’t. I guess you are targeting technical users whereas I’m thinking if it’s possible to have truly non-technical users who might want to spin up their own instance of some redbean app.

              My thought is “could this power a truly decentralized app like Mastodon where everybody runs their own microinstance?”

              1. 1

                If we provided a service for hosting your redbean containers and editing them in the browser, would you use it?

                1. 1

                  I’m just thinking aloud currently. I can imagine this providing the backend for phone apps that run completely decentralized. Your service would just provision redbean instances using some well-defined container image. Imagine Twitter where your messages are fanned out to your subscribers. This could make an amazing tightly contained blogging platform. These are all really conventional ideas but there’s so much potential in mono-user services.

                  The only drawback I’ve seen so far is lack of ARM64 support but that’s not critical if you choose the hosting hardware.

            2. 3

              I haven’t tried it, but I think this would be a valid Docker file for Redbean:

              FROM scratch
              ENV PATH=/bin
              ADD ape.com /bin/ape
              ADD redbean.com /bin/redbean

              It’s no different from any other static binary like a Go executable; if you want to wrap it in Web Scale Computing Primitive, I think it should work fine.

              If you’re worried about updating redbean from upstream as a developer, use a build process instead of editing the zip manually. Just like go command compiles go code, zip command compiles redbean code:

                cp deps/redbean.com build/app
                zip build/app src/*

              As for files and end-user upgrading, nothing forces redbean to store user data inside the zip. Like SQLite, you could write all data adjacent to the executable, or to %USERDATA% or ~/.myapp.

              1. 2

                Great stuff! This was also shared by Loam on our Discord server:

                FROM alpine AS builder
                RUN wget https://redbean.dev/redbean-tiny-2.0.1.com -O /redbean.com \
                    && chmod +x /redbean.com \
                    && /redbean.com --assimilate
                FROM scratch
                COPY --from=builder /redbean.com /
                EXPOSE 8080/tcp
                VOLUME /src
                ENTRYPOINT ["/redbean.com", "-D", "/src"]

                You should come join us! https://discord.gg/EZwQUAcx

                1. 1

                  why do you use discord?