MicroBin on Fly.io
Published: 2023-05-17 15:00:03

MicroBin is a super tiny, feature rich, configurable, self-contained and self-hosted paste bin web application. It is very easy to set up and use, and will only require a few megabytes of memory and disk storage.

**Fly.io**
Fly.io is a platform for running full-stack applications and databases close to the users without any DevOps. You can deploy your apps to Fly.io (it's about the simplest place to deploy a Docker Image) and use our CLI to launch instances in regions that are most important for their application.


**Structure of MicroBin**

**_Step 1:_**
Clone your repository

```
git clone https://github.com/manjularajamani/microbin.git
cd microbin/
```

**_Step 2:_**
Using Dockerfile(or pre-built Docker images)we can able to deploy the application on the fly.io app server

```
FROM rust:latest as build

WORKDIR /app

COPY . .

RUN \
  DEBIAN_FRONTEND=noninteractive \
  apt-get update &&\
  apt-get -y install ca-certificates tzdata &&\
  CARGO_NET_GIT_FETCH_WITH_CLI=true \
  cargo build --release

# https://hub.docker.com/r/bitnami/minideb
FROM bitnami/minideb:latest

# microbin will be in /app
WORKDIR /app

# copy time zone info
COPY --from=build \
  /usr/share/zoneinfo \
  /usr/share/zoneinfo

COPY --from=build \
  /etc/ssl/certs/ca-certificates.crt \
  /etc/ssl/certs/ca-certificates.crt

# copy built executable
COPY --from=build \
  /app/target/release/microbin \
  /usr/bin/microbin

# Expose webport used for the webserver to the docker runtime
EXPOSE 8080

ENTRYPOINT ["microbin"]
```
Or fetch Docker image from [DockerHub: danielszabo99/microbin:latest
](https://hub.docker.com/r/danielszabo99/microbin)

**_Step 3:_**

**_Install flyctl_:**
flyctl is a command line interface to the Fly.io platform.It allows users to manage authentication, application launch, deployment, network configuration, logging and more with just the one command.Install [Flyctl CLI](https://fly.io/docs/hands-on/install-flyctl/) 

**_Sign In_:**
If you already have a Fly.io account, all you need to do is sign in with flyctl

```
fly auth login
```
Your browser will open up with the Fly.io sign-in screen, enter your user name and password to sign in.

**_Step 4:_**
To deploy app into fly.io we need a `fly.toml` file

```
app = "microbin"
primary_region = "ams"
kill_signal = "SIGINT"
kill_timeout = "5s"

[experimental]
  entrypoint = ["microbin", "--highlightsyntax", "--private", "--qr", "--editable", "--enable-burn-after"]

[build]
  image = "danielszabo99/microbin:latest"

[[mounts]]
  source = "microbin_data"
  destination = "/app/pasta_data"

[http_service]
  internal_port = 8080
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
```
I've added only a few things that are enough for micro bin

- _**kill_signal:**_
The kill_signal option allows you to change what signal is sent so that you can trigger a softer, less disruptive shutdown. 

- _**kill_timeout:**_
When shutting down a Fly app instance, by default, after sending a signal, Fly gives an app instance five seconds to close down before being killed.


- _**experimental:**_
 This section is for flags and feature settings which have yet to be promoted into the main configuration.

- _**build:**_
The image builder is used when you want to immediately deploy an existing public image

- _**mounts:**_
This section supports the Volumes feature for persistent storage

- _**auto_stop_machines**_:
Whether to automatically stop an application's machines when there's excess capacity, per region.

- _**auto_start_machines**_:
Whether to automatically start an application's machines when a new request is made to the application and there's no excess capacity, per region.

**_Step 5:_**

_**Launch an App on Fly:**_
Fly.io enables you to deploy almost any kind of app using a Docker image.

```
flyctl launch 
      (or)
flyctl launch --image danielszabo99/microbin:latest
```
If you need to edit `fly.toml` and redeploy use the below command

```
flyctl deploy
```
_**Check Your App's Status:**_
The application has been deployed with a DNS hostname of `microbin.fly.dev`. Your deployment's name will, of course, be different. `fly status` give us basic details

```
flyctl status
```

**_Step 6:_**
The DESTROY command will remove an application from the Fly platform.

```
flyctl destroy <APPNAME>

```


**Adding Custom Domains**
Fly offers a simple command-line process for manual configuration of custom domains and for people integrating Fly custom domains into their automated workflows.

**_Step 1:_**
 Run `flyctl ips list` to see your app's addresses

```
flyctl ips list
```
Create an A record pointing to your v4 address, and an AAAA record pointing to your v6 address on your respective DNS.

**_Step 2:_**
You can add the custom domain to the application's certificates.

```
flyctl certs create <domain.name>
```
**_Step 3:_**
You can check on the progress by running the below command

```
flyctl certs show <domain.name>
```
Once the certificate is issued you can access your application to your Domain

**_Step 4:_**
To removes the hostname from the application, dropping the certificates in the process.

```
flyctl certs delete <domain.name> 
```