DB2 Implementation of TodoList
Swift
Latest commit da5f37a Jan 12, 2017 @tfrank64 tfrank64 Revert "quick deploy to bluemix button test"
This reverts commit 60335ec.
Permalink
Failed to load latest commit information.
Images added ContainerOverview image Oct 16, 2016
Sources primary manifest updates Jan 5, 2017
Tests primary manifest updates Jan 5, 2017
.gitignore Remove API and Web packages. Tests now included. (#9) Oct 16, 2016
.swift-version update swift version to 3.0.2 Dec 19, 2016
.travis.yml typo fix Jan 4, 2017
Dockerfile Update Dockerfile Jan 5, 2017
LICENSE.txt
Package.swift
README.md Revert "quick deploy to bluemix button test" Jan 11, 2017
manifest.yml primary manifest updates Jan 5, 2017

README.md

TodoList DB2 backend

Build Status

Table of Contents

Summary

A Swift DB2 implementation of the TodoList backend

Installation:

  1. Install Swift 3

    XCode 8 if on macOS or the toolchain if on Linux

  2. Install dependencies:

    macOS: brew install wget unixodbc

    Linux: sudo apt-get update sudo apt-get install -y clang unixodbc-dev unzip wget tar

  3. 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

  4. Clone the repository:

    git clone https://github.com/IBM-Swift/todolist-db2

  5. 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

  1. Create the DB2 Service

    cf create-service dashDB Entry TodoList-DB2-Analytics
    
  2. Open the newly created dashDB for Analytics service in your Bluemix services dashboard.

  3. 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
    );
    

    DB2 service

Run the app locally

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.

dashDB Credentials

Using Docker

  1. Install Docker on your operating system

  2. Build the Docker image:

    sudo docker build -t todolist-db2 .

  3. 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.

  1. Login to your Bluemix account (create an account, if necessary)

  2. Download and install the Cloud Foundry tools.

  3. Login to Bluemix CLI

    cf login

    bluemix api https://api.ng.bluemix.net

    bluemix login -u username -o org_name -s space_name

  4. Download and install the IBM Container's Plugin

  5. Configure the IBM Container's Plugin - set your IBM Container Namespace.

  6. Login into cf ic

    cf ic login

  7. Build the Docker image:

    sudo docker build -t todolist-db2 .

  8. Tag the Docker image:

    docker tag todolist-db2 registry.ng.bluemix.net/<NAMESPACE FROM STEP 5>/todolist-db2

  9. Push the Docker image:

    docker push registry.ng.bluemix.net/<NAMESPACE FROM STEP 5>/todolist-db2

  10. Run the Container

    cf ic group create --anti --auto -m 128 --name my-todolist-db2 -p 8090 -n <hostname> -d mybluemix.net registry.ng.bluemix.net/<your namespace>/todolist-db2
    

    Where the <your namespace> is the namespace you chose when setting up IBM Containers. <hostname> is the hostname URL you want your application to run at.

  11. 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

To run tests, run:

swift test -Xcc -I/usr/local/include -Xlinker -L/usr/local/lib