Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] update sinatra version in part 0 documentation #63

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/cloud_service_port_configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Rackup is one app that relies on ports being opened to serve pages. If you want to use it or similar on cloud systems such as Cloud9 or Codio you'll need to add command switches as shown below:

##### Cloud9 operation

If you're using Cloud9, you should use this command line:

```sh
$ bundle exec rackup -p $PORT -o $IP
```
[Available ports on a hosted Cloud9 workspace](https://docs.c9.io/docs/run-an-application)

##### Codio operation

If you're using Codio, you should use this command line:

```sh
$ bundle exec rackup --host 0.0.0.0 -p 3000
```

and click on the Codio "Project Index (static)" drop down and select "Box URL" in order to access
24 changes: 9 additions & 15 deletions docs/part_0_create_saas_app.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ Let's start with the following steps:
source 'https://rubygems.org'
ruby '>= 2.2.0', '< 3.0.0'

gem 'sinatra', '>= 2.0.1'
gem 'sinatra', '>= 2.0.5'
```

The first line says that the preferred place to download any necessary gems is https://rubygems.org, which is where the Ruby community registers "production ready" gems.

The second line specifies which version of the Ruby language interpreter is required. If we omitted this line, Bundler wouldn't try to verify which version of Ruby is available; there are subtle differences between the versions, and not all gems work with all versions, so it's best to specify this.

The last line says we need version 2.0.1 or later of the `sinatra` gem. In some cases we don't need to specify which version of a gem we want; in this case we do specify it because we rely on some features that are absent from earlier versions of Sinatra.
The last line says we need version 2.0.5 or later of the `sinatra` gem. In some cases we don't need to specify which version of a gem we want; in this case we do specify it because we rely on some features that are absent from earlier versions of Sinatra.

Run Bundler
-----------
Expand Down Expand Up @@ -106,15 +106,9 @@ If you're developing locally, you're now ready to test-drive our simple app with
```sh
$ bundle exec rackup
```
**Note:** [How to run web apps (e.g. rackup) on cloud services such as Cloud9 or Codio](cloud_service_port_configuration.md)

If you're using Cloud9, you should use this command line:

```sh
$ bundle exec rackup -p $PORT -o $IP
```
[Available ports on a hosted Cloud9 workspace](https://docs.c9.io/docs/run-an-application)

This command starts the Rack appserver and the WEBrick webserver. Prefixing it with `bundle exec` ensures that you are running with the gems specified in `Gemfile.lock`. Rack will look for `config.ru` and attempt to start our app based on the information there.
Whichever platform you are working with, this `rackup` command starts the Rack appserver and the WEBrick webserver. Prefixing it with `bundle exec` ensures that you are running with the gems specified in `Gemfile.lock`. Rack will look for `config.ru` and attempt to start our app based on the information there.

If you're developign locally, you can visit `localhost:9292` in your browser to see the webapp. If you're using Cloud9, you will see a small popup in the terminal with a URL to your running webapp. It will open in a new tab in the IDE if you click on it, but you should open up a fresh browser tab and paste in that URL.

Expand All @@ -138,7 +132,7 @@ Modify `app.rb` so that instead of "Hello World" it prints "Goodbye World". Save

No changes? Confused?

Now go back to the shell window where you ran `rackup` and press Ctrl-C to stop Rack. Then type `bundle exec rackup` again (`bundle exec rackup -p $PORT -o $IP`, for Cloud9), and once it is running, go back to your browser tab with your app and refresh the page. This time it should work.
Now go back to the shell window where you ran `rackup` and press Ctrl-C to stop Rack. Then type `bundle exec rackup` again, and once it is running, go back to your browser tab with your app and refresh the page. This time it should work.

What this shows you is that if you modify your app while it's running, you have to restart Rack in order for it to "see" those changes. Since restarting it manually is tedious, we'll use the `rerun` gem, which restarts Rack automatically when it sees changes to files in the app's directory. (Rails does this for you by default during development, as we'll see, but Sinatra doesn't.)

Expand All @@ -152,15 +146,15 @@ end

Any gem specifications inside the `group :development` block will only be examined if bundle is run in the development environment. (The other environments you can specify are :test and :production, and you can define new environments yourself.) Gem specifications outside of any group block are assumed to apply in all environments.

Say `bundle exec rerun -- rackup -p $PORT -o $IP` in the terminal window to start your app and verify the app is running. There are more details on rerun's usage available in the gem's [GitHub README](https://github.com/alexch/rerun#usage). Gem's are usually on GitHub and their README's full of helpful instructions about how to use them.
Say `bundle exec rerun -- rackup` in the terminal window to start your app and verify the app is running. There are more details on rerun's usage available in the gem's [GitHub README](https://github.com/alexch/rerun#usage). Gem's are usually on GitHub and their README's full of helpful instructions about how to use them.

In this case we are prefixing with `bundle exec` again in order to ensure we are using the gems in the Gemfile.lock, and the `--` symbol is there to assert that the command we want rerun to operate with is `rackup -p $PORT -o $IP`. We could achieve the same effect with `bundle exec rerun "rackup -p $PORT -o $IP"`. They are equivalent. More importantly any detected changes will now cause the server to restart automatically, similar to the use of `guard` to auto re-run specs when files change.
Any detected changes will now cause the server to restart automatically, similar to the use of `guard` to auto re-run specs when files change.

Modify `app.rb` to print a different message, and verify that the change is detected by refreshing your browser tab with the running app. Also before we move on you should commit your latest changes to git.

Deploy to Heroku
----------------
Heroku is a cloud platform-as-a-service (PaaS) where we can deploy our Sinatra (and later Rails) applications in a more robust way than via Cloud9. If you don't have an account yet, go sign up at http://www.heroku.com. You'll need your login and password for the next step.
Heroku is a cloud platform-as-a-service (PaaS) where we can deploy our Sinatra (and later Rails) applications in a more robust way than via Cloud9 or Codio. If you don't have an account yet, go sign up at http://www.heroku.com. You'll need your login and password for the next step.

If you're developing locally, install Heroku CLI following [instructions](https://devcenter.heroku.com/articles/heroku-cli).

Expand All @@ -170,7 +164,7 @@ If using Cloud9, update your Heroku Toolbelt installation by typing the followin
$ wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh
```

Log in to your Heroku account by typing the command: `heroku login` in the terminal. This will connect you to your Heroku account.
Log in to your Heroku account by typing the command: `heroku login -i` in the terminal. This will connect you to your Heroku account.

While in the root directory of your project (not your whole workspace), type `heroku create` to create a new project in Heroku. This will tell the Heroku service to prepare for some incoming code, and locally it will add a remote git repository for you called `heroku`.

Expand Down