ctfs

6 Steps to Deploying a Swift To-Do List Sample App Without A Command Line

IBM Cloud Tools for Swift (ICT) provides Mac users with a simple interface for deploying, managing and monitoring end-to-end Swift applications. The application integrates with tools designed by IBM Swift Engineers to easily get started writing Swift on the Server. Download the Beta version of ICT to your Mac.

A previous post showed how to set up a To-Do list using Kitura, a lightweight web framework that allows you to easily build web services with complex routes. Below, I will walk through how to deploy that To-Do List to Bluemix, IBM’s Cloud Platform, using ICT instead of a Command Line Interface. ICT offers many benefits you typically wouldn’t get by deploying through a CLI. It allows you to easily organize your Projects by grouping related client-side and server-side code written in Swift; deploy the server-side code to Bluemix with one simple click; then monitor and manage your Projects through Mac’s native notifications, even when not actively using the application.

1. Download the application and get a Bluemix account

Download the Beta version to your Mac.

Before using the app, you will need to create and sign in to your Bluemix account. Bluemix is IBM’s cloud platform where you can host and integrate services. If you do not have a Bluemix ID, sign up for one and get started with your free 30-day trial. To learn more about what Bluemix offers, click here.

1

After creating an account, log in to Bluemix to set up your Org and Spaces. Orgs are for accounting purposes. If you belong to your business’s larger Org, your account will be paid for and managed by them. Spaces are areas for organizing shared Bluemix Applications within your Org. You may want to set up a test space to easily distinguish between test Projects and Projects in production. You will also notice that Bluemix asks for your region. Bluemix servers sit across the globe to optimize your application. Early versions of ICT only support US South, so select US South as your region in order to use our application. Future versions will support other regions. To sum up, your Cloud Runtime will belong to a Space within your Org running on servers in the US South region.

2. Download the Kitura To-Do List Sample App

Clone the Kitura To-Do List onto your machine. Use this URL to git clone: https://github.com/IBM-Swift/todolist-couchdb.git

3. Create a Kitura Project

Open ICT. From the Projects view within the application, click the blue “+” icon in the upper right hand corner.

2

Select Create Kitura Project.

3

Enter a Project Name and click Create Kitura Project.

4

Enter a Cloud Runtime Name. This will generate a Cloud Runtime URL on Bluemix. Select the space on Bluemix where you would like to deploy. Click Next.

5

Choose a location to save your files.

6

You will see a loading screen signifying that ICT is cloning the Kitura Buildpack to your computer, deploying and compiling the code to Bluemix, then running the Project on the server. It may take 5-7 minutes for ICT to do this for you in the background.

4. Create a Cloudant service

Click here to launch the Bluemix website and sign in.

7

Navigate to your dashboard then click Work With Data under Data & Analytics.

8

Select New Service.

9

Choose Cloudant NoSQL DB under Full-Service.

10

Click Choose Cloudant NoSQL DB on the next page to get started.

11

Under Add Service, choose the space where you created your Cloud Runtime. Under App, choose your Cloud Runtime name. If your Cloud Runtime is not an option, the application either needs more time to start it ,or there was an error. ICT will notify you once it’s running or if an error occurred causing it to stop.

Under Service name, type “TodoList-Cloudant”. The service name needs to be exactly that or the program will not run successfully. Then click Create.

12

Click Restage on the following screen.

13

On the left hand column under your Cloud Runtime name, you’ll see Cloudant NoSQL DB under Services. Click it to see the view then click launch in the upper right hand corner of the screen.

14

Select Create Database and name it “todolist”. Then click Create.

15

Select the “+” icon next to All Documents then choose New View.

16

This view will be called “example”. The Index name should be “all_todos” and paste the following function in the Map function:

function (doc) {
	if (doc.type == 'todo' && doc.active) {
	emit(doc._id, [doc.title, doc.completed, doc.order]);
	}
}

Reduce should be none.

Click Create Document and Build Index.

17

Click the “+” icon next to example and select new view.

18

The Index name should be “total_todos” and paste the following function in Map function:

function (doc) {
	if (doc.type == 'todo' && doc.active) {
	emit(doc._id, 1);
	}
}

Reduce should be _count.

19

Now you have your Cloudant service set up to run the to-do list.

5. Deploy the Kitura To-Do List

Now you must move the cloned Kitura To-Do List files into your Project folder. Do this by using Finder to copy all of the contents of the cloned ToDo List, then pasting it within your Project folder where ICT saved the Kitura Buildpack. You will need to replace all of the Kitura Buildpack files with the To-Do List files because the manifest.yml, Package.swift, Procfile, and Source files are all customized for the To-Do List. For more information on how these files were created, visit the Kitura To-Do List tutorial by clicking here.

Deploy the updated files to Bluemix by clicking the deploy icon (signified by a cloud with an arrow going into it).

20

6. It works!

Navigate to:
http://www.todobackend.com/client/index.html?https://[Your Cloud Runtime Name].mybluemix.net/

Todobackend.com is acting as the client-side of the application, pointing to the server-side code you deployed in the last step. If you navigate to your Cloud Runtime URL, you will see a version that is not stylized.

Don’t be surprised if the deployment isn’t immediate. In the background, the application is installing and uploading items to make the process work. In some situations, the Beta version takes up to 10 minutes to deploy. We are actively working on reducing that time for our users.

Type to-do items then refresh the page to prove that your Cloudant Service saved the items. Or, you can navigate to your all_todos view within the Cloudant database to see your items.

21

22

If you have questions along the way, reach out to us through dWAnswers. We are actively working on improving the experience of adding existing Swift on the Server files. If you would like to give feedback for future enhancements, fill out our survey.

To learn more about how to get started, check out our demo. You can visit the Swift@IBM website to view even more demos about Swift initiatives. If you’re new to Swift on the Server, check out our Sandbox to start learning now.

9 Comments on "6 Steps to Deploying a Swift To-Do List Sample App Without A Command Line"

  1. […] Tutorial: Deploying a Swift to-do list app to the cloud (Emma Tucker) […]

  2. Emma Tucker thank you for taking the time to put together this article. I’m running into some trouble deploying the app using the steps outlined above.

    The Bluemix console is reporting the following:

    —–> Installing Swift DEVELOPMENT-SNAPSHOT-2016-06-20-a
    DEPENDENCY_MISSING_IN_MANIFEST: ‘swift-DEVELOPMENT-SNAPSHOT-2016-06-20-a.tar.gz’
    Staging failed: Buildpack compilation step failed

    I’m wondering what version of the toolchain was used when you tried this last, and if there is a recommended commit I could check out to make sure I can follow the steps above.

  3. I was using https://github.com/IBM-Swift/TodoList-CouchDB, commit [c8246f2]. I tried again on the current commit [2c3ca1a], and am getting a little further, but it looks like the app is crashing.

    App instance exited with guid fd8edfed-foo-bar-baz payload: {“cc_partition”=>”default”, “droplet”=>”fd8edfed-foo-bar-baz”, “version”=>”3419b26a-foo-bar-baz”, “instance”=>”ef481ffoobarbaz”, “index”=>0, “reason”=>”CRASHED”, “exit_status”=>255, “exit_description”=>”app instance exited”, “crash_timestamp”=>1469652231}

    The link you supplied in the comment above points to commit [12392d0]. When I checked out that commit and tried it, I received the following error while trying to deploy:

    swift-build: error: The dependency graph could not be satisfied (https://github.com/IBM-Swift/Kitura.git)

    • Hi, yesterday we discovered what should be the issue and hope to release that fix today or tomorrow. Thank you for bringing this to our attention!

  4. it never starts “App staging failed in the buildpack compile phase”

    • Hi, thank you for the comment. We will hopefully have this fixed within the tool today or tomorrow.

Join The Discussion

Your email address will not be published. Required fields are marked *