Contact: Please reach out to Jackson Romero ([email protected] or [email protected]) for help with deployment or development on q'
- Install postgresql,
sudo apt install postgresql
- Switch to postgres user,
sudo -i -u postgres
- Create a new user,
createuser --interactive
(I called mineohq
and will continue to use that as an example) - Create a database with the same name,
createdb ohq
- Logout of the postgres user,
^D
- Add new Linux user with the same name,
sudo adduser ohq
- Login to that user to connect to the database,
sudo -u ohq psql
- You can verify your connection by running
\conninfo
- Install NGINX,
sudo apt install nginx
- Start NGINX,
sudo systemctl start nginx
- Edit the file at
/etc/nginx/sites-enabled/default
to be the following
upstream ohq {
server localhost:4000;
}
upstream api {
server localhost:8000;
}
server {
server_name <YOUR_DOMAINS>;
listen 80;
return 301 https://$host$request_uri;
}
server {
server_name <YOUR_DOMAINS>;
listen 443 ssl; # managed by Certbot
listen [::]:443 ssl ipv6only=on;
# RSA certificate
ssl_certificate /etc/letsencrypt/live/<YOUR_DOMAIN>/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/<YOUR_DOMAIN>/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
# This is old and seemingly not needed, could cause ERR_TOO_MANY_REDIRECTS
# Redirect non-https traffic to https
# if ($scheme != "https") {
# return 301 https://$host$request_uri;
# } # managed by Certbot
location /ohq/ {
rewrite /ohq/(.*) /$1 break;
proxy_pass http://ohq/;
}
location /api {
rewrite /api/(.*) /$1 break;
proxy_pass http://api;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
Be sure to replace <YOUR_DOMAINS>, e.g. "cs122.andrew.cmu.edu www.cs122.andrew.cmu.edu" and replace <YOUR_DOMAIN> with the folder path we'll create in a few steps, e.g. "cs122.andrew.cmu.edu"
- Install certbot,
sudo snap install --classic certbot
and thensudo ln -s /snap/bin/certbot /usr/bin/certbot
- Use certbot to generate SSL certificates. THIS MAY REQUIRE DIFFERENT STEPS DEPENDING ON HOW AND WHERE YOUR DOMAIN IS HOSTED. You will have to research this on your own. Ideally, your certificates will be created at
/etc/letsencrypt/live/<YOUR_DOMAIN>/fullchain.pem
and/etc/letsencrypt/live/<YOUR_DOMAIN>/privkey.pem
, but if they're created in different places, you will have to modify these lines of the nginx config. BE AWARE THAT YOU MAY HAVE TO SETUP CERTIFICATE ROTATION - You can validate your nginx config with
sudo nginx -t
- Start nginx with
sudo systemctl start nginx
- Depending on your domain hosting provider, there may be built-in ways to do this. However, if manually configuring your website, you should be able to add a .A record to your domain and going to it should show a 502 error page from nginx!
- Using the Google Cloud console, create a project and search for OAuth
- Under "OAuth Consent Screen", select "External" as the User Type and hit "Create".
- Follow the instructions and add your primary domain under "Authorized Domains" (e.g. for cs122.andrew.cmu.edu this domain would be cmu.edu)
- On the next page, add the ".../auth/userinfo.email", ".../auth/userinfo.profile", and "openid" scopes
- Publish the app to remove testing/development limitations on the number and kinds of users you can have
- Under "Credentials", create an OAuth Client ID
- Select "Web Application" as the type.
- For "Authorized JavaScript origins", add the following
- Your primary URL, e.g. "https://cs122.andrew.cmu.edu"
- "http://localhost:3000"
- "http://localhost:8000"
- Your primary URL with port 443, e.g. "https://cs122.andrew.cmu.edu:443"
- For "Authorized redirect URIs", add the following
- Your primary URL with /login/callback, e.g. "https://cs122.andrew.cmu.edu/login/callback"
- Your primary URL with /login/, e.g. "https://cs122.andrew.cmu.edu/login"
- "http://localhost:3000/login/callback"
- "http://localhost:8000/login/callback"
- Your primary URL with a /, e.g. "https://cs122.andrew.cmu.edu/"
- Your primary URL, e.g. "https://cs122.andrew.cmu.edu"
- Your primary URL with port 443, e.g. "https://cs122.andrew.cmu.edu:443"
- Are all of these necessary? Quite frankly I don't know but 122 has all of these and our queue works so just to be safe I listed them all
- Clone this repo
- Install Node.js 16+ for your system. This can be done via various package managers and their site (definitely works on Node 18.19 and 16.18)
- In both the /client and /server folders, run
npm install
- Setup the client and server .env files as follows:
WDS_SOCKET_PORT=0
REACT_APP_PROTOCOL=https
REACT_APP_DOMAIN=<YOUR_DOMAIN>
REACT_APP_GOOGLE_CLIENT_ID=<GOOGLE_CLIENT_ID>
REACT_APP_SOCKET_PATH=/api/socket.io
REACT_APP_SERVER_PATH=/api
PUBLIC_URL=/ohq
PROTOCOL=https
DOMAIN=<YOUR_DOMAIN>
CLIENT_PORT=443
GOOGLE_CLIENT_ID=<GOOGLE_CLIENT_ID>
GOOGLE_CLIENT_SECRET=<GOOGLE_CLIENT_SECRET>
GOOGLE_REDIRECT_URI=https://<YOUR_DOMAIN>
POSTGRESQL_DB_HOST=localhost
POSTGRESQL_DB_USER=<YOUR_POSTGRES_USER>
POSTGRESQL_DB_PASSWORD=<YOUR_POSTGRES_USER_PASSWORD>
POSTGRESQL_DB=<YOUR_POSTGRES_DB>
POSTGRESQL_DB_PORT=5432
TOKEN_KEY=<any long random string that will be used as a secret key>
OWNER_EMAIL=<YOUR_ADMIN_EMAIL>
- Deploy the server
% cd server
% npm run db:sync # Only on first time running or after database modification
% npm install -g nodemon
% npm start
- Deploy the client
% cd client
% npm run build
% sudo npm install --global serve
% serve -s build -l 4000 -n
- We have GitHub actions set up now to automatically push new queue updates. This isn't required to deploy the queue and is optional, but it's a nice to have. We use tmux to manage the client and server sessions. If you aren't doing this, I'd recommend deleting the .github folder.