Reduce Cost of Aws Bill - Part 1

Developing and deploying to the cloud has become a mandatory requirement than a nice to have skill. The promise of the cloud is that it abstracts all the complexity of managing a server and you only pay for what you use. If you accept that at face value, then the cloud is 100% legit. You only pay for what you use (just the cost is high), and they do abstract the regular complexity, and create some new complexity to worry about. There is a reason why AWS offers certificate programs. AWS Certified Cloud Practitioner/Architect/SysOps Admin/Developer/Solution Architect/Dev Ops Engineer all these shouldn’t be there if all the complexity were truly abstracted.

Now that I have finished writing my frustration about cloud, lets return to the main topic of this article. Recently I was tasked with reducing our AWS bill. Our general approach to reduction in system performance have been to increase the server spec or DB spec. Looking at which resource was maxing out. DB or Server.

Speed Up Docker Build using cache

Docker has become a popular tool in recent years for building and deploying applications in a portable and scalable way. However, the build process can sometimes be slow, especially for large applications with many dependencies. In this article, we’ll explore how we can optimize our Dockerfile to speed it up.

When building a rails app for production we would need to do the following steps in the docker file

1
2
3
4
COPY . .
bundle install
yarn install
bundle exec rails assets:precompile

Docker after building each step it will cache that step. If the instructions/context of that steps or steps before haven’t change then docker will use the cache.

So we need to make docker understand that there is no change, hence we can use the cache instead of rebuilding it.

Setup NFS Server on Ubuntu

NFS - Network File System is a distributed file system protocol developed by Sun Systems. It facilitates a client computer to have access to file/folder over network like a local folder. This is a easy/simple way to provide persistant storage for your docker-swarm or kubernetes cluster. In both these cases, the container (or pod) run on one of the available nodes (servers), and when we have replicas it will be running on more than one node. So local storage on the server is out of the question.

With NFS we can directly mount the folder in the container. We can control everything from the configuration file. And thanks to the NFS storage we can increase and reduce node without worries as well.

Wildcard Domain in Pi Hole

PiHole is a DNS server that will block ads and website on a DNS level. This is an integral part of my homelab as it blocks a lot of ads on my phones and system, and also easily allows us to manage domains for local application.

For homelab I have a docker-swarm which is managed using portainer. I have a nginx proxy manager to map the ports to a proper domain, even provide https using lets encrypt.But PiHole doesn’t have a wildcard domain setting, hence after i set or before i set a domain my nginx proxy I need to add it to PiHole.