- Open "Applications" at Discord Developer Portal
- Click "New Application" button
- Type application name and "Create" button
- Click "Bot" on the left panel of the created application
- Click "Reset Token" button and then confirm by clicking "Yes, do it!" button
- Re-enter your Discord password and click "Submit" button
- Copy and save the generated bot token
- Check "MESSAGE CONTENT INTENT" and click "Save Changes" button
- Click "OAuth2" on the left panel
- In "OAuth2 URL Generator" -> "SCOPES" section check "bot"
- In "OAuth2 URL Generator" -> "BOT PERMISSIONS" section check "Send Messages"
- Set "OAuth2 URL Generator" -> "INTEGRATION TYPE" = Guild Install
- Copy "OAuth2 URL Generator" -> "GENERATED URL", open it in your browser and authorize the bot to a server
Initial deployment is done once. Update section is executed for redeployment
-
Create EC2 instance:
1.1 Open EC2 console: https://us-west-2.console.aws.amazon.com/ec2/home?region=us-west-2
1.2 Click "Launch instance"
1.3 Fill in the following:
- Name and tags -> Name: thenewboston.network
- Application and OS Images: Ubuntu Server 22.04 LTS (HVM), SSD Volume Type, Architecture = 64-bit (x86)
- Instance type: t2.micro
- Key pair (login): choose a key pair from the list
- Network settings: Create security group
- Network settings: Allow SSH traffic from (Anywhere), Allow HTTPS traffic from the internet, Allow HTTP traffic from the internet
- Configure storage: 20 Gb (gp2)
1.4 Click "Launch instance"
-
Create elastic IPv4 address and assign to the EC2 instance
-
Create DNS A record
thenewboston.network
pointing to the elastic IPv4 address -
Add 4G swapfile (this is necessary to avoid out of memory errors which lead to EC2 instance reboot):
# Login to the EC2 instance
ssh [email protected]
sudo -i
# Allocate swap space
fallocate -l 4G /swapfile && \
chmod 600 /swapfile && \
mkswap /swapfile
# Turn on swap file
swapon /swapfile
vim /etc/fstab
# Add the following line
# /swapfile swap swap defaults 0 0
# Correcting swappiness
sysctl vm.swappiness=10
vim /etc/sysctl.conf
# Add the following line
# vm.swappiness=10
# Reboot
reboot
# Login to the EC2 instance again
ssh [email protected]
# Validate new settings
free -h
swapon --show
cat /proc/sys/vm/swappiness
- Install the latest software and prerequisites:
ssh [email protected] # if necessary
sudo apt update && sudo apt upgrade
sudo apt install make nginx
sudo reboot
- Configure nginx:
# Run on local machine:
scp thenewboston/project/settings/templates/nginx.conf [email protected]:/tmp/thenewboston.conf && \
ssh [email protected] 'sudo cp /tmp/thenewboston.conf /etc/nginx/sites-available/ && sudo ln -s /etc/nginx/sites-available/thenewboston.conf /etc/nginx/sites-enabled/thenewboston.conf && sudo rm /etc/nginx/sites-available/default'
-
Install certbot as described at https://certbot.eff.org/instructions?ws=nginx&os=ubuntufocal (use [email protected] for urgent renewal and security notices)
-
Create environment specific configuration file:
# Run on local machine:
ssh [email protected] 'sudo mkdir -p /etc/thenewboston' && \
scp thenewboston/project/settings/templates/template.env [email protected]:/tmp/template.env && \
ssh [email protected] 'sudo cp /tmp/template.env /etc/thenewboston/.env'
- Update
/etc/thenewboston/.env
with actual values at thenewboston.network:
ssh [email protected]
sudo vim /etc/thenewboston/.env
- Install docker as described at https://docs.docker.com/engine/install/ on thenewboston.network
- Setup and check docker installation:
ssh [email protected]
sudo usermod -aG docker $USER
exit
ssh [email protected]
# Known working versions described in the comments below
docker --version # Docker version 26.0.1, build d260a54
# (!!!) At least Docker Compose version v2.24.0 is required
docker compose version # Docker Compose version v2.26.1
- Create database RDS instance:
3.1 Open AWS RDS -> Databases: https://us-west-2.console.aws.amazon.com/rds/home?region=us-west-2#databases
3.2 Click "Create database"
3.3 Fill in the following:
- Choose a database creation method: Standard create
- Engine options -> Engine type: PostgreSQL
- Engine options -> Engine version: 16.2
- Templates: Free tier
- Settings -> DB instance identifier: thenewboston
- Settings -> Credentials Settings -> Master username: thenewboston
- Settings -> Credentials Settings -> Credentials management: Self managed
- Settings -> Credentials Settings -> Master password:
- Settings -> Credentials Settings -> Confirm master password:
- Instance configuration -> DB instance class -> Burstable classes (includes t classes): db.t3.micro
- Storage -> Storage type -> gp2
- Storage -> Allocated storage: 20
- Storage -> Storage autoscaling -> Storage autoscaling -> Enable storage autoscaling: checked
- Storage -> Storage autoscaling -> Storage autoscaling -> Maximum storage threshold: 40
- Connectivity -> Compute resource: Don’t connect to an EC2 compute resource
- Connectivity -> Network type: IPv4
- Connectivity -> Virtual private cloud (VPC): Default VPC
- Connectivity -> DB subnet group: default
- Connectivity -> Public access: Yes
- Connectivity -> VPC security group (firewall) -> Create new: Automatic setup
- Connectivity -> New VPC security group name: thenewboston-database-sg
- Database authentication -> Database authentication options: Password authentication
- Monitoring -> Turn on Performance Insights: unchecked
- Monitoring -> Additional configuration -> Enable Enhanced Monitoring: unchecked
- Additional configuration -> Database options -> Initial database name: thenewboston
- Additional configuration -> Log exports -> PostgreSQL log: checked
- Additional configuration -> Log exports -> Upgrade log: checked
- Additional configuration -> Deletion protection -> Enable deletion protection: checked
- Additional configuration: leave defaults for the rest of the options
- Clone git repo:
ssh [email protected] # if necessary
git clone https://github.com/thenewboston-developers/thenewboston-Backend.git
- Update docker-compose.yaml:
ssh [email protected] # if necessary
bash -c 'cd ~/thenewboston-Backend && make update-docker-compose-yaml'
- Run Update section
- Login:
- Fetch the latest code:
cd ~/thenewboston-Backend && git fetch origin && git checkout origin/master
- Redeploy:
make deploy
- Clean up:
make deploy-cleanup