Before You Begin
This 15-minute tutorial shows you how to connect a Ruby application to Oracle MySQL Cloud Service in Oracle Application Container Cloud Service.
Background
Oracle Application Container Cloud Service provides a lightweight infrastructure so that you can run Java, PHP, Node.js, Python, and Ruby applications in Oracle Cloud. To develop more robust applications, you can integrate this cloud service with other Oracle services (for example, Oracle MySQL Cloud Service).
Oracle MySQL Cloud Service provides you the ability to deploy MySQL Server in the Cloud, with each deployment containing a single MySQL Server. You have full access to the features and operations available with MySQL Server, with Oracle providing the computing power, physical storage and tooling to simplify maintenance and management operations.
This tutorial provides you a sample application developed with Sinatra and Active Record.
What Do You Need?
- An Oracle Cloud account
- Completion of Creating an Instance of Oracle MySQL Cloud Service
- cURL 7.0+ with Secure Sockets Layer (SSL) support
- Ruby Employee application service sinatra-employee-service.zip
Create the Startup Script
- Create
sinatra-employee-servicedirectory in your local system. - In the
sinatra-employee-servicedirectory, extract the content of thesinatra-employee-service.zipfile. - Create the
start.shscript file and add the following content:#Install the dependencies specified in the Gemfile bundle install #Run the database migration to create the Employee table. bundle exec rake db:migrate #Run the Sinatra application. Your application must run on the port specified in the PORT environment variable and in the 0.0.0.0 host. rackup -p ${PORT} --host 0.0.0.0 - Create again the
sinatra-employee-service.zipfile with the content of thesinatra-employee-servicedirectory. Make sure thezipfile doesn't contain a subdirectory.
Prepare Your Application for Cloud Deployment
- In your local system, create the
deployment.jsonfile and add the following content. Replace the placeholders with the information of your Oracle MySQL Cloud Service instance:{ "services": [{ "name": "<name-of-your-instance>", "type": "MYSQLCS", "username": "<your-username>", "password": "<your-password>" }] } - Create the
manifest.jsonfile and add the following content:{ "runtime":{ "majorVersion":"2.4.1" }, "command": "sh ./start.sh", "release": {}, "notes": "Employee service developed with Sinatra" }
Deploy Your Application to Oracle Application Container Cloud Service
- Log in to Oracle Cloud at http://cloud.oracle.com/. Enter your account credentials in the Identity Domain, User Name, and Password fields.
- In the Oracle Cloud Services dashboard, click the Action menu
, and select Oracle Application Container Cloud Service. - In the Applications list view, click Create Application.
- In the Create Application dialog box, click Ruby.
- In the Application section, enter
EmployeeServicefor the name of your application and click Browse. - In the File Upload dialog box, select the
sinatra-employee-service.zip.file. - Keep the default values in the Instances and Memory fields and click More Options.
- Click Browse next
to Manifest, select the
manifest.jsonfile, and click Open. - Click Browse next
to Deployment Configuration, select the
deployment.jsonfile, and click Open. - Click Create.
- Wait until the application is created. The URL is enabled when the creation is completed. Copy the URL of your application. You'll use it in the next section.
Test the Application
- In the Oracle Application Container Cloud Service console, click the URL of your application.
- Open a command-line window (or terminal in Linux).
- Create an employee record and replace the
app_endpointplaceholder with the URL of your application.curl -i -X POST -H "Content-Type:application/json" -d "{ \"firstName\" : \"John\", \"lastName\" : \"Smith\",\"birthDate\":\"1957-10-14\", \"phone\":\"193-754-4112\",\"email\":\"john.smith@example.com\",\"title\" : \"Manager\",\"department\" : \"Sales\" }" app_endpoint/employees - Query all employee entities.
curl app_endpoint/employees - Get the employee by ID.
curl app_endpoint/employees/1 - Update the employee.
curl -i -X PUT -H "Content-Type:application/json" -d "{ \"firstName\" : \"John\", \"lastName\" : \"Smith\",\"birthDate\":\"1957-12-08\", \"phone\":\"193-124-8212\",\"email\":\"john.smith@example.com\",\"title\" : \"Manager\",\"department\" : \"IT\" }" app_endpoint/employees/1 - Delete the employee.
curl -i -X DELETE app_endpoint/employees/1
Want to Learn More?
- Oracle Application Container Cloud Service in the Oracle Help Center
- Sinatra website sinatrarb.com
Connect a Ruby Application to MySQL