This tutorial will show you how to create a basic ruby on rails application locally and prepare/deploy it to Azure App Service on Linux
- Ruby 2.3.3 is installed onto your development machine however you want (RVM or rbenv etc)
- git is installed on your development machine
- Azure account + subscription
- This tutorial is written under the context of an Ubuntu environment, so all system commands are bash specific
- create a separate directory to work in
mkdir workspace
;cd workspace
- Initialize ruby and check its version using
ruby -v
- Install rails using
gem install rails
- Create a new rails application hello-world using
rails new hello-world
If you are using Rails 5.1+, a package.json will be created. You can either delete package.json, add it to your .git-ignore, or in use the command "rails new hello-world --skip-yarn" as the presence of it will interfere with our platform (for now) - Move into created directory
cd hello-world
- Start the rails server
rails server
- Navigate to
localhost:3000
in your web browser of choice
The ruby image, by default, runs the server with the flag -e production
. This requires some special setup, some of which the container takes care of (such as setting a SECRET_KEY_BASE). What you as the user needs to prepare is a root landing page as the default rails landing page, otherwise the website will fail to start.
- Open
config/routes.rb
and add the lineroot 'application#hello'
- Open
app/controllers/application_controller.rb
and add these lines of code:
def hello
render html: "Hello, world from App Service on Linux!"
end
After these steps your landing page should be configured. You can try running the server and navigating to the page yourself to see.
- On the azure portal portal.azure.com, click on the
+
symbol on the sidebar and search forweb apps on linux
- Choose an appropriate application name
- For app service plan, create a new one as such:
- For configure container choose
Ruby 2.3
Your finished settings should look something like this:
- Create the site and browse to the webpage and you should see the default splash page
- Your newly created azure application has built in local git deployment set up. The git link can be found here:
https://{yoursitename}.scm.azurewebsites.net/api/scm/info
and is traditionally formatted as:https://{yoursitename}.scm.azurewebsites.net/{yoursitename}.git
- Go back to your hello world application's home directory in bash and run these git commands:
git init
git remote add azure <link to your sites git>
git add -A
git commit -m "Initial Commit"
git push azure master
- Deployment will take a while, see the github readme for our ruby image to see the steps taken. You may be waiting for a few minutes, but afterwards your output should look like this:
if the git client returns any error indicating the remote hung up, your deployment may still be progressing on the server side. To check the status of your deployment, navigate to this link: https://{yoursitename}.scm.azurewebsites.net/api/deployments
- You will need to manually restart your site to see the new deployment take effect.
Restart may take a while to be put in effect, so after you click restart in the portal, wait a few minutes before navigating back to the website. You may receive 503's while restart is in effect
And when navigating to your site you should see this!