A Swift DB2 implementation of the TodoList backend
- Install Swift 3
XCode 8 if on macOS or the toolchain if on Linux
- Install dependencies:
macOS:
brew install wget unixodbc
Linux:
sudo apt-get update
sudo apt-get install -y clang unixodbc-dev unzip wget tar
- Install the DB2 system driver:
wget https://github.com/IBM-DTeam/swift-for-db2-cli/archive/master.zip && unzip master.zip && cd swift-for-db2-cli-master && sudo ./cli.sh && . env.sh && cd .. && rm -f master.zip && rm -rf swift-for-db2-cli-master
- Clone the repository:
git clone https://github.com/IBM-Swift/todolist-db2
- Compile the application
macOS:
swift build -Xcc -I/usr/local/include -Xlinker -L/usr/local/lib
Linux:
swift build -Xcc -I/usr/local/include -Xlinker -L/usr/local/lib
##Setup DB2 service
-
Login to your Bluemix account (create an account, if necessary)
-
Open the Bluemix catalog by clicking the blue hexagon '+' icon
-
Select your desired plan and click the Create button. You will now have a provisioned dashDB Database in your services.
-
Open the newly created service in Bluemix, then open the dashDB dashboard.
-
Select "Tables" from the menu on the left, then click "Add Table" button. Enter the following DDL statement to create your TODOS table:
CREATE TABLE "todos"
(
"todoid" INT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1),
"title" VARCHAR(256) NOT NULL,
"ownerid" VARCHAR(128) NOT NULL,
"completed" INT NOT NULL,
"orderno" INT NOT NULL
);
Change the default parameters in Sources/TodoList/TodoList.swift to the parameters of your DB2 instance - hostname, port, uid and password.
The parameters of your DB2 instance can be copied from your dashDB settings, "Service Credentials" tab.
-
Install Docker on your operating system
-
Build the Docker image:
sudo docker build -t todolist-db2 .
- Run the web server:
sudo docker run -p 8090:8090 -d todolist-db2
##Deploy to Bluemix To deploy this app to Bluemix, you have to build and a deploy a Docker image with the app.
-
Login to your Bluemix account (create an account, if necessary)
-
Download and install the Cloud Foundry tools.
-
Login to Bluemix CLI
cf login
bluemix api https://api.ng.bluemix.net
bluemix login -u username -o org_name -s space_name
-
Download and install the [IBM Container's Plugin] (https://console.ng.bluemix.net/docs/containers/container_cli_cfic_install.html)
-
Configure the IBM Container's Plugin - set your IBM Container Namespace.
-
Login into cf ic
cf ic login
- Build the Docker image:
sudo docker build -t todolist-db2 .
- Tag the Docker image:
docker tag todolist-db2 registry.ng.bluemix.net/<NAMESPACE FROM STEP 5>/todolist-db2
- Push the Docker image:
docker push registry.ng.bluemix.net/<NAMESPACE FROM STEP 5>/todolist-db2
- Go to Bluemix and click on
All Items
- Click on the
+
sign to create a new Container
- Select the Docker image that was pushed in Step 7
- Configure the Container as follows. Make sure to switch from
Single
toScalable Group
and to set HTTP port to 8090 (the your app listens to)
-
Create the Container
-
The URL of the app appears in the "Routes" field of the Container Overview
-
Now you can test and access your app by the URL from step 15. In particular, when accessing the app's URL, a list of currently existing todo items will be returned. Note that you must not to append the port to the URL, the default ports will be used. (The port 8090 that you specified in step 13 is used by Bluemix to access your app and is mapped to the default HTTP/HTTPS ports)
##Test
- Clone the Tests to your project:
git clone https://github.com/IBM-Swift/todolist-tests Tests
- Run the tests:
swift test -Xcc -I/usr/local/include -Xlinker -L/usr/local/lib