This tutorial will show you:
- Debugging versioning issues in deploying your Rails application
- Serving precompiled assets from your website
- git is installed in your local machine
- A text editor of your choice
- A freshly-created Web App on Linux using Ruby 2.3 (see previous tutorial here for details on how to do that)
- Navigate to the Rails-Bootstrap Github repository here
- Copy the git link from the "clone or download" tab as such
- Clone the git repository to your local machine using the command 'git clone https://github.com/RailsApps/rails-bootstrap.git`
- Run these series of git commands to set up git to your website
git remote add azure https://<your-website-name>.scm.azurewebsites.net/<your-website-name>.git
git push azure master
Your deployment will fail unfortunately as such
-
After digging though the deployment logs in our
/home/site/deployments
directory (through kudu site or ftp copy), we can see versioning issues happening. As the Web Apps on Linux service only currently supports 2.3.3, we need to tailor our application accordingly. -
To fix this, we first open our Gemfile and locate this line:
and change it to this:
- That's not all yet, as if you try deploying again you will see this error in your logs:
To fix this, open up your .ruby-version file and change the line to say 2.3.3
- Now let's redeploy our application. Run these commands:
git add Gemfile
git add .ruby-version
git commit -m "Update ruby version"
git push azure master
Your output should look something like this:
- Let's try and hit our site! Let's see....oh no...
It looks like there's no css. If we check the developer console in chrome we see this:
This happens because rails applications in App Service are run in production mode. If you look in config/environments/production.rb
you will see that an environment variable RAILS_SERVE_STATIC_FILES needs to be set in order to serve static assets.
- In your site application settings in the portal, you need to set
RAILS_SERVE_STATIC_FILES=true
- If we ping our website again we will see this:
This means that we need to precompile our stylesheets and javascript using rake. Luckily, we can do this through our kudu deployment.
- In your site appsettings, set
ASSETS_PRECOMPILE=true
- Check your scm site
<yoursitename>.scm.azurewebsites.net/Env.cshtml
to make sure that you see your appsetting there:
If it's not there, keep refreshing until you do. This is to make sure that the Kudu container has successfully recycled with the new appsetting before we deploy.
- Now, let's kick off a new git deployment. A quick and simple way to do this would be to create a temporary file and add it to your git repo.
touch restart.txt
git add restart.txt
git commit -m "Add restart.txt"
git push azure master
- In your deployment output, you should now see this:
- After deployment is finished, check your site. If it hasn't changed, you might need to manually restart through the portal. After restarting and waiting a couple minutes (the site container has to restart which takes a bit of time), you should see this:
Congrats! You have now created a ruby website that serves precompiled javascript and stylesheet assets (in this case with bootstrap).