Hi folks. Today, I want to touch on a topic about the cloud alternative. All of us talk about code, but too few words are said about how to share this code. Most people have heard a lot about Azure, AWS, GCP, and even DigitalOcean. For newbies, it can be too complicated and need additional knowledge. And you don't always need all these multiple features. You just need to deploy your small application and scale it if needed.
I want to tell you how easy it is to deploy your application without any special knowledge about infrastructure. I'll detail to tell you about it step by step.
Step1
Let's generate a simple MVC project.
dotnet new mvc -n FlyIoSample
Go to the folder with the project.
cd FlyIoSample
Let's check this out to ensure that it works fine.
Step2
We must download and install CLI for fly.io. If you use Windows, you can download the installer by this link. Or you can also use PowerShell script as well.
iwr https://fly.io/install.ps1 -useb | iex
If you use NIX systems, you can run a bash script.
curl -L https://fly.io/install.sh | sh
Or you can use a more elegant way with homebrew.
brew install flyctl
Step 3
Most of you don't have an account on fly.io, and for this reason, follow this instruction:
fly auth signup
If you already registered, then you need to log in:
fly auth login
You should see something like this:
Opening https://fly.io/app/auth/cli/c62de925b715fafca3245a9016ec3e0f ...
Waiting for session... Done
successfully logged in as korols83@gmail.com
Step 4
Go to your dashboard https://fly.io/dashboard. You have a free hobby plan for non-commercial use.
There is one crucial action. You must add your credit/debit card. Don't worry. This service won't withdraw any money. You can add an empty card with a zero balance.
Step 5
Let's start to deploy the application. You need to run this command:
fly launch
You'll see this information. It's what will be configured for your application.
Scanning source code
Detected a .NET app
Creating app in /Users/serhiikorol/RiderProjects/FlyIoSample
We're about to launch your .NET app on Fly.io. Here's what you're getting:
Organization: Serhii Korol (fly launch defaults to the personal org)
Name: flyiosample (derived from your directory name)
Region: Warsaw, Poland (this is the fastest region for you)
App Machines: shared-cpu-1x, 1GB RAM (most apps need about 1GB of RAM)
Postgres: <none> (not requested)
Redis: <none> (not requested)
And also, you'll see this question:
Do you want to tweak these settings before proceeding? (y/N)
It would help if you typed 'y'.
You'll be automatically redirected to the page with the configuration that needs to be confirmed. Pay attention that the name of the application must be unique.
If everything is good, you'll see this information:
Waiting for launch data... Done
Created app 'flyiosample' in organization 'personal'
Admin URL: https://fly.io/apps/flyiosample
Hostname: flyiosample.fly.dev
Wrote config file fly.toml
Validating /Users/serhiikorol/RiderProjects/FlyIoSample/fly.toml
Platform: machines
✓ Configuration is valid
==> Building image
Remote builder fly-builder-weathered-glitter-6371 ready
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
As you might have noticed, the flyctl
created your project's fly.toml
file. It contains the minimal deploy configuration:
# fly.toml app configuration file generated for flyiosample on 2023-11-19T09:35:01+02:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = "flyiosample"
primary_region = "waw"
[build]
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ["app"]
After flyctl
finishes pushing the Docker image, you'll see an invitation to visit your deployed application.
image: registry.fly.io/flyiosample:deployment-01HFK829P639MJ9DDS4HVKBEHN
image size: 220 MB
Watch your deployment at https://fly.io/apps/flyiosample/monitoring
Provisioning ips for flyiosample
Dedicated ipv6: 2a09:8280:1::69:aa45
Shared ipv4: 66.241.125.123
Add a dedicated ipv4 with: fly ips allocate-v4
This deployment will:
* create 2 "app" machines
No machines in group app, launching a new machine
Creating a second machine to increase service availability
Finished launching new machines
-------
NOTE: The machines for [app] have services with 'auto_stop_machines = true' that will be stopped when idling
-------
Visit your newly deployed app at https://flyiosample.fly.dev/
Step 6
Let's check this out that we did get.
By the way, you can easily open your application with the command:
flyctl apps open
Step 7
And last, what you need to know. If your project deployed and you changed the application, then you should use another command:
fly deploy
Also, you can check the status of your deployment:
fly status
It'll be like this:
App
Name = flyiosample
Owner = personal
Hostname = flyiosample.fly.dev
Image = flyiosample:deployment-01HFK829P639MJ9DDS4HVKBEHN
Platform = machines
Machines
PROCESS ID VERSION REGION STATE ROLE CHECKS LAST UPDATED
app 148ed124c93798 1 waw stopped 2023-11-19T07:51:47Z
app 6e82de57ad4058 1 waw stopped 2023-11-19T07:42:59Z
Another command shows used IP addresses:
fly ips list
Bonus
If you want to deploy a static application, then you need to add a Dockerfile with the content:
FROM pierrezemb/gostatic
COPY ./public/ /srv/http/
Your static files will be copied to this image.
Conclution
I showed you a super-friendly and easy cloud service for deploying your applications. It can be helpful for demos, pet projects, and even technical tasks when looking for a job. This cloud service will be beneficial for newbies who don't have enough experience with Azure.
Thanks for reading. See you on the following week. And for sure, happy coding!