Skip to content

Commit

Permalink
New: publish package to npm (#191)
Browse files Browse the repository at this point in the history
* New: publish package to npm

* Update watchkeeper

* Update package-lock.json
  • Loading branch information
alewitt2 authored Oct 21, 2020
1 parent 03a80cd commit b70d4a0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 13 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ script:
- docker images
- ./build/process-template.sh kubernetes/watch-keeper/resource.yaml >/tmp/resource.yaml
- ./build/process-template.sh kubernetes/watch-keeper/rbac.yaml >/tmp/rbac.yaml
- if [[ "${TRAVIS_TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then npm version --no-git-tag-version "${TRAVIS_TAG}"; fi

before_deploy:
- docker login -u="${QUAY_ID}" -p="${QUAY_TOKEN}" quay.io
Expand Down Expand Up @@ -45,3 +46,10 @@ deploy:
on:
tags: true
condition: ${TRAVIS_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+$
- provider: npm
email: "${NPMJS_EMAIL}"
api_key: "${NPMJS_API_KEY}"
skip_cleanup: true
on:
tags: true
condition: ${TRAVIS_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+$
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ USER node
WORKDIR /home/node

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

require('..').run();
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "watch-keeper",
"version": "0.0.1",
"name": "@razee/watchkeeper",
"version": "0.0.0-dev",
"description": "Observe Kubernetes changes",
"main": "src/index.js",
"main": "./src/index.js",
"bin": "./bin/watchkeeper",
"scripts": {
"start": "node src/index.js",
"test": "KUBECONFIG=./testdata/kubeconfig.yaml nyc --all --reporter=html --reporter=text mocha ",
Expand Down
35 changes: 28 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,31 @@ async function init() {
return true;
}

process.on('unhandledRejection', (reason) => {
log.error(reason, 'Unhandled promise rejection.');
});
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}`);
});

promiseRetry({ retries: 5 },
retry => {
return init().catch(retry);
}).catch(err => log.error(`Failed to init watch-keeper | ${err}`));
}

async function run() {
try {
createEventListeners();
await promiseRetry({ retries: 5 },
retry => {
return init().catch(retry);
});
} catch (error) {
log.error('Failed to init watchkeeper', error);
}

}

async function setEnvs() {
const env = process.env;
Expand Down Expand Up @@ -148,3 +165,7 @@ async function setEnvs() {
env.LOG_LEVEL = (await fs.readFile('envs/watch-keeper-config/LOG_LEVEL', 'utf8')).trim();
}
}

module.exports = {
run
};

0 comments on commit b70d4a0

Please sign in to comment.