Advertisement
Guest User

Untitled

a guest
Dec 9th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.65 KB | None | 0 0
  1. ## EIC Trading Server & Web
  2. This is the web application server and web app client for EIC's trading application (and some other stuff).
  3.  
  4. ## Configuring your local environment
  5. In order to contribute to development of the EIC trading web app, you'll need to set-up your local environment. If you run into issues in this process be sure to check the troubleshooting section of this README. It's likely that your issue has a solution that is covered in this section.
  6.  
  7. ### Step 1 - Vagrant and Virtualbox
  8. Grab the latest version of vagrant + virtualbox and install them on your local machine before continuing.
  9. * [Vagrant Download](https://www.vagrantup.com/downloads.html)
  10. * [Virtualbox Download](https://www.virtualbox.org/wiki/Downloads)
  11.  
  12. ### Step 2 - Initializing your local git repo
  13. You should clone the git repo for this project on your local machine somewhere before continuing.
  14.  
  15. ### Step 3 - Launching the virtual machine
  16. Now that you have the codebase, vagrant and virtualbox on your machine, it's time to launch your virtual machine. The following command will launch your VM as well as run a provisioning script which will install all project dependencies.
  17.  
  18. vagrant up
  19.  
  20. ### Step 4 - Connecting to your virtual machine
  21. Once your VM is up and running you will need to connect to it. To do this we do the following:
  22.  
  23. vagrant ssh
  24.  
  25. ### Step 5 - Configuring your ruby environment
  26. Once you `ssh` into your VM after setting up your environment variables, we need to install all ruby libraries. To do this run the bundle command below:
  27.  
  28. sudo gem install bundler -v 1.15.3
  29. bundle install
  30.  
  31. ### Step 6 - Setting up your database
  32. Once your ruby environment is initialized you will need to configure your local postgresql database. To do this copy and paste the following set of commands into your console. Ensure you `ssh` before running this.
  33.  
  34. sudo su postgres
  35. pg_dropcluster --stop 9.1 main ; pg_createcluster --start --locale en_US.UTF-8 9.1 main
  36. exit
  37. sudo -u postgres createuser -s eic_development
  38. sudo -u postgres psql -c "ALTER USER eic_development WITH PASSWORD 'eic_development'"
  39.  
  40. ### Step 7 - Provisioning your database
  41. Now that your database configuration has been set you should provision your database with our application's schema.
  42.  
  43. rake db:create
  44. rake db:migrate
  45.  
  46. ### Step 8 - Launching the web server
  47. At this point all resources have been installed and initialized and you are ready to start your rails server. To do this use the following command:
  48.  
  49. bundle exec puma -C config/puma.rb
  50.  
  51. OR to start just one instance of the server:
  52.  
  53. rails s -b 42.42.42.42
  54.  
  55. You should be able to access your running web app via your web browser now. You can access it via the following ip address.
  56.  
  57. ip address: 42.42.42.42:3000
  58.  
  59. ## Working with Rails migrations
  60. Fixing issues with migrations in a production environment is time-consuming and risky. In order to avoid issues, we should follow the following best practices:
  61.  
  62. Always use Rails' migration generator to create new migrations.
  63.  
  64. rails generate migration AddUserToLandscape
  65.  
  66. Never change the timestamp of a migration -- there should never be a need to change it. Make sure to also test your migrations in reverse. Run `rake db:rollback` after running `rake db:migrate` to make sure your migration won't fail if it needs to be rolled back.
  67.  
  68. ## Working with Rails tests
  69. As of Rails 4.1 you must maintain your test database/environment manually. Run the following commands to ensure that happens. The migration step must be run each time the database schema updates.
  70.  
  71. RAILS_ENV=test;bundle exec rake db:create;RAILS_ENV=development
  72. RAILS_ENV=test;bundle exec rake db:migrate;RAILS_ENV=development
  73. RAILS_ENV=test;bundle exec rake test:prepare;RAILS_ENV=development
  74.  
  75. Once migrated, you can run the tests with the following command:
  76.  
  77. RAILS_ENV=test;bundle exec rake test;RAILS_ENV=development
  78.  
  79. Finally, if you would like to run a specific test we use the `m` gem for this as follows:
  80.  
  81. RAILS_ENV=test;bundle exec m test/functional/controllers/api/v4/companies_controller_test.rb:13;RAILS_ENV=development
  82.  
  83. ## Working with Bower & Grunt
  84. We use bower to install locally all the `JS` libraries grunt will need to compile our front-end web client. Ocassionally you will need to update or add a library in bower. You can do that with a command like the following:
  85.  
  86. bower install ember-data#1.0.0-beta.11 --save-dev
  87.  
  88. Once all of your libraries are installed you can deploy the web client with one of the following commands. `dev` will wait for new file revisions and automatically re-deploy while `deploy` will deploy once and not wait for new file updates.
  89.  
  90. grunt dev
  91. grunt deploy
  92.  
  93. ## Using the virtual machine
  94. Variant and virtualbox are not difficult to use. Below are some general commands to help you in managing your local VM.
  95.  
  96. This first set of commands should be your basic operating commands.
  97.  
  98. vagrant up - Boot the VM (or awake from sleep mode)
  99. vagrant ssh - Connect to the VM
  100. exit - Exit the VM
  101. vagrant suspend - Put the VM into sleep mode
  102.  
  103. If you run into issues with your VM, you can always hard shutdown your VM with the following command:
  104.  
  105. vagrant halt -f
  106.  
  107. Finally, if your VM is locking up often or in general running very slow then it might be time to destroy and rebuild your VM.
  108.  
  109. vagrant destroy -f
  110.  
  111. ## Using GIT with EIC
  112. We have some general rules that we like to follow when using GIT with EIC's ruby server. So long as we follow the below rules then we should never have to do any cherry picking or difficult merging.
  113.  
  114. ### Rule 1 - Don't cross-merge branches
  115. If `branch-a` and `branch-b` are both branched off of `master`, `branch-a` and `branch-b` should never be merged into any branch but master. Adhering to this strict hierarchy rule will avoid any question of what code is where, and we should avoid cross-merging all together.
  116.  
  117. ### Rule 2 - Stick to the following commands
  118. Git is not a complicated system and you should never have to do things like rebasing so long as you stick to the following command set.
  119.  
  120. git init
  121. git fetch
  122. git remote
  123. git checkout
  124. git add -A
  125. git commit
  126. git status
  127. git pull
  128. git push
  129. git merge
  130.  
  131. ## Troubleshooting the Web Server
  132. VMs and their providers (virtualbox) can sometimes misbehave. If you run into issues with the above process, don't panic, you're not the first to run into issues. Below are some issues along with some general solutions to problems you may run into.
  133.  
  134. ### VM Boot issues
  135. If you run into issues when booting your VM, don't panic. The issue very well may be that you need to restart the virtualbox instance. The following command will reboot that instance, keep in mind the file path, yours may be installed somewhere else.
  136.  
  137. sudo /Library/StartupItems/VirtualBox/VirtualBox restart
  138.  
  139. ## Inegration with Auth on core EIC server
  140. The following are examples of how to access users on the EIC server along with how to auth from the EIC server. The third example is how we verify auth creds.
  141.  
  142. ```
  143. // Get user
  144. GET /api/v1/users.php?username=Cazz0r&password=test
  145. > 200 OK {"user":{"username":"Cazz0r","tags":["bgs-nerd"]}}
  146.  
  147. // Get user
  148. GET /api/v1/users.php?username=Cazz0r&password=test&bgs-nerd
  149. > 200 OK {"user":{"username":"Cazz0r","tags":["bgs-nerd"],"bgs-nerd":true}}
  150.  
  151. // Auth creds
  152. GET /api/v1/users.php?username=Cazz0r&password=test&sales-nerd
  153. > 401 Unauthorized {"user":{"username":"Cazz0r","tags":["bgs-nerd"],"sales-nerd":false}}
  154.  
  155. // Full domain example
  156. https://eicgaming.com/api/v1/users.php
  157.  
  158. // MySQL Creds (read permission only)
  159. Host: eicgaming.com
  160. Port: 3306
  161. User: drieton
  162. Pass: passwordofdrieton
  163. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement