•Updated: Mar 4, 2020
•Published: Sep 25, 2018
Winds is a popular RSS and Podcast application provided by Stream – a service that allows you to build news and activity feeds in hours instead of months. Because Stream values collaboration and the opinions of our users, Winds is 100% open-source and the backend is easy to install in a local environment or in the cloud. Fabric, a tool that we’ll be using in this tutorial, is a Python library and command-line tool for streamlining the use of SSH for application deployment and administration tasks. It’s an extremely powerful tool, however, for sake of time, we’ll only be touching the very basics of what is possible with Fabric. To ensure that you make it through the tutorial, please make sure to complete all of the prerequisites.
As with any tutorial, there are some requirements that come with it. For this post, you’ll need to ensure that you have the following up and running, and ready to go prior to continuing on. If you decide to skip the requirements, you’ll likely get hung up at some point along the way – and we don’t want you throwing your computer against the wall when you get frustrated. 😉 Please make sure you’ve got:
- An account on DigitalOcean with billing enabled and your SSH key set
- A fresh clone of Winds from https://github.com/GetStream/Winds
- An account with MongoDB Atlas or another MongoDB provider (we recommend MongoDB Atlas)
- A free account with Stream
- An instance of Redis – we recommend AWS ElastiCache (copy the URI as you’ll need it shortly)
- A free API key from Mercury (this handles RSS article parsing, so it’s very important)
- A free set of credentials from Algolia
- A domain name configured for use on DigitalOcean
Creating and Configuring Your Droplet 💧
Under the “Manage” section of your DigitalOcean dashboard, there will be an option for “Droplets”. Click “Droplets” and then click “Get Started with a Droplet”. Follow the instructions below:
- Choose your image (Ubuntu 18.0.4 x64)
- Choose a size (1GB @ $5/mo.)
- Choose data center region (New York - 1)
- Add your SSH key (for me, it’s Nick)
- Choose a hostname (winds-api)
Let your Droplet build – this can take up to 2 minutes. Once complete, copy the IP address and SSH into the Droplet using your terminal and the username root.
Update & Upgrade
For good measure, update and upgrade your packages (and be sure to follow any prompts that show up in the terminal):And, don’t forget to install the essentials:
Now, let’s install NVM (Node Version Manager):Run command -v nvm to source NVM and then run the following command: As you probably noticed, NVM listed out all of the available versions of Node.js. Go ahead and select the latest (v10.10.0 at the time of this post): Now if you type node --version, the output should say “Now using node v10.10.0 (npm v6.4.1)”.
Next, let’s go ahead and install Yarn, the package manager that we’ll be using for Node. On Ubuntu, you can install Yarn via the Debian package repository. You will first need to configure the repository:Then, you can simply “run” to finalize the Yarn installation:
PM2 is a great package that will handle the clustering of our Node.js processes and ensure that they stay alive. It’ll even keep an eye on scripts and restart them after an update. Install is simple since we have Yarn installed:
Setting up GitHub 💻
Clone the Repo 📀
Modify the Nginx Configuration 👩💻
In order for Nginx to pick up on what app we’re running, we need to specify the correct path. Let’s go ahead and do that now. Open default with vim, nano, or your favorite editor and change your configuration to resemble the following:Note: Line numbers 15-19 are the most important. Once you’re done, you can run sudo service nginx restart to restart the Nginx process.
Validate That the API is Working ✔
- pm2 list (lists the current processes running)
- pm2 kill (kills all process running)
- pm2 restart all --update-env (restarts all process while also reloading your .env file)
Next, we’ll dive into Fabric and show you how to create a Fabfile for deploying automatically.
Creating a Fabfile 📝
In order to run a Fabfile, you must first install Fabric, which can be done with pip. You can use the following script to install from your terminal:To speed things up, I’ve created a Fabfile for you. Copy the contents of the file below and save them as fabfile.py in the root of your project. Be sure to swap out the IP address, and the path to your SSH key (if it differs from mine). Once saved, you can run fab deploy and the script will SSH into your Droplet, install dependencies if new, and reload the environment file.
That’s It! 🎉
If you have any questions or comments on this tutorial, please leave them in the comments below. Your feedback is greatly appreciated. I hope you enjoyed this tutorial! Happy coding! 👏