This document is, essentially, a short guide to setting up a "droplet" on DigitalOcean to be used as a tool for deploying simple web applications. This is by no means a comprehensive guide, and you are encouraged to reach out to classmates, faculty, and TAs (through Slack, for example) with questions.
The majority of the information here will be presented in the form of bulleted lists, because we all know none of us actually read walls of text.
These instructions assume you're in the lab. The SSH key part in particular won't likely work if you're not. If you don't get the SSH keypair stuff right, you'll probably have a pile of issues logging in to your droplet.
Most of this will happen in a terminal window, which is yet another reason to take some time to learn how to use the Unix shell.
You're going to see the word "droplet" used a lot here. Digital ocean is in the business of hosting Virtual Private Servers (VPS), which they have decided to call "droplets." The term isn't terribly important, and for the most part just refers specifically to the VPSs hosted by DigitalOcean and all the features which that entails.
- Buy a domain (use namecheap and you can get one for $1 or less)
CloudFlare.com allows you to add an SSL certificate to your website. Create an account and sign in.
Under your DNS Records, add a record with these settings:
Type: A
Name: yourdomain.com
Value: your droplet IP address without a port
TTL: Automatic
Add another record with these settings:
Type: A
Name: www
Value: your droplet IP address without a port
TTL: Automatic
In this section, you are given NS pointers with values that are needed for your domain's registrar. In mine, I have the two following pointers:
ali.ns.cloudflare.com
elliot.ns.cloudflare.com
Have these ready for the following step.
We are using namecheap, so this step may be different if you are using another domain registrar.
Sign in, then go to your Dashboard. Next to your domain name, click the "Manage" button.
Next to "NAMESERVERS", select "Custom DNS" on the dropdown menu. Copy and paste the two values that you saved earlier. It could take up to 24 hours for this to take effect.
- Go to Digital Ocean.
- You can create an account without adding billing information.
- You cannot create any droplets without "activating" your account (by adding billing info).
- You do get $50 of free credit for D.O. through the Github StudentPack. Be sure to redeem it.
- Follow these directions: How to Configure SSH Key-Based Authentication on a Linux Server
- All this happens in a terminal window.
- Steps 1 and 2 happen on the machine in the lab.
- Steps 3 and 4 will happen on the Digital Ocean VPS when you have one set up.
- Click the big shiny "Create" button, and choose "Droplet" as the thing you want to create.
- Select the suggested Ubuntu version as your operating system.
- Select the smallest droplet, it should be $5 / month.
- Don't add block storage.
- Stick with the default datacenter / region (probably New York).
- Don't select any additional options.
- Add an SSH key. Use the contents of the public key file you generated in step 2.
- DigitalOcean will use this info to automagically do steps 3 and 4 from the SSH keypair instructions so you never have to do them "by hand".
- Finally, only make one droplet and choose a name for it.
- It will take a couple seconds to make the droplet.
- SSH to your droplet by running
ssh root@[my ip here]
(using the IP of your droplet) - Logged in? Good, keep reading. Problems? Ask someone for help (or Google).
- run:
wget https://gist.githubusercontent.com/pluck011/f44c9d1557a5127e100a300d018d3b63/raw/f78291783666ca776681ff9e1fd9e99428d6c522/3601-setup.sh
as root. - run
chmod +x 3601-setup.sh
- run
./3601-setup.sh
- Do whatever it asks.
- Reboot the droplet by typing
reboot
. SSH intodeploy-user@[my ip here]
.
- Use
git clone [your repo url here]
to get your repo on the droplet. - Use
cd [your repo name]
to move into the directory you just grabbed from github. (cd = Change Directory) - Use
cd client/src/envrionments/
and typenano envrionment.prod.ts
. - Edit the API_URL to reflect the domain of your website with
/api/
at the end of it. (i.e.https://sunshinejournal.site/api/
). UseCtrl + X
to exit and then save the file. - Navigate back to your repository. (Type
cd ~
and thencd [your repo name]
). - Use
cd server/src/main/java/umm3601/
and typenano Server.java
. - Find your server port (in our case it is 4567). Change
4567
to80
then save. - Navigate back to your repository.
- Run
./build.sh
to build and deploy your project. - run
tmux
to enter a Tmux session. - run
sudo ./3601.sh
to start your server (3601.sh is in the home directorycd ~
). (thesudo
part is required because connecting to port 80 requires special permission) - press
Ctrl + b
and thend
to detach from this Tmux session. It will continue running even after you log out. To reconnect to the Tmux session, log into your droplet and runtmux a
(a for attach!)
If you're interested in doing more fun things with Tmux, check out this cheat-sheet. Tmux is a really cool tool, and if you ever plan on doing system administration stuff in the future it's worth getting to know it.
- Navigate to the home directory.
- Run
rm -rf server/
to remove the old version. - Navigate to the repository directory on your droplet.
- Run
git pull
- Repeat steps starting at
./build.sh
from above.
- You're free to add accounts to your droplet as you see fit and provide that login info to others.
- You should not share the private key that you generated.
- You can enable password ssh logins by editing the
PasswordAuthentication
field in/etc/ssh/sshd_config