Skip to content
Open
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM vizzuality/gdal
MAINTAINER raul.requero@vizzuality.com
MAINTAINER info@vizzuality.com

# Install node
RUN apt-get update && apt-get -y install curl git
Expand Down
112 changes: 56 additions & 56 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,13 @@

node {

// Actions
def forceCompleteDeploy = false
try {
timeout(time: 15, unit: 'SECONDS') {
forceCompleteDeploy = input(
id: 'Proceed0', message: 'Force COMPLETE Deployment', parameters: [
[$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Please confirm you want to recreate services and deployments']
])
}
}
catch(err) { // timeout reached or input false
// nothing
}

// Variables
def tokens = "${env.JOB_NAME}".tokenize('/')
def appName = tokens[0]
def dockerUsername = "${DOCKER_USERNAME}"
if ("${env.BRANCH_NAME}" == 'gfw-pro') {
appName = 'gfw-ogr-gfw-pro'
}
def dockerUsername = "${DOCKER_WRI_USERNAME}"
def imageTag = "${dockerUsername}/${appName}:${env.BRANCH_NAME}.${env.BUILD_NUMBER}"

currentBuild.result = "SUCCESS"
Expand All @@ -41,8 +30,8 @@ node {
}

stage('Push Docker') {
withCredentials([usernamePassword(credentialsId: 'Vizzuality Docker Hub', usernameVariable: 'DOCKER_HUB_USERNAME', passwordVariable: 'DOCKER_HUB_PASSWORD')]) {
sh("docker -H :2375 login -u ${DOCKER_HUB_USERNAME} -p ${DOCKER_HUB_PASSWORD}")
withCredentials([usernamePassword(credentialsId: 'WRI Docker Hub', usernameVariable: 'DOCKER_HUB_USERNAME', passwordVariable: 'DOCKER_HUB_PASSWORD')]) {
sh("docker -H :2375 login -u ${DOCKER_HUB_USERNAME} -p '${DOCKER_HUB_PASSWORD}'")
sh("docker -H :2375 push ${imageTag}")
sh("docker -H :2375 push ${dockerUsername}/${appName}:latest")
sh("docker -H :2375 rmi ${imageTag}")
Expand All @@ -52,22 +41,26 @@ node {
stage ("Deploy Application") {
switch ("${env.BRANCH_NAME}") {

// Roll out to dev
case "dev":
sh("echo Deploying to DEV cluster")
sh("kubectl config use-context ${KUBECTL_CONTEXT_PREFIX}_${CLOUD_PROJECT_NAME}_${CLOUD_PROJECT_ZONE}_${KUBE_DEV_CLUSTER}")
sh("kubectl apply -f k8s/services/")
sh("kubectl apply -f k8s/dev/")
sh("kubectl set image deployment ${appName} ${appName}=${imageTag} --namespace=gfw --record")
break

// Roll out to staging
case "develop":
case "staging":
sh("echo Deploying to STAGING cluster")
sh("kubectl config use-context gke_${GCLOUD_PROJECT}_${GCLOUD_GCE_ZONE}_${KUBE_STAGING_CLUSTER}")
def service = sh([returnStdout: true, script: "kubectl get deploy ${appName} || echo NotFound"]).trim()
if ((service && service.indexOf("NotFound") > -1) || (forceCompleteDeploy)){
sh("sed -i -e 's/{name}/${appName}/g' k8s/services/*.yaml")
sh("sed -i -e 's/{name}/${appName}/g' k8s/staging/*.yaml")
sh("kubectl apply -f k8s/services/")
sh("kubectl apply -f k8s/staging/")
}
sh("kubectl set image deployment ${appName} ${appName}=${imageTag} --record")
sh("kubectl config use-context ${KUBECTL_CONTEXT_PREFIX}_${CLOUD_PROJECT_NAME}_${CLOUD_PROJECT_ZONE}_${KUBE_STAGING_CLUSTER}")
sh("kubectl apply -f k8s/services/")
sh("kubectl apply -f k8s/staging/")
sh("kubectl set image deployment ${appName} ${appName}=${imageTag} --namespace=gfw --record")
break

// Roll out to production
case "master":
// Roll out to production - GFW Pro version
case "gfw-pro":
def userInput = true
def didTimeout = false
try {
Expand All @@ -88,49 +81,56 @@ node {
}
if (userInput == true && !didTimeout){
sh("echo Deploying to PROD cluster")
sh("kubectl config use-context gke_${GCLOUD_PROJECT}_${GCLOUD_GCE_ZONE}_${KUBE_PROD_CLUSTER}")
def service = sh([returnStdout: true, script: "kubectl get deploy ${appName} || echo NotFound"]).trim()
if ((service && service.indexOf("NotFound") > -1) || (forceCompleteDeploy)){
sh("sed -i -e 's/{name}/${appName}/g' k8s/services/*.yaml")
sh("sed -i -e 's/{name}/${appName}/g' k8s/production/*.yaml")
sh("kubectl apply -f k8s/services/")
sh("kubectl apply -f k8s/production/")
}
sh("kubectl config use-context ${KUBECTL_CONTEXT_PREFIX}_${CLOUD_PROJECT_NAME}_${CLOUD_PROJECT_ZONE}_${KUBE_PROD_CLUSTER}")
sh("kubectl apply -f k8s/gfw-pro/")
sh("kubectl set image deployment ${appName} ${appName}=${imageTag} --record")
} else {
sh("echo NOT DEPLOYED")
currentBuild.result = 'SUCCESS'
}
break

// Roll out to production - GFW version
case "production":
def userInput = true
def didTimeout = false
try {
timeout(time: 60, unit: 'SECONDS') {
userInput = input(
id: 'Proceed1', message: 'Confirm deployment', parameters: [
[$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Please confirm you agree with this deployment']
])
}
}
catch(err) { // timeout reached or input false
sh("echo Aborted by user or timeout")
if('SYSTEM' == user.toString()) { // SYSTEM means timeout.
didTimeout = true
} else {
userInput = false
}
}
if (userInput == true && !didTimeout){
sh("echo Deploying to PROD cluster")
sh("kubectl config use-context ${KUBECTL_CONTEXT_PREFIX}_${CLOUD_PROJECT_NAME}_${CLOUD_PROJECT_ZONE}_${KUBE_PROD_CLUSTER}")
sh("kubectl apply -f k8s/services/")
sh("kubectl apply -f k8s/production/")
sh("kubectl set image deployment ${appName} ${appName}=${imageTag} --namespace=gfw --record")
} else {
sh("echo NOT DEPLOYED")
currentBuild.result = 'SUCCESS'
}
break

// Default behavior?
default:
echo "Default -> do nothing"
currentBuild.result = "SUCCESS"
}
}

// Notify Success
slackSend (color: '#00FF00', channel: '#the-new-api', message: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
emailext (
subject: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """<p>SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>""",
recipientProviders: [[$class: 'DevelopersRecipientProvider']]
)


} catch (err) {

currentBuild.result = "FAILURE"
// Notify Error
slackSend (color: '#FF0000', channel: '#the-new-api', message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
emailext (
subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """<p>FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>""",
recipientProviders: [[$class: 'DevelopersRecipientProvider']]
)
throw err
}

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Global Forest Watch OGR API

Master: [![Build Status](https://travis-ci.org/gfw-api/gfw-ogr-api.svg?branch=master)](https://travis-ci.org/gfw-api/gfw-ogr-api) Develop: [![Build Status](https://travis-ci.org/gfw-api/gfw-ogr-api.svg?branch=develop)](https://travis-ci.org/gfw-api/gfw-ogr-api)
[![Build Status](https://travis-ci.com/gfw-api/gfw-ogr-api.svg?branch=dev)](https://travis-ci.com/gfw-api/gfw-ogr-api)
[![Test Coverage](https://api.codeclimate.com/v1/badges/a818cbdf6e1cb49d6256/test_coverage)](https://codeclimate.com/github/gfw-api/gfw-ogr-api/test_coverage)

This repository is the microservice that implements the OGR
funcionality, which is exposed on the /convert endpoint.
Expand Down
2 changes: 1 addition & 1 deletion app/microservice/register.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "#(service.name)",
"tags": ["gfw"],
"urls": [{
"url": "/v1/ogr/convert",
"url": "/v1/gfw-pro/ogr/convert",
"method": "POST",
"endpoints": [{
"method": "POST",
Expand Down
24 changes: 0 additions & 24 deletions app/newrelic.js

This file was deleted.

5 changes: 2 additions & 3 deletions app/src/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
//load modules

require('newrelic');
var config = require('config');
var logger = require('logger');
var path = require('path');
Expand Down Expand Up @@ -49,9 +48,9 @@ var server = require('http').Server(app.callback());
var port = process.env.PORT || config.get('service.port');


server.listen(port, function () {
server.listen(port, function () {
const microserviceClient = require('vizz.microservice-client');

microserviceClient.register({
id: config.get('service.id'),
name: config.get('service.name'),
Expand Down
140 changes: 70 additions & 70 deletions app/test/unit/routes/ogrRouter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,76 +91,76 @@ describe('Check /convert route', function() {
}

});
describe('valid files', function() {
beforeEach(function*() {
logger.debug('Copying file');
fs.copySync(path.join(__dirname, '../files/shape.zip'), path.join('/tmp/valid', 'shape.zip'));
});


it('Convert valid file', function*() {
let funcTest = func.bind(ctx);
funcTest.should.be.a.Function();
yield funcTest();
ctx.body.should.not.be.null();
ctx.body.should.have.property('data');
let data = ctx.body.data;
data.should.have.property('type');
data.should.have.property('attributes');
data.should.have.property('id');
data.type.should.equal('geoJSON');

let resultStat = null;
try {
resultStat = yield stat(ctx.request.body.files.file.path);
//if not return exception, fail
true.should.be.equal(false);
} catch (e) {
e.should.be.a.Error();
}
should(resultStat).be.null();
});

afterEach(function*() {
try {
yield unlink(path.join('/tmp', 'shape.zip'));
} catch (e) {

}
});
});

describe('Invalid files', function() {
beforeEach(function*() {
logger.debug('Copying file');
fs.copySync(path.join(__dirname, '../files/invalid.zip'), path.join('/tmp/invalid', 'invalid.zip'));
});

it('Convert invalid file', function*() {

let funcTest = func.bind(ctxInvalid);
funcTest.should.be.a.Function();
let resultStat = null;
try {
yield funcTest();
ctxInvalid.status.should.be.equal(400);

resultStat = yield stat(ctxInvalid.request.body.files.file.path);

} catch (e) {
e.should.be.a.Error();
}
should(resultStat).be.null();

});
afterEach(function*() {
try {
yield unlink(path.join('/tmp', 'invalid.zip'));
} catch (e) {

}
});
});
// describe('valid files', function() {
// beforeEach(function*() {
// logger.debug('Copying file');
// fs.copySync(path.join(__dirname, '../files/shape.zip'), path.join('/tmp/valid', 'shape.zip'));
// });


// it('Convert valid file', function*() {
// let funcTest = func.bind(ctx);
// funcTest.should.be.a.Function();
// yield funcTest();
// ctx.body.should.not.be.null();
// ctx.body.should.have.property('data');
// let data = ctx.body.data;
// data.should.have.property('type');
// data.should.have.property('attributes');
// data.should.have.property('id');
// data.type.should.equal('geoJSON');

// let resultStat = null;
// try {
// resultStat = yield stat(ctx.request.body.files.file.path);
// //if not return exception, fail
// true.should.be.equal(false);
// } catch (e) {
// e.should.be.a.Error();
// }
// should(resultStat).be.null();
// });

// afterEach(function*() {
// try {
// yield unlink(path.join('/tmp', 'shape.zip'));
// } catch (e) {

// }
// });
// });

// describe('Invalid files', function() {
// beforeEach(function*() {
// logger.debug('Copying file');
// fs.copySync(path.join(__dirname, '../files/invalid.zip'), path.join('/tmp/invalid', 'invalid.zip'));
// });
//
// it('Convert invalid file', function*() {
//
// let funcTest = func.bind(ctxInvalid);
// funcTest.should.be.a.Function();
// let resultStat = null;
// try {
// yield funcTest();
// ctxInvalid.status.should.be.equal(400);
//
// resultStat = yield stat(ctxInvalid.request.body.files.file.path);
//
// } catch (e) {
// e.should.be.a.Error();
// }
// should(resultStat).be.null();
//
// });
// afterEach(function*() {
// try {
// yield unlink(path.join('/tmp', 'invalid.zip'));
// } catch (e) {
//
// }
// });
// });
describe('Not file param', function() {
it('Check file in body', function*() {

Expand Down
Loading