Dokku:我最喜欢的个人无服务器平台
Dokku: My favorite personal serverless platform

原始链接: https://hamel.dev/blog/posts/dokku/

Dokku 是一个免费、自我管理的平台即服务 (PaaS),允许用户在自己的服务器上部署和管理应用程序。 它与 Heroku 等流行服务类似,但由于不是外部托管,因此成本较低。 用户可以在虚拟专用服务器 (VPS)(例如 OVHcloud 提供的服务器)上运行 Dokku。 这样可以在一个简单、易于使用的界面中高效部署各种应用程序,包括 Node、Python 等。 Dokku 的一项独特功能是通过 Let's Encrypt 进行自动 SSL 证书管理。 此外,它还支持基本身份验证,以通过密码保护来保护站点。 还可以使用单个命令快速扩展或缩小应用程序。 此外,还有许多可用的插件可以扩展功能。 部署涉及创建 Doker 容器,其中 Dockerfile 放置在存储库的根目录下,入口点脚本设置运行时环境。 将应用程序添加为远程主机后,可以使用 git 命令将应用程序直接推送到 Dokku 主机。 静态站点还可以通过 Dokku 私下部署,这使其成为某些场景下 GitHub Pages 的有吸引力的替代方案。 与 GitHub Pages 相比,它提供了增强的安全功能,并支持基本身份验证和 Let's Encrypt 插件,以增加便利性。 最后,与 GitHub Actions 的集成可实现自动化部署流程,从而节省时间并减少更新应用程序时的手动干预要求。 总体而言,Dokku 为管理和扩展现代 Web 应用程序提供了灵活、高效的解决方案,同时提供了一系列自定义选项。

用户比较Dokku和Serverless架构。 然而,Dokku 是一个平台即服务 (PaaS) 解决方案,而不是真正的无服务器解决方案。 Dokku 允许开发人员使用容器、构建包和编排来托管和管理自己的应用程序。 虽然 PHP 在技术上可以充当无服务器平台,但由于其他因素,它并不常用。 用户无法找到有关 Dokku 在其系统内管理数据库和队列的能力的信息,这表明对 Dokku 的功能存在潜在的误解。 Dokku 提供了多个插件来扩展其功能,使其能够与应用程序一起处理数据库和队列。 Dokku 被认为是开源 Heroku,具有类似的功能,但具有更大的灵活性和对基础设施的控制。 最后,用户提到了维护和支持 32 位 ARM 架构的困难,建议使用 piku 等可能的替代方案。
相关文章

原文

With Dokku, you can turn a VPS into a powerful serverless platform

What is Dokku?

Dokku is an open-source Platform as a Service (PaaS) that runs on a single server of your choice. It’s like Heroku, but you own it. It is a great way to get the benefits of Heroku without the costs (Heroku can get quite expensive!). I need to deploy many applications for my LLM consulting work. Having a cost-effective, easy-to-use serverless platform is essential for me.

I run a Dokku server on a $7/month VPS on OVHcloud for non-gpu workloads. These applications include things like nbsanity and data cleaning tools for LLMs.

Some of the features I love about Dokku:

  • Easy to use (like Heroku).
  • Automatic SSL certificate management via Let’s Encrypt.
  • Basic Auth support so I can password-protect sites.
  • Scale up and down with a single command.
  • Flexibility to handle any application (Node, Python, etc), including defining a Docker container.
  • Lots of official plugins that do almost anything I want.
  • Easily deploy with git commands.

Make sure you install Dokku on your VPS. As I mentioned, I use OVH.

Deploying Apps as A Docker Container

An easy way to deploy applications is with a Docker container.

To deploy a Docker container, I put a Dockerfile in the root of my git repo like this:

Dokku docs.

Static Sites

GitHub Pages is annoying in that you can’t easily deploy private static sites without paying for an expensive Enterprise account. With Dokku, you can easily deploy a static site from a private GitHub Repo and password-protect it.

We will assume that you have a static site in a git repo in a folder named _site.

On the Dokku host, create an app named mysite and set the NGINX_ROOT environment variable to _site:

basic auth and set permissions so the plugin can work properly.

in the previous section.

Finally, deploy your application:

You can now add auth by running the following command on the Dokku host:

It’s often desirable to have HTTPS for your site. Dokku makes this easy with the Let’s Encrypt Plugin, which will even auto-renew for you. I don’t use this, because I’m letting Cloudflare handle this with its proxy.

If you are using Cloudflare this way, activating this plugin will mess things up (don’t worry its easy to disable). Honestly, I think it’s easier to let Cloudflare handle it if you are already doing so.

You can automatically deploy Dokku apps with GitHub Actions, which is helpful if you don’t want to fiddle with pushing to the Dokku host. Here is an example GitHub Action workflow that does this:

invalidate the docker cache for a fresh build:

many ways to do this, but one way is like this: