Amplify (WebAPI)
- Clone the repo
git clone git@github.com:wcoombs/Amplify-Web.git - install the approriate ruby version (
2.5.0) also listed in.ruby-versionfile at the root of the project- You can use any ruby version manager of your choosing, we've been using RVM for local development and I choose to use
RBENVfor the production server (play nicely with capistrano) - If you use
RVMinstalling ruby 2.5.0 is as simple asrvm install 2.5.0and thervm use 2.5.0to set that version. - Word of caution when use ruby version managers is that some shells behave in unexpected ways when switching between folders and may unset the current version of ruby being used. I won't get into further details here about managing that.
- You can use any ruby version manager of your choosing, we've been using RVM for local development and I choose to use
gem install bundlebundler will manage our projects gem dependenciesbundleorbundle installto install the gems needed for the projectnpm installornpm install yarnto install yarn (only use npm to install yarn, then use yarn going forward)yarn installto install our javascript dependenciesbrew install postgresqlto install postgresbrew services listand confirm that postgresql isstartedbundle exec rake db:createto create our databasebundle exec rake db:migrateto run any outstanding migrations- create a local secrets file
config/secrets.yml, we have an example secrets file that can be used as a template, to create your development copy.- Use
rake secretif you want to generate your ownsecret_key_basefor your local secrets file
- Use
- You need to sign up for a Spotify Premium account and become a Spotify Developer in order to test and develop locally with the mobile app. That information can be found on the Mobile repository
- Add the client ID and client secret to both the
developmentandtestenvironments in thesecretsfile- Be sure to also set the redirect_uri to
"http://127.0.0.1:3000/spotify_callback"for bothdevelopmentandtest - If this is being setup for grading purposes, in order to avoid tedious setup with Spotify (and to having to get a Spotify Premium account for grading purposes), please contact Will at william.m.coombs@gmail.com to be given his Spotify Premium account credentials that you can add to your
secretsfile - This is necessary in order to fully run and demo the application
- If you attempt to run the mobile application without Spotify Premium account credentials, you will be notified on the device that a Premium account is required
- Be sure to also set the redirect_uri to
- create a local database file
config/database.yml, we have an example database file that can be used as a template to create your own copy.
bundleto fetch any gems that may have been added to the projectbundle exec rake db:migrateto run any new migrationsyarn installto fetch any new javascript dependencies
There are two options for running the rails server
- Simply
rails sshort forrails server
Or if you want to run webpacker separately (faster for asset compilation, and css hot reloading)
webpack-dev-serverto start the webpack development server- after the webpack dev server is up
rails s
* A quick fix for database errors related to junk data
bundle exec rake db:reset RAILS_ENV=environmentwhereenvironmentis test/development/staging (never production),db:resetwill drop the database, then runcreate,schema:load, and finallyseedso it's lazy command to run if you do not care whatsoever about the information in the database.
* If you get errors back on the web side asking to update your local database, run the command
bin/rails db:migrate RAILS_ENV=development. There should be some tables created if they were missing. Restart the server after the migration is complete.
* If you encounter any errors mentioning webpacker, packs, manifest, or any thing javascripty
- Be sure to run
yarn installin the project directory to install any javascript dependencies.- If
yarn installfails make sure you have npm installed and up to date, and then donpm installin the project directory.
* If you continue to have trouble getting the project to run and are evaluating us for grading purposes, email rob @ robert.laurin89@gmail.com
- For ease of use, use your Mac!
- Create a room
- Set up the local server (must be on a Mac)
- Start the mobile simulator (click the run icon)
- Go into the Amplify-Web repository and run "rails s" to start the server
- Hit "Create Room" button to be given a room code (remember this!)
- Join a room
- Go to localhost:3000 to access the web app
- Enter the aforementioned room code and a nickname to enter the room (case insensitive)
- View the songs and vote accordingly (you get one vote per song; vote can be changed)
- Follow the steps under the Mobile repository
- The link to the production web site is
https://amplifyapp.ca
- Navigate to the root directory for the repository
- Run the command
rspec
- If this fails for whatever reason, explicitly state what you want to do (
bundle exec rspec spec)
- ...
- Profit
- Navigate to the root directory for the repository
- Run the command
rails routes - ...
- Profit
| Completed | Method | Endpoint | Usage | Permission | Returns |
|---|---|---|---|---|---|
| ✓ | POST | /api/register/room_id |
Join a room | Anybody | - |
| Completed | Method | Endpoint | Usage | Permission | Returns |
|---|---|---|---|---|---|
| ✓ | POST | /rooms/ | Create a room | Anybody | - |
| ✓ | DELETE | /rooms/room_id |
Destroy a room | Anybody | - |
| Completed | Method | Endpoint | Usage | Permission | Returns |
|---|---|---|---|---|---|
| ✓ | GET | /api/playlist/room_id |
View playlist | Authenticated | Songs |
| ✓ | PUT | /api/playlist/room_id/song_id |
Vote on a song | Authenticated | Song |
- Ubuntu Server 16.04
- Free tier box
- Add security group
- http
- https
- ssh
- Launch!
Configuring access. More Info
-
create a deployment user
adduser deploypasswd -l deploy- add your pub key so you can log in as the deployment user
su - deploy# this is logging in as the deploy usercd ~mkdir .ssh- `echo "ssh pub key here" >> .ssh/authorized_keys
chmod 700 .sshchmod 600 .ssh/authorized_keys- from your local machine test to see if it worked
ssh deploy@server-ip-here 'hostname; uptime'
-
give the deploy user access to the repo
- locally and within the project repo
- get the git repo url
git config remote.origin.url
ssh-addssh -A deploy@server-ip-here 'git ls-remote git-url-here'
Project dependencies. More Info
-
install nginx
sudo apt-get updatesudo apt-get install curl git-core nginx -y
-
visiting the instance ip now should greet you with an nginx welcome message
-
install ruby and its dependencies More Info
sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
-
install rbenv for managing our ruby version More Info
- these steps performed as deploy user
git clone https://github.com/rbenv/rbenv.git ~/.rbenvecho 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrcecho 'eval "$(rbenv init -)"' >> ~/.bashrcsource ~/.bashrc
-
type rbenv and it should output some text indicating it's there.
-
get the rbenv install command
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
-
install your project version of ruby
rbenv install 2.5.0 --verbose# verbose because it seems like it's hanging otherwise :/rbenv global 2.5.0# set 2.5.0 as the version to usegem install bundle# needed for deployment
-
install postgres More Info
sudo apt-get updatesudo apt-get install postgresql postgresql-contrib libpq-dev- create postgres user
sudo -u postgres createuser -s pguser# where pguser is the user name of your choicesudo -u postgres psql\password pguser# this password needs to be added to the database.yml file\qto quit pg
- in /home/deploy/apps/amplify/shared/config
- create/add a secrets.yml file
- create/add a database.yml file
cap stage deploy# will probably fail due to db not being created- need a better way of doing this but just jump in a recently created release and do
bundle exec rake db:create RAILS_ENV=stage
cap stage deploy# should succeed, now we just need to do a final tweak to the nginx confsudo rm /etc/nginx/sites-enabled/defaultsudo ln -nfs /home/deploy/apps/amplify/current/config/nginx.conf /etc/nginx/sites-enabled/amplifysudo service nginx restart