Serve small with Fly.io and GoStatic

Static websites are great for carrying unchanging content, be it assets, images, fonts or even, as in this case, an entire site. Well, I say entire site, but if you saw my last article, you’ll know I recently rebranded a Maker organization and needed

Dj Walker-Morgan
5 min readbeginner
--
View Original

Overview

The article discusses how to deploy a small static website using Fly.io and GoStatic, emphasizing the benefits of minimal Docker image sizes and efficient deployment processes. It provides a step-by-step guide for setting up a static web server with a focus on reducing costs and resource usage.

What You'll Learn

1

How to deploy a static website using Fly.io and GoStatic

2

Why using minimal Docker images can reduce deployment costs

3

How to configure port routing for GoStatic on Fly.io

Key Questions Answered

How do you deploy a static website with GoStatic on Fly.io?
To deploy a static website with GoStatic on Fly.io, create a project using 'fly init' with the '-p 8043' option to route traffic correctly. Then, set up a Dockerfile with the GoStatic image and copy your 'index.html' to the appropriate directory. Finally, run 'flyctl deploy' to complete the deployment.
What are the benefits of using GoStatic for static websites?
GoStatic provides a lightweight solution for serving static websites, with a Docker image size of only 6MB compared to larger official Golang images. This minimal footprint helps reduce deployment costs and resource usage, making it ideal for simple static content.
What is the default port used by GoStatic?
GoStatic uses port 8043 by default. When initializing a project on Fly.io, it is important to specify this port to ensure proper routing of traffic from ports 80 and 443.
How does Fly.io handle HTTPS for deployed applications?
Fly.io automatically manages HTTPS connections for applications deployed on its platform, allowing developers to focus on building their applications without worrying about SSL certificates or HTTPS configuration.

Key Statistics & Figures

Docker image size for GoStatic
6MB
This is significantly smaller than the official Golang images, which can be as large as 500MB.
Default Fly.io VM size
512MB of RAM and a quarter of a virtual CPU
This is the standard allocation for new applications deployed on Fly.io.
Scaled VM size to micro-1x
128MB of RAM
This adjustment can help reduce running costs for applications with minimal resource requirements.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Key Actionable Insights

1
Consider using GoStatic for your next static website project to minimize resource usage and costs.
GoStatic's small Docker image size allows for efficient deployments, making it a cost-effective choice for hosting static content.
2
Utilize Fly.io's automatic HTTPS management to simplify your deployment process.
By letting Fly.io handle HTTPS, you can save time and avoid the complexities of managing SSL certificates.
3
Optimize your Dockerfile by using multi-stage builds to keep your image size small.
This practice not only reduces deployment times but also improves the performance of your application by minimizing unnecessary layers.

Common Pitfalls

1
Neglecting to specify the correct port when initializing the Fly.io project can lead to routing issues.
Always remember to add '-p 8043' to the 'fly init' command to ensure traffic is routed correctly to the GoStatic server.
2
Using larger base images can unnecessarily increase deployment costs.
Opt for smaller images like GoStatic to keep your deployments efficient and cost-effective.

Related Concepts

Docker Best Practices
Static Site Generation
Cloud Deployment Strategies