page-brochureware.php

Getting Started with Swift on IBM Cloud

Introduction

The following tutorial discusses the steps to create, build, run locally and deploy a Swift application. Use the IBM Cloud Developer Tools CLI to access via command line or the web-based IBM App Service on the IBM Cloud dashboard. These tools can generate a server-side Swift application on-demand, fully equipped with a Kitura server, integration with IBM Cloud Services, and deployment configurations for Cloud Foundry and IBM Container Service Kubernetes on IBM Cloud.



Application Architectures

There are several different Swift applications available. The Create Project option, only accessible from the App Service Console, provides a bare bones project in the supported langauges. It contains deployment files for IBM Cloud, and a simple Kitura web server with a default endpoint, but provides the option to generate custom endpoints as defined in a swagger file. The other two paradigms are the Basic Web application and the Backend for Frontend application. The Basic Web application is more robust than the blank application, whereas the Backend for Frontend application comes with far more features by default. Read more about these architectures and their features in the Web Basic and Backend for Frontend tutorials. Alternatively, any Swift application can be run on IBM Cloud by injecting the required deployment files.

Using the CLI

The IBM Cloud Developer Tools CLI provides a command driven approach for creating, developing, and deploying a web application. It is ideal for developers that would like to use command line control to develop end-to-end microservice applications.

  1. Install prerequisites

    For Mac and Linux Operation Systems use the following curl command to install git, docker, kubectl, helm and IBM Cloud Developer Tools CLI.


    curl -sL https://ibm.biz/idt-installer | bash

    For Windows, open PowerShell as administrator and use the following equivalent command:

    Set-ExecutionPolicy Unrestricted; iex(New-Object Net.WebClient).DownloadString('http://ibm.biz/idt-win-installer')

  2. Create

    Use the bx dev create command from IBM Cloud Developer Tools CLI to generate a pre-configured starter.
    • Note: Be sure to log in with an IBM Cloud account to create a project. First-time users can register for a free account. Use the bx login command to login on the command line.
    • Alternatively, you may also use the Open Source Kitura CLI to create a Swift application. The IBM Cloud Developer Tools CLI and Kitura CLI use the same underlying generator technology. The Kitura CLI does not include functions to create Cloud runtime resources, such as DevOps toolchains, Cloud Foundry runtimes, and Kubernetes clusters, nor to deploy to these resources. If using the Kitura CLI method to create a Swift application, continue to the instructions on the Kitura CLI Github readme.

  3. Build

    Use the bx dev build command to build the application.
  4. Run locally

    Use the bx dev run command to run the application locally.

    Test the running application in a browser by going to localhost:8080.
  5. Deploy to IBM Cloud

    Use bx dev deploy to deploy to IBM Cloud as a Cloud Foundry application. To deploy to IBM Container Service in IBM Cloud using Kubernetes techniques, use bx dev deploy –target container. Check out our documentation for more information on setting up a Kubernetes cluster in IBM Cloud.

Using the App Service

IBM Cloud App Service is an online console that makes it easy to quickly create and manage applications, configure and attach services (such as databases, notifications, and Watson), and monitor and deploy apps. The App Service can be used to deploy to IBM Cloud as a Cloud Foundry application, to IBM Container Service or through a DevOps toolchain.
  1. Create

    1. From the Starter Kits page in the App Service, select a Starter Kit based in the desired programming language. For example, for a Swift application, go to Swift Kitura Basic and click Select Starter Kit.
      • Note: Be sure to log in with an IBM Cloud account to create a project. First-time users can register for a free account.
    2. Enter desired project name.
    3. Enter a unique hostname. This hostname will be used for the project’s route.
      For example: my-kitura-project.mybluemix.net.
    4. Click Create Project. After the project is created, select the option to deploy using a toolchain OR continue to build and deploy from the command line.
    5. If creating a toolchain, click Create Toolchain in the Deploy with Toolchain panel. Select a deployment method. Choices include:
      • Cloud Foundry App, where underlying infrastructure does not need to be managed.
      • Kubernetes Cluster, where a set of worker nodes can be provisioned and configured, e.g. VMs, to deploy and manage highly available application containers.

      Click Create after configuring any options to create the toolchain.
    6. If continuing with the CLI, download the project to the local machine, unzip it and cd into the root directory. Then install the prerequisites with the following curl command:

      curl -sL https://ibm.biz/idt-installer | bash

      Then continue with the build and deploy steps below.

  2. Build

    Use the bx dev build command to build your application, and the bx dev run command to run and debug your application locally.
  3. Deploy to IBM Cloud

    Use bx dev deploy to deploy to IBM Cloud as a Cloud Foundry application. To deploy to IBM Container Service in IBM Cloud using Kubernetes techniques, use bx dev deploy –target container. For more information on setting up a Kubernetes cluster in IBM Cloud go here.

Conclusion

This tutorial illustrates how to create and deploy a project using two approaches: the IBM Cloud Developer Tools CLI and the IBM Cloud App Service. For more information, check out Swift@IBM and take a look at the following tutorials: