Tic-tac-toe via SSH using Bubble Tea, Golang and Wish
This is a quick guide to deploying a terminal-based Tic Tac Toe game built using Wish and Bubble Tea to Fly.io.
I was looking for a way to build my ideas quickly and let people access them easily. Usually, I’ll spin up a website and build there, but every now and then I get stuck in the weeds of the design, when what I actually want is to focus on building my vision. What better way to do this than by creating a terminal app? But then the question becomes: where and how?
To answer this, I learned about Charm, who offer a ton of libraries that honestly made development so much easier.
To test whether I should use this, I initially decided to create a simple Tic Tac Toe game. The plan was for it to be played couch co-op and for anyone to be able to access it without needing to download a single thing. I used Bubble Tea to build the TUI aspect of it first. As someone in the fun phase of building and failing while learning Go, I found I didn’t really struggle to grasp the concepts needed to build my first app. At first, Bubble Tea wasn’t entirely intuitive, but the documentation is fantastic.
With a working local version of Tic Tac Toe, the next step was figuring out how to deploy it so anyone could play. The next library is Wish, which is an SSH server that let me hook up my Bubble Tea TUI incredibly easily.
Finally, to host my app, I decided to go with Fly.io. There are other platforms available, but many only offer HTTP(S) services, whereas Fly.io allows hosting on any port.
The source code can be found here and the steps to deploying it below.
Step 1: Install the Fly.io CLI
You'll need the `flyctl` command-line tool. Follow the instructions in the official docs, or if you're on Linux, you can run:
terminal
$curl -L https://fly.io/install.sh | sh
Make sure to add it to your `PATH` if it isn't already.
Step 2: Launch the App
In your project directory, run:
terminal
$fly launch --no-deploy --vm-memory 256
When prompted:
Do you want to tweak these settings before proceeding? (y/N)
Type `N`.
This will generate the necessary config files but not deploy it as of now. We will be making changes to the configuration first.
Step 3: Edit the Config
Open the fly.toml
file and update it with the settings for your app.
fly.toml
1app = 'ssh-tictactoe-laurenzguevara'2primary_region = 'lhr'34[build]56[env]7 PORT = '23234'89[[services]]10 internal_port = 2323411 protocol = "tcp"12 auto_stop_machines = true13 auto_start_machines = true14 [[services.ports]]15 port = 221617[[vm]]18 memory = '256mb'19 cpu_kind = 'shared'20 cpus = 12122[mounts]23 source = "ssh_key"24 destination = "/ssh-tictactoe-keys"
So what are we doing here? Initially, a name and a region: in my case, "lhr" is London. Pick the location nearest to your users. We set the port and update the protocol to TCP and the port, which is what SSH listens to. Next, we set the memory to a minimal amount. The default Fly.io gives is a bit too much, and for an app like this it is overkill to go any higher. Finally, we must mount a directory to store our SSH key inside. If we do not do this, the VM will have a random set of keys, which will then cause a warning message to users attempting to connect.
ssh my-app.com
$@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@>>@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @>>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@>>IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!>>Someone could be eavesdropping on you right now (man-in-the-middle attack)!>>It is also possible that a host key has just been changed.>>The fingerprint for the RSA key sent by the remote host is>>xx:xx:xx.>>Please contact your system administrator.
So to prevent this keep the mount and specify the path where we will access the key.
Step 4: Deploy
Finally we have made the changes required so it's now time to deploy our game.
terminal
$fly deploy
When asked:
Would you like to allocate dedicated ipv4 and ipv6 addresses now? (y/N)
Type `y`.
Fly.io will also create a 1 GB volume for the app.
Done
The Tic Tac Toe game should now be up and running on Fly.io. You can connect via SSH and play it from the terminal.
terminal
$ssh ssh-tictactoe-laurenzguevara.fly.dev

Source Code: https://github.com/Laurenz-Guevara/ssh-tictactoe-laurenzguevara