Skip to content
This repository was archived by the owner on Nov 24, 2020. It is now read-only.

Commit 9904803

Browse files
feat: Add semantic releases and IAM support
1 parent 5e58d6e commit 9904803

File tree

9 files changed

+179
-113
lines changed

9 files changed

+179
-113
lines changed

.env.example

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
# Service credentials
2-
DISCOVERY_USERNAME=<username>
3-
DISCOVERY_PASSWORD=<password>
1+
# You need to provide either username and password
2+
DISCOVERY_USERNAME=
3+
DISCOVERY_PASSWORD=
4+
# OR IAM API key and URL
5+
DISCOVERY_IAM_APIKEY=
6+
DISCOVERY_IAM_URL=
7+
48

59
ENVIRONMENT_ID=<environment>
610
COLLECTION_ID=<collection>
11+
DISCOVERY_URL=https://gateway.watsonplatform.net/discovery/api

.releaserc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"branch": "release",
3+
"publish": ["@semantic-release/github"]
4+
}

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: node_js
22
dist: trusty
33
sudo: required
4-
node_js: 6
4+
node_js: 8
55
before_install:
66
- openssl aes-256-cbc -K $encrypted_aba75b5b520c_key -iv $encrypted_aba75b5b520c_iv
77
-in .env.enc -out .env -d
@@ -10,3 +10,9 @@ script:
1010
cache:
1111
directories:
1212
- node_modules
13+
deploy:
14+
- provider: script
15+
skip_cleanup: true
16+
script: npx semantic-release
17+
on:
18+
node: 8

README.md

Lines changed: 71 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,101 @@
1-
# Discovery Demo [![Build Status](https://travis-ci.org/watson-developer-cloud/discovery-nodejs.svg?branch=master)](https://travis-ci.org/watson-developer-cloud/discovery-nodejs)
2-
3-
4-
Use the IBM Watson [Discovery][service_url] service to add a cognitive search and content analytics engine to your applications to identify patterns, trends and actionable insights that drive better decision-making.
5-
6-
![Demo](readme-images/new-demo.gif)
1+
<h1 align="center" style="border-bottom: none;">🔎 Discovery Demo </h1>
2+
<h3 align="center">Use the IBM Watson Discovery service to add a cognitive search and content analytics engine to your applications to identify patterns, trends and actionable insights that drive better decision-making.</h3>
3+
<p align="center">
4+
<a href="http://travis-ci.org/watson-developer-cloud/discovery-nodejs">
5+
<img alt="Travis" src="https://travis-ci.org/watson-developer-cloud/discovery-nodejs.svg?branch=master">
6+
</a>
7+
<a href="#badge">
8+
<img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
9+
</a>
10+
</p>
11+
</p>
12+
13+
![demo](readme-images/new-demo.gif)
714

815
Demo: https://discovery-news-demo.ng.bluemix.net/
916

10-
## Getting started
17+
## Prerequisites
1118

12-
To deploy this repository as-is, click the "Deploy to IBM Cloud" button
19+
1. Sign up for an [IBM Cloud account](https://console.bluemix.net/registration/).
20+
1. Download the [IBM Cloud CLI](https://console.bluemix.net/docs/cli/index.html#overview).
21+
1. Create an instance of the Discovery service and get your credentials:
22+
- Go to the [Discovery](https://console.bluemix.net/catalog/services/discovery) page in the IBM Cloud Catalog.
23+
- Log in to your IBM Cloud account.
24+
- Click **Create**.
25+
- Click **Show** to view the service credentials.
26+
- Copy the `apikey` value, or copy the `username` and `password` values if your service instance doesn't provide an `apikey`.
27+
- Copy the `url` value.
1328

14-
[![Deploy to IBM Cloud][deploy_button_url]][deploy_url]
29+
## Configuring the application
1530

16-
When this button is clicked, it will begin the process of creating a deployment toolchain based on the master branch of the repo into Bluemix and you will have to modify the application name to the name of the host you want to put it at. The default will get mapped to {organization/user}-{repo_name}-{timestamp}.
31+
1. In the application folder, copy the *.env.example* file and create a file called *.env*
1732

18-
After creating the toolchain, you must either run the deployment script as part of the [Continuous Delivery](https://www.ibm.com/devops/method/content/deliver/practice_continuous_delivery/) which will create the service for you, or refer to the [Setup a IBM Watson Discovery Service](#setup-a-ibm-watson-discovery-service) section below to create it manually.
33+
```
34+
cp .env.example .env
35+
```
1936
20-
For more details about developing applications that use Watson Developer Cloud services in Bluemix, see [Getting started with Watson Developer Cloud and Bluemix][getting_started].
37+
2. Open the *.env* file and add the service credentials that you obtained in the previous step.
2138
22-
## Development
39+
Example *.env* file that configures the `apikey` and `url` for a Discovery service instance hosted in the US East region:
2340
24-
### Setup a IBM Watson Discovery Service
41+
```
42+
DISCOVERY_IAM_APIKEY=X4rbi8vwZmKpXfowaS3GAsA7vdy17Qh7km5D6EzKLHL2
43+
DISCOVERY_URL=https://gateway-wdc.watsonplatform.net/discovery/api
44+
```
2545
26-
1. You need a Bluemix account. If you don't have one, [sign up][sign_up].
46+
- If your service instance uses `username` and `password` credentials, add the `DISCOVERY_USERNAME` and `DISCOVERY_PASSWORD` variables to the *.env* file.
2747
28-
1. Download and install the [Cloud-foundry CLI][cloud_foundry] tool if you haven't already.
48+
Example *.env* file that configures the `username`, `password`, and `url` for a Discovery service instance hosted in the Sydney region:
2949
30-
1. Connect to Bluemix with the command line tool.
50+
```
51+
DISCOVERY_USERNAME=522be-7b41-ab44-dec3-g1eab2ha73c6
52+
DISCOVERY_PASSWORD=A4Z5BdGENrwu8
53+
DISCOVERY_URL=https://gateway-syd.watsonplatform.net/discovery/api
54+
```
3155
32-
```sh
33-
cf api https://api.ng.bluemix.net
34-
cf login
35-
```
56+
<!-- **ADD ANY APP-SPECIFIC CONFIGURATION INSTRUCTIONS HERE** -->
3657
37-
1. Create and retrieve service keys to access the [Discovery][service_url] service:
58+
## Running locally
3859
39-
```none
40-
cf create-service discovery standard Discovery-Demo
41-
cf create-service-key Discovery-Demo myKey
42-
cf service-key Discovery-Demo myKey
43-
```
60+
1. Install the dependencies
4461
45-
1. Create an `.env` file in the root directory by copying the sample `.env.example` file using the following command:
62+
```
63+
npm install
64+
```
4665
47-
```none
48-
cp .env.example .env
49-
```
50-
Update the `.env` with your service instance information from step 4
66+
1. Run the application
5167
52-
The `.env` file will look something like the following:
68+
```
69+
npm start
70+
```
5371
54-
```none
55-
DISCOVERY_USERNAME=<username>
56-
DISCOVERY_PASSWORD=<password>
57-
```
72+
1. View the application in a browser at `localhost:3000`
5873
59-
### Run the demo locally
74+
## Deploying to IBM Cloud as a Cloud Foundry Application
6075
61-
1. Install the needed application dependencies with this command:
76+
1. Login to IBM Cloud with the [IBM Cloud CLI](https://console.bluemix.net/docs/cli/index.html#overview)
6277
63-
```none
64-
npm install
65-
```
78+
```
79+
ibmcloud login
80+
```
6681
67-
1. Start the application locally:
82+
1. Target a Cloud Foundry organization and space.
6883
69-
```none
70-
npm start
71-
```
84+
```
85+
ibmcloud target --cf
86+
```
7287
88+
1. Edit the *manifest.yml* file. Change the **name** field to something unique. For example, `- name: my-app-name`.
89+
1. Deploy the application
7390
74-
1. Point your browser to [http://localhost:3000](http://localhost:3000).
91+
```
92+
ibmcloud app push
93+
```
7594
76-
You may build the optimized production build by running `npm run build`. Then you only require to run the `node server.js` to see your code hosted at [http://localhost:5000](http://localhost:5000)
95+
1. View the application online at the app URL, for example: https://my-app-name.mybluemix.net
7796
78-
### Run tests
97+
98+
## Tests
7999
80100
#### Unit tests
81101
Run unit tests with `npm run test-unit`, then `a` to run all tests. See the output for more info.
@@ -85,19 +105,7 @@ First you have to make sure your code is built: `npm run build`
85105
86106
Then run integration tests with: `npm run test-integration-runner`
87107
88-
## Troubleshooting
89-
90-
* The main source of troubleshooting and recovery information is the Bluemix log. To view the log, run this command:
91-
92-
```sh
93-
cf logs <your application name> --recent
94-
```
95-
96-
* For more details about the service, see the [documentation][docs] for the Discovery service.
97-
98-
----
99-
100-
### Directory structure
108+
## Directory structure
101109
102110
```none
103111
.
@@ -126,7 +134,7 @@ Then run integration tests with: `npm run test-integration-runner`
126134
## Open Source @ IBM
127135
Find more open source projects on the [IBM Github Page](http://ibm.github.io/)
128136

129-
# Privacy Notice
137+
## Privacy Notice
130138

131139
Sample web applications that include this package may be configured to track deployments to [IBM Cloud](https://www.bluemix.net/) and other Cloud Foundry platforms. The following information is sent to a [Deployment Tracker](https://github.com/IBM/metrics-collector-service) service on each deployment:
132140

@@ -150,9 +158,7 @@ If you want to disable deployment tracking, follow these steps:
150158
- Set the environment variable `DEMO_DEPLOY` to `1` OR
151159
- remove the `tracker.track();` line in the `./server.js` file
152160

153-
[cloud_foundry]: https://github.com/cloudfoundry/cli
154161
[getting_started]: https://www.ibm.com/watson/developercloud/doc/common/index.html
155-
[service_url]: http://www.ibm.com/watson/developercloud/discovery.html
156162
[docs]: http://www.ibm.com/watson/developercloud/doc/discovery/index.html
157163
[sign_up]: https://console.ng.bluemix.net/registration/
158164
[deploy_button_url]: https://metrics-tracker.mybluemix.net/stats/77edd7e5d6ad4cedf9bc7afaddc29f05/button.svg

app.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@ const NEWS_COLLECTION_ID = 'news';
55

66
const DiscoveryV1 = require('watson-developer-cloud/discovery/v1');
77

8-
const discovery = new DiscoveryV1({
9-
// If unspecified here, the DISCOVERY_USERNAME and
10-
// DISCOVERY_PASSWORD env properties will be checked
11-
// After that, the SDK will fall back to the bluemix-provided VCAP_SERVICES environment property
12-
// username: '<username>',
13-
// password: '<password>',
14-
version_date: '2017-08-01',
15-
});
8+
let discovery;
9+
10+
if (process.env.DISCOVERY_IAM_APIKEY && process.env.DISCOVERY_IAM_APIKEY !== '') {
11+
discovery = new DiscoveryV1({
12+
version: '2017-08-01',
13+
iam_apikey: process.env.DISCOVERY_IAM_APIKEY || '<iam_apikey>',
14+
iam_url: 'https://iam.bluemix.net/identity/token',
15+
url: process.env.DISCOVERY_URL || 'https://gateway.watsonplatform.net/discovery/api',
16+
});
17+
} else {
18+
discovery = new DiscoveryV1({
19+
version: '2017-08-01',
20+
username: process.env.DISCOVERY_USERNAME || '<username>',
21+
password: process.env.DISCOVERY_PASSWORD || '<password>',
22+
url: process.env.DISCOVERY_URL || 'https://gateway.watsonplatform.net/discovery/api',
23+
});
24+
}
1625

1726
// Bootstrap application settings
1827
const express = require('express');

casper-runner.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ require('dotenv').config();
22
const app = require('./app');
33
const spawn = require('child_process').spawn;
44

5-
if (!process.env.DISCOVERY_USERNAME) {
5+
if (!process.env.DISCOVERY_USERNAME && !process.env.DISCOVERY_IAM_APIKEY) {
66
// eslint-disable-next-line no-console
7-
console.log('Skipping integration tests because DISCOVERY_USERNAME is null');
7+
console.log('Skipping integration tests because DISCOVERY_USERNAME and DISCOVERY_IAM_APIKEY are null');
88
} else {
99
const port = 3000;
1010
const server = app.listen(port, () => {

0 commit comments

Comments
 (0)