Build Log #5 - Routing traffic with Traefik

May 19, 2025

🛠️ What I Worked On

Finally getting Traefik to work, networking and bug fixes.


🚪 Traefik

TTraefik is a reverse proxy and load balancer, similar to Nginx or Caddy, well suited for containerized environments due to its ability to automatically discover and route traffic to new containers.

The issues I was having with Traefik were simple in hindsight, the labels and environment variables needed to start the application in automatic container discovery mode weren't being set on deployment. This wasn't exactly an issue with Traefik but with Serversinc and Tugboat's management of Container labels so there were various smaller bug fixes across both codebases to ensure Containers were created properly.

However, even with all the bugs fixed in Serversinc, the Traefik container still wasn't routing requests properly. After a bit of googling, I found out Traefik doesn't play well with the default Docker network and so wasn't discovering new containers. The fix was simple: I added a line in the server setup script to create a custom Docker network and made sure all containers use it by default.

Once that was in place, everything clicked. Now, when an application gets deployed, Traefik picks it up automatically and routes traffic to it as long as the new container contains the correct labels. I added an extra button to the labels screen to add these labels in.


🐛 Various Bug Fixes and Testing

There were various bug fixes done around the system. One in particular meant that saving Environment Variables would duplicate them and then the whole deployment process became a mess so that was fixed.

Whilst going through the system again and fixing bugs, I also wrote tests for the complex parts such as provisioning a new server or deploying an application for the first time. This improved my confidence across the system as the most complex parts are rigorously tested every time a new feature is added or something is refactored.


🚀 Improved DX

I took some time to improve the developer experience on the project by adding a few background tasks to VS Codes .vscode/tasks.json file.

As the project is built on Laravel 12, I run composer dev to start the app, vite and queues and a Cloudflare tunnel to route requests from a test domain to the app running locally. Before the tasks file update, I'd open two terminals side by side and type out the commands. Now, once VS code has opened the app's folder, it'll start both commands side by side in the terminal automatically.

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Laravel Dev",
            "type": "shell",
            "command": "composer dev",
        },
        {
            "label": "Cloudflare Tunnel",
            "type": "shell",
            "command": "npm run tunnel",
        },
        {
            "label": "Start Dev Environment",
            "dependsOn": [
                "Laravel Dev",
                "Cloudflare Tunnel"
            ],
        }
    ]
}

✅ Wins

  • Traefik auto-routing & discovery
  • Improved DX
  • Test coverage for most complex parts.
  • Containerize the app & swap databases to PostgreSQL

⚠️ Challenges

  • Traefik docker configuration - Not a huge challenge, but certainly highlighted parts of Serversinc that are currently lacking (i.e no network control from the dashboard).

💡 What I Learned

  • Traefik doesn't like the default network
  • New features I could add in the future, i.e network control

🔜 Next Up

  • Billing & Organisations
  • More testing
  • Launch (hopefully!)

Share this post: