{"id":45471,"date":"2016-04-19T21:36:51","date_gmt":"2016-04-19T18:36:51","guid":{"rendered":"https:\/\/www.altoros.com\/blog\/?p=45471"},"modified":"2024-08-27T06:17:54","modified_gmt":"2024-08-27T03:17:54","slug":"sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis","status":"publish","type":"post","link":"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/","title":{"rendered":"Sinatra Starter for Predix: Ruby App with PostgreSQL and Redis"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2019\/07\/sinatra-starter-for-predix-platform-v1.png\" alt=\"sinatra-starter-for-predix-platform-v1\" width=\"200\" style=\"margin: 0px 0px 0px 10px;\" class=\"alignright size-full wp-image-45472\" \/><\/p>\n<p>The technical requirements for the <a href=\"https:\/\/www.altoros.com\/blog\/tag\/iot\/\">Internet of Things<\/a> (IoT) server applications can substantially differ from the ones applied to the Internet of Humans. First of all, the need for any visual interfaces is completely eliminated.<\/p>\n<p>These step-by-step instructions are intended to guide you through the process of starting a basic Ruby\/Sinatra application server on <a href=\"https:\/\/www.altoros.com\/blog\/tag\/predix\/\">Predix<\/a>, GE&#8217;s IoT platform for the Industrial Internet. From the post, you can learn how to deploy the application to Predix, as well as configure the PostgreSQL database and Redis.<\/p>\n<p>&nbsp;<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/#Preparing_Sinatra\" >Preparing Sinatra<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/#Deploying_the_application_to_Predix\" >Deploying the application to Predix<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/#Configuring_the_PostgreSQL_database\" >Configuring the PostgreSQL database<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/#Configuring_Redis\" >Configuring Redis<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/#Further_reading\" >Further reading<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Preparing_Sinatra\"><\/span>Preparing Sinatra<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><a href=\"http:\/\/sinatrarb.com\/\" rel=\"noopener noreferrer\" target=\"_blank\">Sinatra<\/a> is a simple Ruby framework that has the flexibility to focus on the main task of exchanging information between the server and clients.<\/p>\n<p>Since we are going to concentrate on Predix deployment rather than on preparing a Sinatra application, we\u2019ll use <a href=\"https:\/\/github.com\/c7\/hazel\" target=\"_blank\" rel=\"noopener noreferrer\">Hazel<\/a> to streamline the process.<\/p>\n<pre style=\"padding-left: 30px;\"><code>gem install hazel\r\nhazel predix_sinatra_starter -d postgres --redis --rvm --git<\/code><\/pre>\n<p><\/p>\n<p>Executing these commands generates a proper Sinatra application skeleton prepared to run PostgreSQL through Sequel and with Redis bindings.<\/p>\n<p><center><a href=\"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2019\/07\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis.png\" rel=\"attachment wp-att-9873\"><img decoding=\"async\" src=\"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2019\/07\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis.png\" alt=\"sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\" width=\"640\" class=\"aligncenter size-full wp-image-45473\" \/><\/a><\/center><\/p>\n<p>You might need to temporarily comment out the <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">Sequel.connect<\/code> attempts in <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">config\/initializers\/database.rb<\/code> until you configure the connection. The command below will start the application for you locally to check that it works.<\/p>\n<pre style=\"padding-left: 30px;\"><code>rackup config.ru<\/code><\/pre>\n<p><\/p>\n<p>To follow along, you can use our <a href=\"https:\/\/github.com\/Altoros\/predix_sinatra_starter\" target=\"_blank\" rel=\"noopener noreferrer\">sample application<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Deploying_the_application_to_Predix\"><\/span>Deploying the application to Predix<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To get started, follow the <a href=\"https:\/\/www.predix.io\/docs#Uva9INX3\" target=\"_blank\" rel=\"noopener noreferrer\">installation instructions<\/a> for the Cloud Foundry CLI binaries.<\/p>\n<pre style=\"padding-left: 30px;\"><code>curl -L \"https:\/\/cli.run.pivotal.io\/stable?release=linux64-binary&source=github\" | tar -zx\r\n.\/cf --version\r\n.\/cf --help<\/code><\/pre>\n<p><\/p>\n<p>Run the <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">cf login -a https:\/\/api.system.aws-usw02-pr.ice.predix.io<\/code> command to enter your authentication data.<\/p>\n<p>Cloud Foundry needs the <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">manifest.yml<\/code> file for your application, which we\u2019re going to create now in the application root.<\/p>\n<pre style=\"padding-left: 30px;\"><code>applications:\r\n - name: sinatra-app\r\n   buildpack: https:\/\/github.com\/cloudfoundry\/ruby-buildpack\r\n   memory: 64M\r\n   stack: cflinuxfs2<\/code><\/pre>\n<p><\/p>\n<p>As we work with the Ruby Cloud Foundry buildpack, there are a couple of things we need to do:<\/p>\n<ol>\n<li style=\"margin-bottom: 6px;\">Declare a Ruby version in your <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">Gemfile<\/code> by adding the following line.<\/li>\n<pre style=\"padding-left: 30px;\"><code>ruby '2.1.8'<\/code><\/pre>\n<p><\/p>\n<li style=\"margin-bottom: 6px;\">Add a <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">Procfile<\/code> starting your application to the root. Ensure it is a valid YAML hash.\n<pre style=\"padding-left: 30px; style=\"margin-top: 6px;\"><code>web: rackup config.ru -p $PORT<\/code><\/pre>\n<p>Reading from the global <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">$PORT<\/code> variable is crucial here, because Cloud Foundry\u2013based Predix assigns you the port to run on and expects you to use it.<\/p>\n<\/li>\n<li>Be sure to add the <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">.cfignore<\/code> file to the root of the application. It should list all files and folders in your project directory tree you don\u2019t want to be uploaded to production.<\/li>\n<\/ol>\n<p>Calling the <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">cf push<\/code> command will upload, bundle, and run our simple Sinatra application.<\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Configuring_the_PostgreSQL_database\"><\/span>Configuring the PostgreSQL database<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Create a local Postgres DB for development.<\/p>\n<pre style=\"padding-left: 30px;\"><code>createdb predix_sinatra_starter_development<\/code><\/pre>\n<p>Update your <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">Rakefile<\/code> with the <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">db:environment<\/code> task.<\/p>\n<pre style=\"padding-left: 30px;\"><code>namespace :db do\r\n  task :environment do\r\n    require 'sequel'\r\n    ENV['RACK_ENV'] ||= 'development'\r\n  end\r\nend<\/code><\/pre>\n<p><\/p>\n<p>If you used Hazel to generate your application, rename its default database configuration file <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">config\/db.yml<\/code> into a standard <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">config\/database.yml<\/code> file. This is the file the Ruby buildpack will replace with an auto-generated one in production. Make sure the file contains your local database\u2019s address.<\/p>\n<pre style=\"padding-left: 30px;\"><code>development: \"postgres:\/\/username@localhost\/predix_sinatra_starter_development\"<\/code><\/pre>\n<p><\/p>\n<p>Note that the simplest database setup might result in Postgres refusing the connection due to no password being supplied. My usual local development databases run in a not-so-safe mode of allowing any local connections, but you can tweak this step of database setup to use password protection.<\/p>\n<p>Let\u2019s create a migration that will demonstrate we have a proper connection between the application and the database.<\/p>\n<p><code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">db\/migrate\/001_create_items_table.rb:<\/code><\/p>\n<p><center><a href=\"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2016\/04\/ge-predix-sinatra-starter-for-ruby-postgresql-and-redis.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2016\/04\/ge-predix-sinatra-starter-for-ruby-postgresql-and-redis.png\" width=\"410\" height=\"262\" class=\"aligncenter size-full wp-image-67833\" \/><\/a><\/center><\/p>\n<p>Add an indicator that we have data access from Sinatra to <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">views\/welcome.erb<\/code>:<\/p>\n<pre style=\"padding-left: 30px;\"><code>&lt;%= DB[:items].map(:name)  %&gt;<\/code><\/pre>\n<p><\/p>\n<p>Create a Postgres service as described in <a href=\"https:\/\/www.predix.io\/docs\/?r=118945#foZFNrXO\" target=\"_blank\" rel=\"noopener noreferrer\">Predix Documentation<\/a> and associate it with your application.<\/p>\n<pre style=\"padding-left: 30px;\"><code>cf create-service postgres shared-nr sinatra-postgres-test\r\ncf bind-service sinatra-app sinatra-postgres-test\r\ncf restage sinatra-app<\/code><\/pre>\n<p>As we\u2019ve already mentioned, the Ruby buildpack writes a new <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">database.yml<\/code> file. However, the file is ERB-enhanced, so it will fail our current application\u2019s database initialization. To avoid that, Sinatra can take a note from Rails, which runs this file through ERB when loading it, to allow various dynamic options.<\/p>\n<p>In the <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">config\/initializers\/database.rb<\/code> file, replace <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">settings = YAML::load_file(\"config\/database.yml\")<\/code> with the input provided below.<\/p>\n<pre style=\"padding-left: 30px;\"><code>require \u2018erb\u2019\r\nsettings = YAML.load(ERB.new(File.read('config\/database.yml')).result)<\/code><\/pre>\n<p><\/p>\n<p>Finally, update <code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">Procfile<\/code> for it to try running the migrations each time we deploy.<\/p>\n<p>To limit the number of times the migration gets triggered, you can add a classic Cloud Foundry Rake task, limiting the Rake execution to only the first instance (when in the batch).<\/p>\n<p><code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">Rakefile<\/code>:<\/p>\n<pre style=\"padding-left: 30px;\"><code>namespace :cf do\r\n  desc 'Only run on the first application instance'\r\n    task :on_first_instance do\r\n      instance_index = JSON.parse(ENV[\"VCAP_APPLICATION\"])[\"instance_index\"] rescue nil\r\n      exit(0) unless instance_index == 0\r\n    end\r\nend\r\n<\/code><\/pre>\n<p><\/p>\n<p><code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">Procfile:<\/code><\/p>\n<pre style=\"padding-left: 30px;\"><code>web: bundle exec rake cf:on_first_instance db:migrate && rackup config.ru -p $PORT<\/code><\/pre>\n<p><\/p>\n<p>Push the new application version:<\/p>\n<pre style=\"padding-left: 30px;\"><code>cf push<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Configuring_Redis\"><\/span>Configuring Redis<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Setting up Redis requires following pretty much the same steps as configuring PostgreSQL.<\/p>\n<pre style=\"padding-left: 30px;\"><code>cf create-service redis-1 shared-vm sinatra-redis-test         \r\ncf bind-service sinatra-app sinatra-redis-test<\/code><\/pre>\n<p>Modify the Redis initializer to read the configuration from an environment variable.<\/p>\n<p><code style=\"color: #222222; background-color: #e6e6e6; padding: 1px 2px;\">config\/initializers\/redis.rb:<\/code><\/p>\n<pre style=\"padding-left: 30px;\"><code>if ENV['VCAP_SERVICES']\r\n   require 'json'\r\n   credentials = JSON.parse(ENV['VCAP_SERVICES'])[\"redis-1\"].first[\"credentials\"]\r\n   REDIS = Redis.new(credentials)\r\nend<\/code><\/pre>\n<p>You can also see this and other production variables by running the following command.<\/p>\n<pre style=\"padding-left: 30px;\"><code>cf env sinatra-app<\/code><\/pre>\n<p><\/p>\n<p>Deploy the new version.<\/p>\n<pre style=\"padding-left: 30px;\"><code>cf push<\/code><\/pre>\n<p><\/p>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Further_reading\"><\/span>Further reading<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li><a href=\"https:\/\/www.altoros.com\/blog\/get-started-with-predix-deploying-a-rails-app-and-binding-services\/\">Get Started with Predix: Deploying a Rails App and Binding Services<\/a><\/li>\n<li><a href=\"https:\/\/www.altoros.com\/blog\/using-predix-mobile-services-to-create-a-cross-platform-app\/\">Using Predix Mobile Services for a Cross-platform App<\/a><\/li>\n<li><a href=\"https:\/\/www.altoros.com\/blog\/deploying-an-asp-net-application-to-ge-predix\/\">Deploying an ASP.NET Application to GE Predix<\/a><\/li>\n<\/ul>\n<hr \/>\n<p><center><small>This blog post was written by <a href=\"https:\/\/www.altoros.com\/blog\/author\/dmitry-savitski\/\">Dmitry Savitski<\/a>, edited by <a href=\"https:\/\/www.altoros.com\/blog\/author\/viktoryia-fedzkovich\/\">Victoria Fedzkovich<\/a> and <a href=\"https:\/\/www.altoros.com\/blog\/author\/alex\/\">Alex Khizhniak<\/a>.<\/small><\/center><\/p>\n","protected":false},"excerpt":{"rendered":"<\/p>\n<p>The technical requirements for the Internet of Things (IoT) server applications can substantially differ from the ones applied to the Internet of Humans. First of all, the need for any visual interfaces is completely eliminated.<\/p>\n<p>These step-by-step instructions are intended to guide you through the process of starting a basic Ruby\/Sinatra [&#8230;]<\/p>\n","protected":false},"author":119,"featured_media":45473,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":"","_links_to":"","_links_to_target":""},"categories":[214],"tags":[873,117,647],"class_list":["post-45471","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-cloud-native","tag-iot","tag-predix"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Sinatra Starter for Predix: Ruby App with PostgreSQL and Redis | Altoros<\/title>\n<meta name=\"description\" content=\"With a source code of a sample Sinatra app, learn how to streamline the process of preparing it with Hazel before configuring the databases.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Sinatra Starter for Predix: Ruby App with PostgreSQL and Redis | Altoros\" \/>\n<meta property=\"og:description\" content=\"The technical requirements for the Internet of Things (IoT) server applications can substantially differ from the ones applied to the Internet of Humans. First of all, the need for any visual interfaces is completely eliminated. These step-by-step instructions are intended to guide you through the process of starting a basic Ruby\/Sinatra [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/\" \/>\n<meta property=\"og:site_name\" content=\"Altoros\" \/>\n<meta property=\"article:published_time\" content=\"2016-04-19T18:36:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-27T03:17:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2019\/07\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis.png\" \/>\n\t<meta property=\"og:image:width\" content=\"760\" \/>\n\t<meta property=\"og:image:height\" content=\"584\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Dmitry Savitski\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dmitry Savitski\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\\\/\"},\"author\":{\"name\":\"Dmitry Savitski\",\"@id\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/#\\\/schema\\\/person\\\/a787fe0020308b728e68ad4a4ff571ca\"},\"headline\":\"Sinatra Starter for Predix: Ruby App with PostgreSQL and Redis\",\"datePublished\":\"2016-04-19T18:36:51+00:00\",\"dateModified\":\"2024-08-27T03:17:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\\\/\"},\"wordCount\":720,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis.png\",\"keywords\":[\"Cloud-Native\",\"IoT\",\"Predix\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.altoros.com\\\/blog\\\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\\\/\",\"url\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\\\/\",\"name\":\"Sinatra Starter for Predix: Ruby App with PostgreSQL and Redis | Altoros\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis.png\",\"datePublished\":\"2016-04-19T18:36:51+00:00\",\"dateModified\":\"2024-08-27T03:17:54+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/#\\\/schema\\\/person\\\/a787fe0020308b728e68ad4a4ff571ca\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.altoros.com\\\/blog\\\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis.png\",\"contentUrl\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis.png\",\"width\":760,\"height\":584},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Sinatra Starter for Predix: Ruby App with PostgreSQL and Redis\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/\",\"name\":\"Altoros\",\"description\":\"Insight\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/#\\\/schema\\\/person\\\/a787fe0020308b728e68ad4a4ff571ca\",\"name\":\"Dmitry Savitski\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/dmitry-savitski-96x96.jpeg\",\"url\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/dmitry-savitski-96x96.jpeg\",\"contentUrl\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/dmitry-savitski-96x96.jpeg\",\"caption\":\"Dmitry Savitski\"},\"description\":\"Dmitry Savitski is a software engineer at Altoros. He specializes in web development using Ruby and JavaScript as his primary tools. Dmitry has a keen interest in the 12-factor application approach and the ways in which different Cloud Foundry implementations\u2014including Predix\u2014support this methodology.\",\"url\":\"https:\\\/\\\/www.altoros.com\\\/blog\\\/author\\\/dmitry-savitski\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Sinatra Starter for Predix: Ruby App with PostgreSQL and Redis | Altoros","description":"With a source code of a sample Sinatra app, learn how to streamline the process of preparing it with Hazel before configuring the databases.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/","og_locale":"en_US","og_type":"article","og_title":"Sinatra Starter for Predix: Ruby App with PostgreSQL and Redis | Altoros","og_description":"The technical requirements for the Internet of Things (IoT) server applications can substantially differ from the ones applied to the Internet of Humans. First of all, the need for any visual interfaces is completely eliminated. These step-by-step instructions are intended to guide you through the process of starting a basic Ruby\/Sinatra [...]","og_url":"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/","og_site_name":"Altoros","article_published_time":"2016-04-19T18:36:51+00:00","article_modified_time":"2024-08-27T03:17:54+00:00","og_image":[{"width":760,"height":584,"url":"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2019\/07\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis.png","type":"image\/png"}],"author":"Dmitry Savitski","twitter_misc":{"Written by":"Dmitry Savitski","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/#article","isPartOf":{"@id":"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/"},"author":{"name":"Dmitry Savitski","@id":"https:\/\/www.altoros.com\/blog\/#\/schema\/person\/a787fe0020308b728e68ad4a4ff571ca"},"headline":"Sinatra Starter for Predix: Ruby App with PostgreSQL and Redis","datePublished":"2016-04-19T18:36:51+00:00","dateModified":"2024-08-27T03:17:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/"},"wordCount":720,"commentCount":0,"image":{"@id":"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/#primaryimage"},"thumbnailUrl":"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2019\/07\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis.png","keywords":["Cloud-Native","IoT","Predix"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/","url":"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/","name":"Sinatra Starter for Predix: Ruby App with PostgreSQL and Redis | Altoros","isPartOf":{"@id":"https:\/\/www.altoros.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/#primaryimage"},"image":{"@id":"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/#primaryimage"},"thumbnailUrl":"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2019\/07\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis.png","datePublished":"2016-04-19T18:36:51+00:00","dateModified":"2024-08-27T03:17:54+00:00","author":{"@id":"https:\/\/www.altoros.com\/blog\/#\/schema\/person\/a787fe0020308b728e68ad4a4ff571ca"},"breadcrumb":{"@id":"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/#primaryimage","url":"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2019\/07\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis.png","contentUrl":"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2019\/07\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis.png","width":760,"height":584},{"@type":"BreadcrumbList","@id":"https:\/\/www.altoros.com\/blog\/sinatra-starter-for-predix-ruby-app-with-postgresql-and-redis\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.altoros.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Sinatra Starter for Predix: Ruby App with PostgreSQL and Redis"}]},{"@type":"WebSite","@id":"https:\/\/www.altoros.com\/blog\/#website","url":"https:\/\/www.altoros.com\/blog\/","name":"Altoros","description":"Insight","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.altoros.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.altoros.com\/blog\/#\/schema\/person\/a787fe0020308b728e68ad4a4ff571ca","name":"Dmitry Savitski","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2019\/07\/dmitry-savitski-96x96.jpeg","url":"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2019\/07\/dmitry-savitski-96x96.jpeg","contentUrl":"https:\/\/www.altoros.com\/blog\/wp-content\/uploads\/2019\/07\/dmitry-savitski-96x96.jpeg","caption":"Dmitry Savitski"},"description":"Dmitry Savitski is a software engineer at Altoros. He specializes in web development using Ruby and JavaScript as his primary tools. Dmitry has a keen interest in the 12-factor application approach and the ways in which different Cloud Foundry implementations\u2014including Predix\u2014support this methodology.","url":"https:\/\/www.altoros.com\/blog\/author\/dmitry-savitski\/"}]}},"_links":{"self":[{"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/posts\/45471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/users\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/comments?post=45471"}],"version-history":[{"count":9,"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/posts\/45471\/revisions"}],"predecessor-version":[{"id":67835,"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/posts\/45471\/revisions\/67835"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/media\/45473"}],"wp:attachment":[{"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/media?parent=45471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/categories?post=45471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.altoros.com\/blog\/wp-json\/wp\/v2\/tags?post=45471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}