Skip to content

Local development support #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 3 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,9 @@ Run `npm run sync:es` from the root of project to execute the script.

**NOTE**: In production these dependencies / services are hosted & managed outside tc-projects-service.

#### Kafka
Kafka must be installed and configured prior starting the application.
Following topics must be created:
```
notifications.connect.project.updated
notifications.connect.project.files.updated
notifications.connect.project.team.updated
notifications.connect.project.plan.updated
notifications.connect.project.topic.created
notifications.connect.project.topic.updated
notifications.connect.project.post.created
notifications.connect.project.post.edited
```
### Import sample metadata

New Kafka related configuration options has been introduced:
```
"kafkaConfig": {
"hosts": List of Kafka brokers. Default: localhost: 9092
"clientCert": SSL certificate
"clientCertKey": Certificate key
}
```
Environment variables:
- `KAFKA_HOSTS` - same as "hosts"
- `KAFKA_CLIENT_CERT` - same as "clientCert"
- `KAFKA_CLIENT_CERT_KEY` - same as "clientCertKey"
To create sample metadata entries (duplicate what is currently in development environment) run `node migrations/seedMetadata.js`

### Test

Expand Down Expand Up @@ -103,4 +80,4 @@ You may replace 172.17.0.1 with your docker0 IP.
You can paste **swagger.yaml** to [swagger editor](http://editor.swagger.io/) or import **postman.json** and **postman_environment.json** to verify endpoints.

#### Deploying without docker
If you don't want to use docker to deploy to localhost. You can simply run `npm run start` from root of project. This should start the server on default port `3000`.
If you don't want to use docker to deploy to localhost. You can simply run `npm run start:dev` from root of project. This should start the server on default port `8001`.
72 changes: 72 additions & 0 deletions migrations/seedMetadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* eslint-disable */
const _ = require('lodash')
const axios = require('axios');
const Promise = require('bluebird');


var url = 'https://api.topcoder-dev.com/v4/projects/metadata';
var targetUrl = 'http://localhost:8001/v4/';
var destUrl = targetUrl + 'projects/';
var destTimelines = targetUrl;

axios.get(url)
.then(async function (response) {
let data = response.data;

var headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiYWRtaW5pc3RyYXRvciJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci1kZXYuY29tIiwiaGFuZGxlIjoidGVzdDEiLCJleHAiOjI1NjMwNzY2ODksInVzZXJJZCI6IjQwMDUxMzMzIiwiaWF0IjoxNDYzMDc2MDg5LCJlbWFpbCI6InRlc3RAdG9wY29kZXIuY29tIiwianRpIjoiYjMzYjc3Y2QtYjUyZS00MGZlLTgzN2UtYmViOGUwYWU2YTRhIn0.wKWUe0-SaiFVN-VR_-GwgFlvWaDkSbc8H55ktb9LAVw'
}


let promises = _(data.result.content.projectTypes).map(pt=>{
return axios.post(destUrl+'metadata/projectTypes',{param:pt}, {headers:headers})
});
try{
await Promise.all(promises);
}catch(ex){
//ignore the error
}

promises = _(data.result.content.projectTemplates).map(pt=>{
return axios.post(destUrl+'metadata/projectTemplates',{param:pt}, {headers:headers})
});
try{
await Promise.all(promises);
}catch(ex){
//ignore the error
}

promises = _(data.result.content.productCategories).map(pt=>{
return axios.post(destUrl+'metadata/productCategories',{param:pt}, {headers:headers})
});
try{
await Promise.all(promises);
}catch(ex){
//ignore the error
}

promises = _(data.result.content.productTemplates).map(pt=>{
return axios.post(destUrl+'metadata/productTemplates',{param:pt}, {headers:headers})
});
try{
await Promise.all(promises);
}catch(ex){
//ignore the error
}

await Promise.each(data.result.content.milestoneTemplates,pt=>{
return new Promise((resolve,reject)=>{
axios.post(destTimelines+'timelines/metadata/milestoneTemplates',{param:pt}, {headers:headers})
.then(r=>resolve())
.catch(e=>resolve()); //ignore the error
})
});



// handle success
console.log('Done');
}).catch(err=>{
console.log(err);
});