Skip to content

Commit

Permalink
Merge pull request #35 from KyeMaloy97/issue.swift4
Browse files Browse the repository at this point in the history
Migrate to Swift 4
  • Loading branch information
Aaron Liberatore authored Nov 2, 2017
2 parents 44b42e4 + 0529aea commit 0a52933
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 135 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/.build
/Packages
/*.xcodeproj
TodoListFull.xcworkspace
couchdb.stdout
couchdb.stderr
Package.resolved
/cloud_config.json
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1
4.0
15 changes: 10 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
branches:
only:
- master
- /^issue.*$/

matrix:
include:
- os: linux
dist: trusty
sudo: required
- os: osx
osx_image: xcode8
osx_image: xcode9
sudo: required

before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
Expand All @@ -14,11 +19,11 @@ before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then open "Apache CouchDB.app"/ && sleep 5 ; fi

- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update -y ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then wget https://swift.org/builds/swift-3.1-release/ubuntu1404/swift-3.1-RELEASE/swift-3.1-RELEASE-ubuntu14.04.tar.gz ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar xzvf swift-3.1-RELEASE-ubuntu14.04.tar.gz ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export PATH=swift-3.1-RELEASE-ubuntu14.04/usr/bin:$PATH ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then wget https://swift.org/builds/swift-4.0-release/ubuntu1404/swift-4.0-RELEASE/swift-4.0-RELEASE-ubuntu14.04.tar.gz ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar xzvf swift-4.0-RELEASE-ubuntu14.04.tar.gz ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export PATH=swift-4.0-RELEASE-ubuntu14.04/usr/bin:$PATH ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get -y install couchdb clang-3.8 ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo couchdb -b && sleep 5 ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo mkdir /var/run/couchdb && sudo couchdb -b && sleep 5 ; fi

script:
- swift build
Expand Down
96 changes: 0 additions & 96 deletions Package.pins

This file was deleted.

36 changes: 24 additions & 12 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

/**
* Copyright IBM Corporation 2017
*
Expand All @@ -16,22 +19,31 @@

import PackageDescription


let package = Package(
name: "TodoList",
products: [],

dependencies: [
.package(url: "https://github.com/IBM-Swift/Kitura.git", from: "1.0.0"),
.package(url: "https://github.com/IBM-Swift/Kitura-CouchDB.git", from: "1.7.2"),
.package(url: "https://github.com/IBM-Swift/CloudEnvironment.git", from: "4.0.5"),
.package(url: "https://github.com/IBM-Bluemix/cf-deployment-tracker-client-swift.git", from: "4.0.1"),
.package(url: "https://github.com/rob-deans/CloudConfiguration.git", from: "2.1.0")
],

targets: [
Target(
.target(
name: "TodoList",
dependencies: ["CloudEnvironment", "CouchDB", "Kitura", "CloudFoundryDeploymentTracker"]
),
.target(
name: "Server",
dependencies: [.Target(name: "TodoList")]
dependencies: [.target(name: "TodoList"), "CloudConfiguration"]
),
Target(
name: "TodoList"
.testTarget(
name: "TodoListTests",
dependencies: ["TodoList"]
)
],
dependencies: [
.Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 1),
.Package(url: "https://github.com/davidungar/miniPromiseKit", majorVersion: 4),
.Package(url: "https://github.com/IBM-Swift/Kitura-CouchDB.git", majorVersion: 1),
.Package(url: "https://github.com/IBM-Swift/CloudConfiguration.git", majorVersion: 2),
.Package(url: "https://github.com/IBM-Bluemix/cf-deployment-tracker-client-swift.git", majorVersion: 3)
]
]
)
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
Todo backend is an example of using the [Kitura](https://github.com/IBM-Swift/Kitura) Swift framework for building a productivity app with a database for storage of tasks.

[![Build Status](https://travis-ci.org/IBM-Swift/TodoList-CouchDB.svg?branch=master)](https://travis-ci.org/IBM-Swift/TodoList-CouchDB)
![](https://img.shields.io/badge/Swift-3.1%20RELEASE-orange.svg)
![](https://img.shields.io/badge/Swift-4.0%20RELEASE-orange.svg)
![](https://img.shields.io/badge/platform-Linux,%20macOS-blue.svg?style=flat)
![Bluemix Deployments](https://deployment-tracker.mybluemix.net/stats/9eef579b69ef97de1ef1083552adeea2/badge.svg)

## Quick start for local development:

You can set up your development environment and use XCode 8 for editing, building, debugging, and testing your server application. To use XCode, you must use the command line tools for generating an XCode project.
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.

1. Download [Xcode 8](https://swift.org/download/)
1. Download [Xcode 9](https://swift.org/download/)
2. Download [CouchDB](http://couchdb.apache.org/) and install

```
Expand All @@ -24,7 +24,7 @@ You can set up your development environment and use XCode 8 for editing, buildin
git clone https://github.com/IBM-Swift/TodoList-CouchDB
```

4. Generate an XCode project
4. Generate an Xcode project

```
swift package generate-xcodeproj
Expand All @@ -40,9 +40,9 @@ You can set up your development environment and use XCode 8 for editing, buildin

## Quick start on Linux

To build the project in Linux, you need to first install the Swift 3 toolchain.
To build the project in Linux, you need to first install the Swift 4 toolchain.

1. Install the [Swift 3 RELEASE toolchain](http://www.swift.org)
1. Install the [Swift 4 RELEASE toolchain](http://www.swift.org)

2. Install CouchDB:

Expand All @@ -69,21 +69,21 @@ To build the project in Linux, you need to first install the Swift 3 toolchain.

Then access [http://localhost:8080/](http://localhost:8080/) in your browser to see an empty database.

## Deploying to Bluemix
## Deploying to IBM Cloud

### Using the IBM Cloud Tools for Swift

The TodoList for Cloudant is deployable with a graphical user interface. Download:

- [IBM Cloud Application Tools for Swift](http://cloudtools.bluemix.net/)

### Deploy to Bluemix Button
### Deploy to IBM Cloud Button

You can use this button to deploy TodoList to your Bluemix account, all from the browser. The button will create the application, create and bind any services specified in the manifest.yml file and deploy.
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.

[![Deploy to Bluemix](https://deployment-tracker.mybluemix.net/stats/9eef579b69ef97de1ef1083552adeea2/button.svg)](https://bluemix.net/deploy?repository=https://github.com/IBM-Swift/TodoList-CouchDB.git)

### Deploying Docker to IBM Bluemix Container
### Deploying Docker to IBM Cloud Container

For the following instructions, we will be using our [Bash Script](config.sh) located in the root directory.
You can attempt to complete the whole process with the following command:
Expand Down Expand Up @@ -118,7 +118,7 @@ Or, you can follow the step-by-step instructions below.
./config.sh stop <imageName>
```

4. Push created Docker container to Bluemix
4. Push created Docker container to IBM Cloud

```
./config.sh push-docker <imageName>
Expand All @@ -136,7 +136,7 @@ Or, you can follow the step-by-step instructions below.
./config.sh create-db
```

7. Create a Bluemix container group where your app will live, binding it to your bridge CF application in the process
7. 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>
Expand All @@ -158,7 +158,7 @@ At this point, your app should be deployed! Accessing your apps route should ret

### Manually

Bluemix is a hosting platform from IBM that makes it easy to deploy your app to the cloud. Bluemix also provides various popular databases. [Cloudant](https://cloudant.com/) is an offering that is compatible with the CouchDB database, but provides additional features. You can use Cloudant with your deployed TodoList-CouchDB application.
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](https://cloudant.com/) is an offering that is compatible with the CouchDB database, but provides additional features. You can use Cloudant with your deployed TodoList-CouchDB application.

1. Get an account for [Bluemix](https://console.ng.bluemix.net/registration/)

Expand Down Expand Up @@ -227,7 +227,7 @@ This Swift application includes code to track deployments to [IBM Bluemix](https
* Labels of bound services
* Number of instances for each bound service and associated plan information

This data is collected from the parameters of the `CloudFoundryDeploymentTracker`, the `VCAP_APPLICATION` and `VCAP_SERVICES` environment variables in IBM Bluemix and other Cloud Foundry platforms. This data is used by IBM to track metrics around deployments of sample applications to IBM Bluemix to measure the usefulness of our examples, so that we can continuously improve the content we offer to you. Only deployments of sample applications that include code to ping the Deployment Tracker service will be tracked.
This data is collected from the parameters of the `CloudFoundryDeploymentTracker`, the `VCAP_APPLICATION` and `VCAP_SERVICES` environment variables in IBM Cloud and other Cloud Foundry platforms. This data is used by IBM to track metrics around deployments of sample applications to IBM Cloud to measure the usefulness of our examples, so that we can continuously improve the content we offer to you. Only deployments of sample applications that include code to ping the Deployment Tracker service will be tracked.

### Disabling Deployment Tracking
Deployment tracking can be disabled by removing the following line from `main.swift`:
Expand All @@ -242,4 +242,4 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use

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.
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.
5 changes: 4 additions & 1 deletion Sources/Server/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import CloudFoundryDeploymentTracker
import TodoList
import Configuration
import CloudFoundryConfig
import CloudEnvironment

HeliumLogger.use()

let configFile = "cloud_config.json"
let databaseName = "todolist"

extension TodoList {

public convenience init(config: CloudantService) {
Expand All @@ -42,6 +42,9 @@ let todos: TodoList

let manager = ConfigurationManager()

let cloudEnv = CloudEnv()
let cloudantCredentials = cloudEnv.getCloudantCredentials(name: "MyTodoListDB")

do {
manager.load(.environmentVariables).load(file: configFile)
let cloudantConfig = try manager.getCloudantService(name: "TodoListCloudantDatabase")
Expand Down
7 changes: 3 additions & 4 deletions Sources/TodoList/TodoList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Foundation

import LoggerAPI
import SwiftyJSON
import MiniPromiseKit
import Dispatch

import CouchDB
Expand All @@ -41,9 +40,9 @@ enum Result<T> {
/// TodoList for CouchDB
public class TodoList: TodoListAPI {

static let defaultCouchHost = "127.0.0.1"
static let defaultCouchPort = UInt16(5984)
static let defaultDatabaseName = "todolist"
public static let defaultCouchHost = "127.0.0.1"
public static let defaultCouchPort = UInt16(5984)
public static let defaultDatabaseName = "todolist"

let databaseName = "todolist"
let designName = "todosdesign"
Expand Down

0 comments on commit 0a52933

Please sign in to comment.