This is an end-to-end introduction, how to run a swift application on Cloud Foundry stack within SAP Cloud Platform.
- Clone Sample App
- Push Application to SCP – CloudFroundry
- Modify iOS app to connect to CF instance
– 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'
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 to the github repo provided by IBM. It seems that the CF community buildpack is no longer maintained.
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:
Create the file Procfile in Foodserver folder, with following content, that CF knows what should be started after an successful upload:
Now the server application can be pushed to
cf api https://api.cf.eu10.hana.ondemand.com cf login 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://foodserver-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")
In a next blog I’ll show you how to extend this server side Swift app with a real database.