Todo backend is an example of using the Kitura Swift framework for building a productivity app with a database for storage of tasks.
You can set up your development environment and use Xcode 9 for editing, building, debugging, and testing your server application. To use Xcode, you must use the command line tools for generating an Xcode project.
-
Download Xcode 9
-
Download CouchDB and install
brew install couchdb
-
Clone the TodoList CouchDB repository
git clone https://github.com/IBM-Swift/TodoList-CouchDB
-
Generate an Xcode project
swift package generate-xcodeproj
-
Start CouchDB
couchdb
-
Run the
Server
target in Xcode and access http://localhost:8080/ in your browser to see an empty database.
To build the project in Linux, you need to first install the Swift 4 toolchain.
-
Install the Swift 4 RELEASE toolchain
-
Install CouchDB:
sudo apt-get install couchdb
-
Clone the repository:
git clone https://github.com/IBM-Swift/TodoList-CouchDB
-
Compile the project
swift build
-
Run the server:
.build/debug/Server
Then access http://localhost:8080/ in your browser to see an empty database.
The TodoList for Cloudant is deployable with a graphical user interface. Download:
You can use this button to deploy TodoList to your IBM Cloud account, all from the browser. The button will create the application, create and bind any services specified in the manifest.yml file and deploy.
For the following instructions, we will be using our Bash Script located in the root directory. You can attempt to complete the whole process with the following command:
./config.sh all <imageName>
Or, you can follow the step-by-step instructions below.
-
Install the Cloud Foundry CLI tool and the IBM Containers plugin for CF with the following
./config.sh install-tools
-
Ensure you are logged in with
./config.sh login
-
Build and run a Docker container with the following
./config.sh build <imageName>
To test out created Docker image, use
./config.sh run <imageName> ./config.sh stop <imageName>
-
Push created Docker container to IBM Cloud
./config.sh push-docker <imageName>
-
Create a bridge CF application to later bind to your container
./config.sh create-bridge
-
Create the Cloudant service and bind to your bridge CF application.
./config.sh create-db
-
Create a IBM Cloud container group where your app will live, binding it to your bridge CF application in the process
./config.sh deploy <imageName>
Afterwards, you can ensure Cloudant was bound correctly by viewing all credentials for your group
cf ic group inspect <imageName>
-
Optionally, if you want to populate your database with some sample data, run the following command with your image name:
./config.sh populate-db <imageName>
At this point, your app should be deployed! Accessing your apps route should return your todos, which should be []
if you did not populate the database.
IBM Cloud is a hosting platform from IBM that makes it easy to deploy your app to the cloud. IBM Cloud also provides various popular databases. Cloudant is an offering that is compatible with the CouchDB database, but provides additional features. You can use Cloudant with your deployed TodoList-CouchDB application.
-
Get an account for IBM Cloud
-
Download and install the Cloud Foundry tools:
cf api https://api.ng.bluemix.net cf login
Be sure to run this in the directory where the manifest.yml file is located.
-
Create your Cloudant Service
cf create-service cloudantNoSQLDB Lite TodoListCloudantDatabase
-
Push your app
cf push
*Note This step will take 3-5 minutes
1 of 1 instances running App started
-
Get the credential information:
cf env TodoListCloudantApp
Note you will see something similar to the following, note the hostname, username, and password:
"VCAP_SERVICES": { "cloudantNoSQLDB": [ { "credentials": { "host": "465ed079-35a8-4731-9425-911843621d7c-bluemix.cloudant.com", "password": "<password is here>", "port": 443, "url": "https://465ed079-35a8-4731-9425-911843621d7c-bluemix:efe561fc02805bcb1e2b013dea4c928942951d31cd74cb2e01df3814751d9f45@465ed079-35a8-4731-9425-911843621d7c-bluemix.cloudant.com", "username": "<username is here>" }, }]}
At this point, your app should be deployed! Accessing your apps route should return your todos, which should be []
to start.
Copyright 2017 IBM
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software :distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.