Deploying on Linux

For when you're ready to go public with your bot.

Right now, the bot is running on your computer. That's not a great solution, because if you shut down your computer, your bot will go offline. The solution to this is to get a server to run your bot, but there are a few things to keep in mind when doing so:

  1. You should build your bot for release to enable performance and other optimisations. It's relatively simple to do so, just build the package with this command:

swift build -c release
  1. If the server you plan to use to host your bot runs Linux, you're gonna have to build your bot on Linux. Unfortunately, Swift does not support cross-compilation at the moment. So if you're on macOS, you'll have to spin up a (Linux) VM, or compile your bot on the server itself.

  2. If you are deploying to a Linux server that does not have Swift installed on it (you probably are), you need to statically link to the Swift stdlib. It will inflate your binary's size by a lot (In testing, it inflated from 38MB to 90MB), but it's worth doing so. The whole swift toolchain is much larger than 52MB, after all. Thankfully, it's easy to do that, just compile with this command:

swift build -c release --static-swift-stdlib

After you compile your bot, you can find the final executable at .build/release/<name of your package>

Last updated