Skip to content

Commit

Permalink
feat(api,worker,contrib): add example of plugin in nodejs
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Coenen <benjamin.coenen@corp.ovh.com>
  • Loading branch information
bnjjj authored Oct 5, 2018
1 parent e7a896d commit 3582d06
Show file tree
Hide file tree
Showing 17 changed files with 1,802 additions and 21 deletions.
2 changes: 1 addition & 1 deletion contrib/grpcplugins/action/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GITHASH := $(if ${GIT_HASH},${GIT_HASH},`git log -1 --format="%H"`)
BUILDTIME := `date "+%m/%d/%y-%H:%M:%S"`

TARGET_DIR = dist
TARGET_NAME = $(filter-out $@,$(MAKECMDGOALS))
TARGET_NAME = $(filter-out $@ examples,$(MAKECMDGOALS))

define PLUGIN_MANIFEST_BINARY
os: %os%
Expand Down
2 changes: 2 additions & 0 deletions contrib/grpcplugins/action/examples/nodejs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
46 changes: 46 additions & 0 deletions contrib/grpcplugins/action/examples/nodejs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.PHONY: clean

VERSION := $(if ${CDS_SEMVER},${CDS_SEMVER},snapshot)

TARGET_DIR = dist
TARGET_NAME = nodejs

define PLUGIN_MANIFEST_BINARY
os: %os%
arch: %arch%
cmd: node
entrypoints:
- index.js
requirements:
- name: node
type: binary
value: node
endef
export PLUGIN_MANIFEST_BINARY

TARGET_OS = $(if ${OS},${OS},windows darwin linux freebsd)
TARGET_ARCH = $(if ${ARCH},${ARCH},amd64 arm 386)
TARGET_TAR = plugin-$(TARGET_NAME).tar.gz

build:
@mkdir -p $(TARGET_DIR)
@cp $(TARGET_NAME).yml $(TARGET_DIR)/plugin.yml
@npm install
@tar -czvf $(TARGET_DIR)/$(TARGET_TAR) node_modules *.js *.json
@for OS in $(TARGET_OS); do \
for ARCH in $(TARGET_ARCH); do \
echo "$$PLUGIN_MANIFEST_BINARY" > $(TARGET_DIR)/plugin-$$OS-$$ARCH.yml; \
perl -pi -e s,%os%,$$OS,g $(TARGET_DIR)/plugin-$$OS-$$ARCH.yml; \
perl -pi -e s,%arch%,$$ARCH,g $(TARGET_DIR)/plugin-$$OS-$$ARCH.yml; \
done; \
done;

publish:
@echo "Updating plugin $(TARGET_NAME)..."
cdsctl admin plugins import $(TARGET_DIR)/plugin.yml
@for OS in $(TARGET_OS); do \
for ARCH in $(TARGET_ARCH); do \
echo "Updating plugin binary $(TARGET_NAME)-$$OS-$$ARCH"; \
cdsctl admin plugins binary-add plugin-$(TARGET_NAME) $(TARGET_DIR)/plugin-$$OS-$$ARCH.yml $(TARGET_DIR)/$(TARGET_TAR); \
done; \
done
100 changes: 100 additions & 0 deletions contrib/grpcplugins/action/examples/nodejs/actionplugin_grpc_pb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// GENERATED CODE -- DO NOT EDIT!

'use strict';
var grpc = require('grpc');
var actionplugin_pb = require('./actionplugin_pb.js');
var google_protobuf_empty_pb = require('google-protobuf/google/protobuf/empty_pb.js');

function serialize_actionplugin_ActionPluginManifest(arg) {
if (!(arg instanceof actionplugin_pb.ActionPluginManifest)) {
throw new Error('Expected argument of type actionplugin.ActionPluginManifest');
}
return new Buffer(arg.serializeBinary());
}

function deserialize_actionplugin_ActionPluginManifest(buffer_arg) {
return actionplugin_pb.ActionPluginManifest.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_actionplugin_ActionQuery(arg) {
if (!(arg instanceof actionplugin_pb.ActionQuery)) {
throw new Error('Expected argument of type actionplugin.ActionQuery');
}
return new Buffer(arg.serializeBinary());
}

function deserialize_actionplugin_ActionQuery(buffer_arg) {
return actionplugin_pb.ActionQuery.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_actionplugin_ActionResult(arg) {
if (!(arg instanceof actionplugin_pb.ActionResult)) {
throw new Error('Expected argument of type actionplugin.ActionResult');
}
return new Buffer(arg.serializeBinary());
}

function deserialize_actionplugin_ActionResult(buffer_arg) {
return actionplugin_pb.ActionResult.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_actionplugin_WorkerHTTPPortQuery(arg) {
if (!(arg instanceof actionplugin_pb.WorkerHTTPPortQuery)) {
throw new Error('Expected argument of type actionplugin.WorkerHTTPPortQuery');
}
return new Buffer(arg.serializeBinary());
}

function deserialize_actionplugin_WorkerHTTPPortQuery(buffer_arg) {
return actionplugin_pb.WorkerHTTPPortQuery.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_google_protobuf_Empty(arg) {
if (!(arg instanceof google_protobuf_empty_pb.Empty)) {
throw new Error('Expected argument of type google.protobuf.Empty');
}
return new Buffer(arg.serializeBinary());
}

function deserialize_google_protobuf_Empty(buffer_arg) {
return google_protobuf_empty_pb.Empty.deserializeBinary(new Uint8Array(buffer_arg));
}


var ActionPluginService = exports.ActionPluginService = {
manifest: {
path: '/actionplugin.ActionPlugin/Manifest',
requestStream: false,
responseStream: false,
requestType: google_protobuf_empty_pb.Empty,
responseType: actionplugin_pb.ActionPluginManifest,
requestSerialize: serialize_google_protobuf_Empty,
requestDeserialize: deserialize_google_protobuf_Empty,
responseSerialize: serialize_actionplugin_ActionPluginManifest,
responseDeserialize: deserialize_actionplugin_ActionPluginManifest,
},
run: {
path: '/actionplugin.ActionPlugin/Run',
requestStream: false,
responseStream: false,
requestType: actionplugin_pb.ActionQuery,
responseType: actionplugin_pb.ActionResult,
requestSerialize: serialize_actionplugin_ActionQuery,
requestDeserialize: deserialize_actionplugin_ActionQuery,
responseSerialize: serialize_actionplugin_ActionResult,
responseDeserialize: deserialize_actionplugin_ActionResult,
},
workerHTTPPort: {
path: '/actionplugin.ActionPlugin/WorkerHTTPPort',
requestStream: false,
responseStream: false,
requestType: actionplugin_pb.WorkerHTTPPortQuery,
responseType: google_protobuf_empty_pb.Empty,
requestSerialize: serialize_actionplugin_WorkerHTTPPortQuery,
requestDeserialize: deserialize_actionplugin_WorkerHTTPPortQuery,
responseSerialize: serialize_google_protobuf_Empty,
responseDeserialize: deserialize_google_protobuf_Empty,
},
};

exports.ActionPluginClient = grpc.makeGenericClientConstructor(ActionPluginService);
Loading

0 comments on commit 3582d06

Please sign in to comment.