Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Commit

Permalink
New: publish package to npm with run option (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
alewitt2 authored Dec 14, 2020
1 parent 26cc9ac commit a44187b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ WORKDIR /home/node

COPY --chown=node --from=buildImg /home/node /home/node

CMD ["npm", "start"]
CMD ["./bin/remoteresources3"]
3 changes: 3 additions & 0 deletions bin/remoteresources3
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('..').run();
21 changes: 0 additions & 21 deletions main.js

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "@razee/remoteresources3",
"version": "0.0.0-dev",
"description": "Razeedeploy: component to download and manage files from s3 object storage",
"main": "main.js",
"main": "./src/index.js",
"bin": "./bin/remoteresources3",
"keywords": [
"kubernetes",
"razee",
Expand Down
46 changes: 39 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const { EventHandler, KubeClass, KubeApiConfig } = require('@razee/kubernetes-ut
const kubeApiConfig = KubeApiConfig();

const ControllerString = 'RemoteResourceS3';
const Controller = require(`./${ControllerString}Controller`);
const log = require('./bunyan-api').createLogger(ControllerString);

const apiGroup = process.env.GROUP || 'deploy.razee.io';
Expand All @@ -28,7 +29,6 @@ async function createNewEventHandler(kc) {
let result;
let resourceMeta = await kc.getKubeResourceMeta(`${apiGroup}/${apiVersion}`, ControllerString, 'watch');
if (resourceMeta) {
const Controller = require(`./${ControllerString}Controller`);
let params = {
kubeResourceMeta: resourceMeta,
factory: Controller,
Expand All @@ -45,11 +45,43 @@ async function createNewEventHandler(kc) {
}

async function main() {
log.info(`Running ${ControllerString}Controller.`);
const kc = new KubeClass(kubeApiConfig);
const eventHandlers = [];
eventHandlers.push(createNewEventHandler(kc));
return eventHandlers;
let kc;
try {
log.info(`Running ${ControllerString}Controller.`);
kc = new KubeClass(kubeApiConfig);
} catch (e) {
log.error(e, 'Failed to get KubeClass.');
}
try {
await createNewEventHandler(kc);
} catch (e) {
log.error(e, 'Error creating new event handler.');
}
}

function createEventListeners() {
process.on('SIGTERM', () => {
log.info('recieved SIGTERM. not handling at this time.');
});
process.on('unhandledRejection', (reason) => {
log.error('recieved unhandledRejection', reason);
});
process.on('beforeExit', (code) => {
log.info(`No work found. exiting with code: ${code}`);
});

}

async function run() {
try {
createEventListeners();
await main();
} catch (error) {
log.error(error);
}
}

main().catch(e => log.error(e));
module.exports = {
run,
RemoteResourceS3Controller: Controller
};

0 comments on commit a44187b

Please sign in to comment.