Deployment
DigitalOcean
Introduction
Deploying with DigitalOcean is simple and cheap. You’ll just need to create a droplet, install Swift, and run your project.
Deploy to a Droplet
First, create a new droplet with the image of your choice, for this guide we’ll use Ubuntu 22.04 (LTS) x64
. You can see the supported Swift platforms here.
Install Swift
Once your droplet is created, ssh into root@<droplet-public-ip>
and install Swift with the official Linux Swift installer.
curl -L https://swiftlang.github.io/swiftly/swiftly-install.sh | bash
Enable Firewall
You’ll need to allow HTTP through your droplet’s firewall.
sudo ufw allow http
Run Your App
Now that Swift is installed, you can just run your app. Start by cloning it.
git clone <project>
Then run it on 0.0.0.0:80
. This will make it available from your droplet’s public IP.
The first time you compile the app it will take a bit, especially if the droplet you created is very small. Future compiles will be much faster.
cd <project>
swift run app --host 0.0.0.0 --port 80
Visit <droplet-public-ip>
in the browser and you’ll see your app running.
Nicely done, your project is live on DigitalOcean!