-
Notifications
You must be signed in to change notification settings - Fork 6
Deployment
Sam Ping edited this page Apr 29, 2021
·
3 revisions
Sledge is deployed on AWS EC2. As of now, the dev server is hosted on a t2.micro instance with 8GB of storage space.
NOTE: The amount of resources Sledge uses has not been properly measured yet. It may be advisable to open an instance with higher specs if needed.
- Create EC2 instance and connect to it. Keep the .pem key somewhere safe!
- Create instance:
- OS: Ubuntu 20.04 LTS x64
- Instance Type: t2.micro (vCPUs: 1, Memory: 1GiB)
- Storage Space: 8GB SSD
- Tags:
- Name: sledge-dev/prod
- env: dev/prod
- Inbound rules:
- Allow HTTP and HTTPS. Expose port 5000 (which the server uses).
- Create instance:
- Update and install dependencies:
sudo apt update # updates repositories
sudo apt install git # installs Git
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs # installs NodeJS and NPM
- By now, you should have Git, NodeJS, and NPM installed.
- Now you can install PM2 with
npm i pm2 -g
. This will be used later in deploying the Express server. If you get an error, try running the same command usingsudo
. - Install MongoDB (instructions taken from here):
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - # should return OK
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org # installs MongoDB
- Now MongoDB should be installed. To start the service, run
sudo systemctl start mongod
. sudo apt-get install nginx # installs nginx
- Now start the server:
- Clone the Sledge repository with
git clone https://github.com/HackRU/sledge.git # clones over HTTPS, may have to be updated
cd sledge/server # go into the server directory
npm i # installs Sledge server dependencies
- Now if you run
node server.js
, you'll see that the server is up and running. However, if you close the terminal, the server will also stop running. Thus, we will be using PM2 (which we installed in the dependencies section) to keep the server running in the background. - If you haven't already, close the current Node.js process with CTRL-C. Now run the Express server using PM2 by running
pm2 start server.js
, and you're good to go!
- Clone the Sledge repository with
- Now set up the Nginx configs:
rm /etc/nginx/sites-available/default # delete default nginx config file
- To be continued...
Setting Up CodeDeploy (based on this):
Make sure the repository you're deploying (probably Sledge since you're on the Sledge Wiki, after all) has an appspec.yaml
file in its root. This file contains the instructions for how CodeDeploy should set up the Sledge files on EC2. You can look here for reference.
- If it doesn't already exist, go to the "IAM Management" section in the AWS console and create a new role with CodeDeploy permissions. Also create an EC2 role with CodeDeploy permissions and attach it to the EC2 instance, and restart CodeDeploy-agent on that instance.
- Install CodeDeploy onto the EC2 instance (based on this).
- Go to your home directory by running:
cd
. sudo apt-get install ruby-full # installs ruby, which the CodeDeploy Agent uses
sudo apt-get install wget # installs wget, which is a useful command. It might already be installed.
-
wget https://<bucket-name>.s3.<region-identifier>.amazonaws.com/latest/install # downloads a script that installs CodeDeploy
- For and , check here.
- Ex.
wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install
chmod +x ./install # gives executable permission to the script
sudo ./install auto > /tmp/logfile # as of 4/22/2021, the docs say to run this to avoid a bug with the script in Ubuntu 20.04.
- Go to your home directory by running:
- Go to CodeDeploy in AWS console.
- Create a new application for Sledge. Since we deployed Sledge on EC2, for "Compute Platform", choose EC2.
- After you create the application, click on it, and create a new deployment group.
- "Deployment Group Name": Name this deployment group whatever you want.
- "Service Role": Add the role you created in step 0.
- "Deployment Type": In-place
- "Environment Configuration": Amazon EC2 Instances
- Use the tags you created for the EC2 instance you launched for Sledge.
- "Agent configuration with AWS Systems Manager": Up to you. I decided on "Now and schedule updates" every 30 days using the basic scheduler. Because of this step, we don't have to manually install CodeDeploy on the EC2 instance.
- "Deployment Settings": CodeDeployDefault.AllAtOnce
- "Load balancer": Disabled
- "Advanced":
- "Rollbacks": I enabled rollbacks for when a deployment fails.
- (Optional) To manually deploy Sledge, click on "Create Deployment":
- Make sure the deployment group is correctly selected as the one you created earlier
- For "Revision Type", be sure to select "My application is stored in GitHub". To connect a new account (preferably official HackRU GH account?), simply type the username of that GitHub account in "GitHub Token Name", then click on Connect.
- "Repository Name": HackRU/sledge
- "Commit ID": probably the latest commit.
Welcome
Using Sledge
Development
Archive