Skip to content

Commit

Permalink
ci: publish to npm (#201)
Browse files Browse the repository at this point in the history
* ci: publish to npm as package

* ci: publish to npm on rc

* ci: dont tag rc candidates with latest

* ci: allow publish of latest

* fix: cant use relative paths

* chore: path to main

* Update .travis.yml
  • Loading branch information
alewitt2 authored Feb 11, 2021
1 parent b95354d commit c59eae0
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 35 deletions.
25 changes: 19 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,44 @@ script:
- if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then npm audit; else npm audit || true; fi
- npm run lint
- npm test
- if [[ "${TRAVIS_TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]]; then npm version --no-git-tag-version "${TRAVIS_TAG}"; fi
- npm version
- docker build --rm -t "quay.io/razee/razeedeploy-delta:${TRAVIS_COMMIT}" .
- if [ -n "${TRAVIS_TAG}" ]; then docker tag quay.io/razee/razeedeploy-delta:${TRAVIS_COMMIT} quay.io/razee/razeedeploy-delta:${TRAVIS_TAG}; fi
- docker images
- ./build/process-template.sh kubernetes/razeedeploy-delta/resource.yaml >/tmp/resource.yaml
- ./build/process-template.sh kubernetes/job/resource.yaml >/tmp/job.yaml


before_deploy:
- docker login -u="${QUAY_ID}" -p="${QUAY_TOKEN}" quay.io

deploy:
# Deploy alpha builds
- provider: script
script: docker push "quay.io/razee/razeedeploy-delta:${TRAVIS_TAG}"
# Publish npm package with tag "next" on release candidates
- provider: npm
email: "${NPMJS_EMAIL}"
api_key: "${NPMJS_API_KEY}"
tag: next
skip_cleanup: true
on:
tags: true
condition: ${TRAVIS_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+_[0-9]{3}$

# Deploy released builds
condition: ${TRAVIS_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)$
# Publish docker image on release and release candidates
- provider: script
script: docker push "quay.io/razee/razeedeploy-delta:${TRAVIS_TAG}"
skip_cleanup: true
on:
tags: true
condition: ${TRAVIS_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$
# Publish npm package as "latest" on release
- 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]+$
# Publish GitHub release assets on release
- provider: releases
file:
- "/tmp/resource.yaml"
Expand Down
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/razeedeploy-delta"]
12 changes: 12 additions & 0 deletions bin/razeedeploy-delta
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env node

const args = process.argv.slice(2);
if (args[0] === undefined) args[0] = 'index';

if (args[0].toLowerCase() === 'install') {
require('../src/install').run();
} else if (args[0].toLowerCase() === 'remove') {
require('../src/remove').run();
} else {
require('../src').run();
}
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "delta",
"version": "0.0.1",
"name": "@razee/razeedeploy-delta",
"version": "0.0.0-dev",
"description": "A service to keep specified Kubernetes custom resources enforced and updated",
"main": "src/index.js",
"main": "./src/index.js",
"bin": "./bin/razeedeploy-delta",
"scripts": {
"start": "node src/index.js",
"test": "nyc --reporter=html --reporter=text mocha ",
Expand All @@ -25,6 +26,9 @@
"name": "Alex Lewitt"
}
],
"publishConfig": {
"access": "public"
},
"license": "Apache-2.0",
"dependencies": {
"@razee/kubernetes-util": "^0.2.0",
Expand Down
34 changes: 30 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
const { KubeClass, KubeApiConfig } = require('@razee/kubernetes-util');
const kubeApiConfig = KubeApiConfig();
const kc = new KubeClass(kubeApiConfig);
var log = require('./bunyan-api').createLogger('delta');
var log = require(`${__dirname}/bunyan-api`).createLogger('delta');
const objectPath = require('object-path');
const yaml = require('js-yaml');
const fs = require('fs-extra');
Expand All @@ -35,15 +35,15 @@ async function main() {
await touch('/tmp/liveness');
try {
let resourceUris = [];
let files = await fs.readdir('./resource-uris');
let files = await fs.readdir(`${__dirname}/../resource-uris`);
log.debug(`Found in dir ${JSON.stringify(files)}`);
await Promise.all(files.map(async f => {
if (f.startsWith('..')) {
log.debug(`${f} is not a file ... skipping`);
return;
}

let uri = await fs.readFile(`./resource-uris/${f}`, { encoding: 'utf8' });
let uri = await fs.readFile(`${__dirname}/../resource-uris/${f}`, { encoding: 'utf8' });
uri = uri.trim();
if (!validUrl.isUri(`${uri}`)) {
log.error(`uri ${uri} not valid`);
Expand Down Expand Up @@ -216,4 +216,30 @@ function reconcileFields(config, lastApplied, parentPath = []) {
});
}

main().catch(e => log.error(e));
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);
}

}

module.exports = {
run
};
45 changes: 34 additions & 11 deletions src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

const log = require('./bunyan-api').createLogger('razeedeploy-install');
const log = require(`${__dirname}/bunyan-api`).createLogger('razeedeploy-install');
const argv = require('minimist')(process.argv.slice(2));
const validUrl = require('valid-url');

Expand Down Expand Up @@ -163,7 +163,7 @@ async function main() {

try {
log.info('=========== Installing Prerequisites ===========');
let preReqsJson = await readYaml('./src/resources/preReqs.yaml', { desired_namespace: argvNamespace });
let preReqsJson = await readYaml(`${__dirname}/resources/preReqs.yaml`, { desired_namespace: argvNamespace });
await decomposeFile(preReqsJson, 'ensureExists');

let resourceUris = Object.values(resourcesObj);
Expand All @@ -175,7 +175,7 @@ async function main() {
if (installAll || resourcesObj['clustersubscription'].install || resourcesObj['watchkeeper'].install) {
if (!rdApi && !rdUrl) log.warn('Failed to find arg \'--razeedash-api\' or \'--razeedash-url\'.. will create template \'razee-identity\' config.');
if (!rdOrgKey) log.warn('Failed to find arg\'--razeedash-org-key\'.. will create template \'razee-identity\' secret.');
let ridConfigJson = await readYaml('./src/resources/ridConfig.yaml', {
let ridConfigJson = await readYaml(`${__dirname}/resources/ridConfig.yaml`, {
desired_namespace: argvNamespace,
razeedash_api: rdApi.href || rdUrl.origin || 'insert-rd-url-here',
razeedash_cluster_id: rdclusterId ? { id: rdclusterId } : false, // have set to false, {} puts any "" string value
Expand All @@ -188,7 +188,7 @@ async function main() {
if (installAll || resourceUris[i].install) {
log.info(`=========== Installing ${resources[i]}:${resourceUris[i].install || 'Install All Resources'} ===========`);
if (resources[i] === 'watchkeeper') {
let wkConfigJson = await readYaml('./src/resources/wkConfig.yaml', {
let wkConfigJson = await readYaml(`${__dirname}/resources/wkConfig.yaml`, {
desired_namespace: argvNamespace,
razeedash_url: rdUrl.href ? { url: rdUrl.href } : false,
razeedash_cluster_metadata: rdclusterMetadata,
Expand All @@ -211,7 +211,7 @@ async function main() {

if (autoUpdate && (installAll || resourcesObj.remoteresource.install)) { // remoteresource must be installed to use autoUpdate
log.info('=========== Installing Auto-Update RemoteResource ===========');
let autoUpdateJson = await readYaml('./src/resources/autoUpdateRR.yaml', { desired_namespace: argvNamespace });
let autoUpdateJson = await readYaml(`${__dirname}/resources/autoUpdateRR.yaml`, { desired_namespace: argvNamespace });
objectPath.set(autoUpdateJson, '0.spec.requests', autoUpdateArray);
try {
await crdRegistered('deploy.razee.io/v1alpha2', 'RemoteResource');
Expand Down Expand Up @@ -390,9 +390,32 @@ async function ensureExists(krm, file, options = {}) {
return response;
}

main().then(() => {
success === true ? process.exit(0) : process.exit(1);
}).catch(e => {
log.error(e);
process.exit(1);
});
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();
success === true ? process.exit(0) : process.exit(1);
} catch (error) {
log.error(error);
process.exit(1);
}

}

module.exports = {
run
};
43 changes: 33 additions & 10 deletions src/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

const log = require('./bunyan-api').createLogger('razeedeploy-remove');
const log = require(`${__dirname}/bunyan-api`).createLogger('razeedeploy-remove');
const argv = require('minimist')(process.argv.slice(2));
const validUrl = require('valid-url');

Expand Down Expand Up @@ -119,7 +119,7 @@ async function main() {
if (removeAll || resourceUris[i].remove) {
log.info(`=========== Removing ${resources[i]}:${resourceUris[i].remove || 'Remove All Resources'} ===========`);
if (resources[i] === 'watchkeeper') {
let wkConfigJson = await readYaml('./src/resources/wkConfig.yaml', { desired_namespace: argvNamespace });
let wkConfigJson = await readYaml(`${__dirname}/resources/wkConfig.yaml`, { desired_namespace: argvNamespace });
await deleteFile(wkConfigJson);
}
let { file } = await download(resourceUris[i]);
Expand All @@ -145,7 +145,7 @@ async function main() {
}

log.info('=========== Removing Prerequisites ===========');
let preReqsJson = await readYaml('./src/resources/preReqs.yaml', { desired_namespace: argvNamespace });
let preReqsJson = await readYaml(`${__dirname}/resources/preReqs.yaml`, { desired_namespace: argvNamespace });
for (let i = 0; i < preReqsJson.length; i++) {
let preReq = preReqsJson[i];
let kind = objectPath.get(preReq, 'kind');
Expand All @@ -157,7 +157,7 @@ async function main() {
}
if (removeAll || (resourcesObj['clustersubscription'].remove && resourcesObj['watch-keeper'].remove)) {
// if watch-keeper and clustersubscription are removed in seperate runs, ridConfig will be left on the cluster
let ridConfigJson = await readYaml('./src/resources/ridConfig.yaml', { desired_namespace: argvNamespace });
let ridConfigJson = await readYaml(`${__dirname}/resources/ridConfig.yaml`, { desired_namespace: argvNamespace });
await deleteFile(ridConfigJson);
}

Expand Down Expand Up @@ -305,9 +305,32 @@ async function deleteResource(krm, file, options = {}) {
}
}

main().then(() => {
success === true ? process.exit(0) : process.exit(1);
}).catch(e => {
log.error(e);
process.exit(1);
});
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();
success === true ? process.exit(0) : process.exit(1);
} catch (error) {
log.error(error);
process.exit(1);
}

}

module.exports = {
run
};

0 comments on commit c59eae0

Please sign in to comment.