Cloud Platform – Server Side Swift Applications with Cloud Foundry

This is an end-to-end introduction, how to run a swift application on Cloud Foundry stack within SAP Cloud Platform.

Steps

* Prerequisites
* Clone Sample App
* Push Application to SCP – CloudFroundry
* Modify iOS app to connect to CF instance

Prerequisites – Cloud Foundry CLI: https://docs.cloudfoundry.org/cf-cli/install-go-cli.html – CocoaPods: https://guides.cocoapods.org/using/getting-started.html (I recommend to install it in user directory via following bash command: gem install cocoapods –user-install echo ‘export PATH=$PATH:$HOME/.gem/ruby/2.3.0/bin’ – Login to your CF account cf api https://api.cf.sap.hana.ondemand.com cf login Clone Sample App IBM has provided a backend sample app for the popular iOS App “FoodTracker” by Apple. git clone https://github.com/IBM/FoodTrackerBackend.git You can now walk through of the tutorial or directly check out the branch “CompletedFoodTracker”.

Push Application to SCP – CloudFroundry  Once the server application successfully runs locally you can push it to you Cloud Foundry instance. Unfortunately, the swift-buildpack in the `manifest.yml` file points to a service, which doesn’t exist in SCP Cloud Foundry environment, yet. Therefor we have to change the buildpack: buildpack: https://github.com/IBM-Swift/swift-buildpack#2.0.10 Which buildpacks are available, can be found out with following command: cf marketplace Modify file .swift-version of the FoodTracker server to meet the version in the buildpack: 4.0.3 Create the file Procfile in Foodserver folder, with following content, that CF knows what should be started after an successful upload: web: FoodServer Now the server application can be pushed to cf push foodserver​ In the output you’ll see for the routes output, under which URL your app is deployed and reachable. It’s something like: https://foodserversql-xxxxxx-yyyyyy.cfapps.eu10.hana.ondemand.com The route name is created dynamically, see manifest.yml file… Modify iOS app to connect to CF instance To communicate with FoodTracker-server via iOS app just replace the baseURL, used for creation the KituraKit class: guard let client = KituraKit(baseURL: “https://foodserver-xxxxxxx-yyyyyyy.cfapps.eu10.hana.ondemand.com”) see sample code line here In a next blog I’ll show you how to extend this server side Swift app with a real database. http://bit.ly/2CWuDhc #SAP #SAPCloud #AI

Subscribe To Newsletter

Sign up for my newsletter and get the latest technology news

2019 © Craig Brown PhD. All rights reserved.