Language support on Glitch: a list


So, as a few of my posts here have hinted at so far, I’ve been experimenting with other languages on Glitch, seeing what I could get working just with what’s installed on the container. I’ve especially been focusing on compile-to-JS languages that are available on NPM because of the space savings from pnpm and caching.

I thought it might be helpful to keep a list of what I’ve discovered so far. Feel free to comment with your own experiments

Native languages:

  • Java: OpenJDK 1.8 and Maven are present. Otherwise untested.
  • .NET: .NET Core 2.1 is installed including the dotnet CLI tool along with the ASP.NET runtimes. I was able to compile a basic F# HelloWorld using this guide. See also Fable below.
  • Python: both Python 2.7 and 3.5 are installed as well as pip. There is a hello world starter glitch for Python/Flask available for remix.
  • Go: A template exists for a Go app using the gin framework, but it no longer works as the go binary no longer seems to be present on the container.
  • Rust: Works. I was able to build a hello-rust template using the Iron framework for the backend. Note that due to disk space premium, some of the more popular options like actix-web and nickel were a no go: they run out of disk space during compilation.
  • Other langs found in ls -al /usr/bin but untested:
    • C/C++. Both gcc and clang. Also LLVM tools.
    • Haskell. ghc, haddock, and cabal are installed.
    • OCaml. the OCaml compiler and camlp4 are installed.
    • Perl. including CPAN.
    • Erlang.
    • Elixir.
    • Lua 5.2.
    • PHP and/or PHP7.
    • Ruby, including Rails
    • Swift

Compile to JS languages:

  • Typescript: Installs via npm. Not tested personally, but unsurprisingly seems to work just fine as there’s a number of projects using it, including several “hello world” type starter apps to remix.
  • Elm: Installs via npm, works great. Have written several little projects, including a hello world to start with. Slight gotcha here: for some reason the “add dependency” tool finds some very ancient version of Elm labeled “2.0.0” rather than the actual current version of 0.19, so it’s best to manually install this.
  • ClojureScript: Can install the lumo-cljs compiler via npm, and basic compilation works, as well as backend node dependencies. However a bug in the CLJS compiler seems to break library imports for frontend applications due to how it handles symlinks. I’ve talked this over with Lumo’s dev and a fix may come, but he’s quite busy with other projects at the moment.
  • Fable: F# to JS compiler. Works! I’ve built a project from the minimal Fable template here. Note that the deps do eat quite a bit of disk space.
  • Bucklescript: OCaml to JS compiler, also used for Facebook’s Reason. Works, but you must install via the GUI “add package” tool in the editor. If you install manually at the console it will “lose” the built bsb compiler on the next restart. Also the initial install takes a very long time as it has to build the compiler from source, but restart time seems to be fine after that. I’ve created a hello-world demo.
  • Purescript: You can install the Purescript tools if you first run enable-npm in the console. I’ve created a very simple hello-purescript for using PS with Bower. psc-package seems to fail on installing packages, so can’t recommend that.

Some other notes from my experimentation:

  • If you start from the node-app/hello-express project template, Glitch will run the project with pnpm install --shamefully-flatten && npm start, and the sample code hosts the static index.html via Express through a random forwarded port. This is useful for compile-to-JS languages at least, as you can just customize the start script to compile your language of choice, and then have the index.html point to your build output for the JS.
  • Because of this setup and the way Glitch “restarts the world”, optimization is kind of a tradeoff here: it’s probably best to use optimized output for payload’s sake if nothing else, but this will also slow down the startup time of the instance.
  • The hello-webpage/webpage starter template on the other hand does not have node installed, but does have Python, OpenJDK, and .NET Core installed still.
  • The Python/Flask template instead uses a bash script to start the server. I haven’t experimented with this, but maybe this might prove a more flexible start for other language experiments since it’s not depending on npm.
  • The Go template however instead uses a glitch.json file, which contains two keys, start and install, which appear to just be commands for Glitch to run when starting the app. It does seem to work too; the template fails, because the go binary isn’t available, but it does try to run the command given in the start key.
  • Disk space is very limited. Disk space is only 200MB, so that limits the amount of space we have for dependencies, installing additional tools, etc. npm dependencies are sort of an exception though, as much of that is cached by pnpm and Glitch so that it doesn’t count against the instance size limit.
  • RAM is a bit tight. Instance has 512MB of RAM, which is not bad for lightweight servers, but not good for running big toolchains in memory. When writing your build scripts, don’t bother with live reloading tools and the like, since Glitch will restart the whole server on change anyway. Compile once.
  • Glitch expects a listening server to be running after it does start. If it doesn’t find one, it will just restart the server in a loop. I had a hell of a time figuring out why my Fable template was doing this. :smiley:
  • The port that the Glitch proxy will pick up to serve as the web server can be found from the environment variable PORT. This usually seems to be 3000, but it’s best to use the env var.

I hope this is helpful, and if any of the Glitch folks have further insights on some of the unclear stuff, or you’ve done your own experiments feel free to share. I’ll try and keep this post updated.

Updated: 25-Oct-2018

Can we add other runtimes to containers?