Sharing economy is efficient, environment-friendly and accessible to all. Uber and Airbnb have swept out the traditional rental business in every aspect. It's much faster and more convenient to ask for a ride by Uber or Lyft, however, sometimes a ride is not sufficient for all travelling demand, in case of family trip, long journey or private event. Therefore, We'd like to work on a Uber-like car-sharing app for CS291A project.
The app is basically a booking system, in which the car owners can post the availability of their car in terms of time, location, model, mileage, photo and price. On the flipping side, the car users can search in the same manner and app will find the best match for both side. At the reserved time and location, the user will pick up the car from the owner and return it, perhaps at another location. All transactions are made online and a rating and review system in app is for users and owners to build up their reputation across board.
This app will have a web version at first, and then derives to a mobile version afterwards.
Make sure Ruby, Rails, and any other tools (such as RVM) are installed and ready to go (click here for geenral installation instructions and here for RVM)
Clone the repo
git clone git@github.com:scalableinternetservices/Luber.git
cd Luber
Setup the project and test that the server starts succesfully
# Install gem dependencies
bundle install --without production
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
rails db:migrate rails db:reset rails s
## Contributing
In order to contribute, complete the `Setup` section, then follow the general flow outlined below
1. Make sure the master branch builds and you can navigate around the site. Familiarize yourself with the codebase
2. Once you have a specific feature/issue you want to work on, create a new branch for that feature
3. Use test-driven development where applicable to create your new feature/resolve the given issue, and once thoroughly tested, submit a pull request on [GitHub](https://github.com/scalableinternetservices/Luber/pulls)
4. Once your code is peer-reviewd and any Travis CI issues are resolved, merge the branch into master
```sh
# Make sure master is up-to-date
git pull origin master
# Make your new branch
git checkout -b my-feature-branch
# Do work son
git add -D
# Make sure tests pass and perform any needed fixes/updates
rails t
# Commit and push work
git commit -m "made this cool thing"
git push origin my-feature-branch
# Merge (or rebase if you're into that) with master
git merge master
# Resolve conflicts and re-commit changes
git add -D
git commit -m "merged with master"
git push origin my-feature-branch
# Open a pull request on the GitHub page and assign someone to review it
Make an account on Heroku
From your local Luber directory, verify that the application is seeding/testing/running correctly
rails db:migrate
rails db:reset
rails t
rails s
Install Heroku, login, and add a SSH key (installing will differ depending on your OS)
# Install then verify a version appears
heroku version
heroku login ssh-keygen -t rsa -C "Heroku ssh key for our Luber" heroku keys:add
4. From your local Luber directory, create a heroku app and deploy it to heroku
```sh
heroku create
git push heroku master
# If you are pushing a branch other than master to heroku master, use:
# git push heroku other-branch:master
# NOTE: To run commands (or specifically run bash and access the terminal) on your remote heroku machine use:
heroku run # insert command here
heroku run bash
heroku run rails db:migrate heroku run rails db:seed
heroku run bundle exec rake assets:precompile
heroku open
6. In case you need to wipe out the existing database (if say you want to re-seed it differently):
```sh
# Locally
heroku pg:reset DATABASE_URL
# Remotely on Heroku, give it a minute to finish the previous command
rails db:migrate
rails db:seed
Download our secret key luber.pem
from Piazza (if don't have luber.pem
already)
aws credentials luber
)ssh into our EC2 instance
ssh -i luber.pem luber@ec2.cs291.com
on EC2, make your own dir to launch EB from:
mkdir Justin
cd Justin
clone our repo (if not done already)
git clone https://github.com/scalableinternetservices/Luber.git
cd Luber
Ensure you're ssh'd into EC2 (see above)
Ensure you're in your git repo
git status
should not say "Not a git repository"Try to deploy EB:
eb deploy luber-justin ( <-- your env name here)
If eb deploy
yields "No environment" error, need to eb create
:
for 'hello world':
eb create -db.engine postgres -db.i db.t2.micro -db.user u --envvars SECRET_KEY_BASE=866b90021b2c4a0ebc32571e4b2ca94a --single luber-justin
for Tsung testing:
eb create -db.engine postgres -db.i db.m3.medium -db.user u --envvars SECRET_KEY_BASE=866b90021b2c4a0ebc32571e4b2ca94a -i m3.medium luber-justin
Note: -db.i
(the db machine) can be one of
Note: -i
(the app server) can be one of
Note: SECRET_KEY_BASE
(base of key that encrypts cookies) should be long alphanumeric string, for example from
head -c 100 </dev/urandom | hexdump | head -n 1 | cut -d" " -f2- | tr -d " "
If eb create
yields error "has not been set up with the EB CLI", need to eb init
, then do eb create
again:
eb init
eb use luber-justin
to make this your default (later can use eb list
to see list of deployments).
eb deploy
instead of eb create
-- faster.Output from eb deploy
or eb create
:
Creating application version archive "app-541a-171128_215113".
Uploading luber-justin/app-541a-171128_215113.zip to S3. This may take a while.
Upload Complete.
Environment details for: luber-justin
Application name: luber-justin
Region: us-west-2
Deployed Version: app-541a-171128_215113
Environment ID: e-zwqrwahpna
Platform: arn:aws:elasticbeanstalk:us-west-2::platform/Puma with Ruby 2.4 running on 64bit Amazon Linux/2.6.1
Tier: WebServer-Standard
CNAME: UNKNOWN
Updated: 2017-11-28 21:51:17.422000+00:00
Printing Status:
INFO: createEnvironment is starting.
INFO: Using elasticbeanstalk-us-west-2-671946291905 as Amazon S3 storage bucket for environment data.
INFO: Created security group named: awseb-e-zwqrwahpna-stack-AWSEBSecurityGroup-WY9IFP478JLS
INFO: Created EIP: 54.191.49.249
INFO: Creating RDS database named: aa3e7jh8yi6knq. This may take a few minutes.
Log in:
bboe-ucsb
luber@ec2.cs291.com:~/luber.txt
Under Menu
> Services
> Elastic Beanstalk
> All Applications
, see your EB deployment name, eg, luber-justin
. Click it to get to its dashboard.
When it's finished deploying, see the tiny URL near the top. Visit it in a web browser to verify it works.
EC2$ eb ssh -e 'ssh -i ~/luber.pem'
APP-SERVER$ cd /var/app/current
On the app server's rails installation, delete contents of db and re-seed:
APP-SERVER$ date ; echo 'ActiveRecord::Base.logger.level = 1 ; Tagging.delete_all ; Rental.delete_all ; Tag.delete_all ; Car.delete_all ; User.delete_all ; ActiveRecord::Base.logger.level = 0' | rails c ; date
APP-SERVER$ rails db:seed
delete_all
doesn't obey foreign-key constraints, so is faster than destroy_all
. APP-SERVER$ DISABLE_DATABASE_ENVIRONMENT_CHECK=1 rails db:reset
(Note: Please use the justin-tsung
branch for load-testing)
(if you know what you're doing)
Log in to EC2
ssh -i luber.pem luber@ec2.cs291.com
cd
to Luber in your personal directory
Start our app on Elastic Beanstalk:
EC2$ git pull
EC2$ eb deploy # if it's still running, or 'eb create ...' if not.
Seed the db:
EC2$ eb ssh -e 'ssh -i ~/luber.pem'
APP-SERVER$ cd /var/app/current
APP-SERVER$ date ; echo 'ActiveRecord::Base.logger.level = 1 ; Tagging.delete_all ; Rental.delete_all ; Tag.delete_all ; Car.delete_all ; User.delete_all ; ActiveRecord::Base.logger.level = 0' | rails c ; date
APP-SERVER$ rails db:seed
In AWS CloudFormation, make a new stack for Tsung
In Options, use ssh command to ssh into Tsung machine
Copy XML to Tsung:
rsync -auvLe 'ssh -i luber.pem' *.xml ec2-user@52.41.232.150:~
Run Tsung:
tsung -f simple.xml -k start
Save XML from Tsung:
rsync -auvLe 'ssh -i demo.pem' ec2-user@54.166.5.220:~ .
Visit AWS CloudFormation
bboe-ucsb
luber@ec2.cs291.com:~/luber.txt
Use for the "S3 template URL": https://cs291.s3.amazonaws.com/Tsung.json
Pick a Stack Name of the form luber-justin
.
App instance type: m3.medium
Team name (pulldown): luber
"Next", "Next", "Create"
If your Stack Name doesn't appear in the table, refresh after a couple secs.
Should see "CREATE_IN_PROGRESS" under Status. Wait until created.
Check your Stack Name, then under "Outputs" tab:
In the ssh session, see simple.xml
, our tsung test.
simple.xml
be sure to rsync
it to your local machine.In the Tsung file simple.xml
change the line
server host="www.google.com"
to the AWS EB URL where your app is running. (See the AWS Console > Elastic Beanstalk > your deployed app.)
Example:
<servers>
<server host="luber-justin.dckugbigqr.us-west-2.elasticbeanstalk.com" port="80" type="tcp"></server>
</servers>
my-laptop$ cd your-tsung-xmls/
my-laptop$ rsync -auvLe 'ssh -i luber.pem' *.xml ec2-user@52.41.232.150:~
Note: When ssh'd into the Tsung machine, ifconfig
lists some weird IP addr, this is NOT the IP to use. Use the IP from the browser's Tsung dashboard, found in CloudFormation.
Start Tsung
tsung -f simple.xml -k start
(Tsung runs.)
See the Tsung dashboard. Neato.
When Tsung is finished, rsync
over the logs & data to your local machine:
rsync -auvLe 'ssh -i demo.pem' ec2-user@54.166.5.220:tsung_logs .
Don't put tsung data into our repo, you'll probably want to experiment with Tsung. Maybe put each log into a folder with a README of which commit hash code you ran in EB, and which Tsung file you used, and how you changed the site (vertical / horiz scaling etc) to accommodate the load.
eb create
etc)/var/app/current/db/seeds.rb
.Note: sometimes AWS EB console can warn you that you're overloading it:
Time Type Details
2017-11-28 14:43:20 UTC-0800 INFO Environment health has transitioned from Severe to Ok.
2017-11-28 14:40:21 UTC-0800 WARN Environment health has transitioned from Ok to Severe. 44.8 % of the requests are failing with HTTP 5xx.
Bryce's Advice re: tsung testing, Nov 30, 2017:
Sujaya Maiyya (@sujaya)
Sammy Guo (@masoug)
Kyle Carson (@carsonkk)
Justin Pearson (@justinpearson)
Michael Zhang & Michael's little helper (@Heronalps)