Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pubish npm package #763

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!app/
!package.json
!package-lock.json
!README.md
!LICENSE
40 changes: 22 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,44 @@ node_js:
services:
- docker

env:
global:
- BUILD_TIME="$(date '+%Y-%m-%d %H:%M:%S')"

script:
# Audit npm packages. Fail build whan a PR audit fails, otherwise report the vulnerability and proceed.
- if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then npx audit-ci --low -a node-fetch; else npx audit-ci --low -a node-fetch || true; fi
- npm run lint
- npm test
- npm run test:apollo:default
- npm run test:apollo:local
- npm run test:apollo:passport.local
- export BUILD_TIME=`date '+%Y-%m-%d %H:%M:%S'`
- docker build --rm --build-arg BUILD_TIME="$BUILD_TIME" --build-arg BUILD_ID="${TRAVIS_BUILD_NUMBER}-${TRAVIS_COMMIT}" -t "quay.io/razee/razeedash-api:${TRAVIS_COMMIT}" .
- travis_fold start "npx.audit-ci" && if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then npx audit-ci; else npx audit-ci || true; fi && travis_fold end "npx.audit-ci"
- travis_fold start "npm.lint" && npm run lint && travis_fold end "npm.lint"
- travis_fold start "npm.test" && npm test && travis_fold end "npm.test"
- travis_fold start "npm.test:apollo:default" && npm run test:apollo:default && travis_fold end "npm.test:apollo:default"
- travis_fold start "npm.test:apollo:local" && npm run test:apollo:local && travis_fold end "npm.test:apollo:local"
- travis_fold start "npm.test:apollo:passport.local" && npm run test:apollo:passport.local && travis_fold end "npm.test:apollo:passport.local"
- travis_fold start "docker.build" && docker build --rm --build-arg BUILD_TIME="$BUILD_TIME" --build-arg BUILD_ID="${TRAVIS_BUILD_NUMBER}-${TRAVIS_COMMIT}" -t "quay.io/razee/razeedash-api:${TRAVIS_COMMIT}" . && travis_fold end "docker.build"
- if [ -n "${TRAVIS_TAG}" ]; then docker tag quay.io/razee/razeedash-api:${TRAVIS_COMMIT} quay.io/razee/razeedash-api:${TRAVIS_TAG}; fi
- docker images
- ./build/process-template.sh kubernetes/razeedash-api/resource.yaml >/tmp/resource.yaml
- if [[ "${TRAVIS_TAG}" =~ ^[0-9]+\.[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

deploy:
adamkingit marked this conversation as resolved.
Show resolved Hide resolved
# Deploy alpha builds
# Publish builds tagged as 1.2.3 for release, or 1.2.3-1 as release candidates
- provider: script
script: docker push "quay.io/razee/razeedash-api:${TRAVIS_TAG}"
skip_cleanup: true
on:
tags: true
condition: ${TRAVIS_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+_[0-9]{3}$
condition: ${TRAVIS_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?$
- provider: releases
file: /tmp/resource.yaml
skip_cleanup: true
draft: true
on:
tags: true
condition: ${TRAVIS_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+_[0-9]{3}$
condition: ${TRAVIS_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+-[0-9]+$
api_key: "${GITHUB_TOKEN}"
name: "${TRAVIS_TAG}"
# Deploy released builds
- provider: script
script: docker push "quay.io/razee/razeedash-api:${TRAVIS_TAG}"
skip_cleanup: true
on:
tags: true
condition: ${TRAVIS_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+$
- provider: releases
file: /tmp/resource.yaml
skip_cleanup: true
Expand All @@ -54,3 +51,10 @@ deploy:
condition: ${TRAVIS_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+$
api_key: "${GITHUB_TOKEN}"
name: "${TRAVIS_TAG}"
- 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]+(-[0-9]+)?$
13 changes: 6 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ USER node
WORKDIR /home/node

COPY --chown=node . /home/node
RUN npm install --production --loglevel=warn
RUN npm ci --production --loglevel=warn


#######################################
Expand All @@ -36,13 +36,12 @@ FROM node:lts-alpine
USER node
WORKDIR /home/node

RUN export BUILD_TIME=`date '+%Y-%m-%d %H:%M:%S'`
ARG BUILD_TIME
ENV BUILD_TIME=${BUILD_TIME}
ARG BUILD_ID
ENV BUILD_ID=${BUILD_ID}
ARG BUILD_TIME="$(date '+%Y-%m-%d %H:%M:%S')"
ENV BUILD_TIME="${BUILD_TIME}"
ARG BUILD_ID="dev"
ENV BUILD_ID="${BUILD_ID}"

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

EXPOSE 3333
CMD ["npm", "start"]
CMD ["./bin/main"]
10 changes: 6 additions & 4 deletions app/apollo/resolvers/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,18 @@ const channelResolvers = {
}
},
editChannel: async (parent, { orgId: org_id, uuid, name }, context)=>{
const { models, me, req_id, logger } = context;
const reqContext=context;
const { models, me, req_id, logger } = reqContext;
const queryName = 'editChannel';
logger.debug({ req_id, user: whoIs(me), org_id, uuid, name }, `${queryName} enter`);

try{
const channel = await models.Channel.findOne({ uuid, org_id });
if(!channel){
throw new NotFoundError(`channel uuid "${uuid}" not found`, context);
throw new NotFoundError(`channel uuid "${uuid}" not found`, reqContext);
}
await validAuth(me, org_id, ACTIONS.UPDATE, TYPES.CHANNEL, queryName, context, [channel.uuid, channel.name]);
reqContext.channel=channel;
await validAuth(me, org_id, ACTIONS.UPDATE, TYPES.CHANNEL, queryName, reqContext, [channel.uuid, channel.name]);
await models.Channel.updateOne({ org_id, uuid }, { $set: { name } });

// find any subscriptions for this channel and update channelName in those subs
Expand All @@ -216,7 +218,7 @@ const channelResolvers = {
throw err;
}
logger.error(err, `${queryName} encountered an error when serving ${req_id}.`);
throw new RazeeQueryError(`Query ${queryName} error. ${err.message}`, context);
throw new RazeeQueryError(`Query ${queryName} error. ${err.message}`, reqContext);
}
},
addChannelVersion: async(parent, { orgId: org_id, channelUuid: channel_uuid, name, type, content, file, description }, context)=>{
Expand Down
25 changes: 13 additions & 12 deletions app/apollo/resolvers/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,34 +330,35 @@ const subscriptionResolvers = {
}
},
editSubscription: async (parent, { orgId, uuid, name, groups, channelUuid: channel_uuid, versionUuid: version_uuid }, context)=>{
const { models, me, req_id, logger } = context;
const reqContext = context;
const { models, me, req_id, logger } = reqContext;
const queryName = 'editSubscription';
logger.debug({req_id, user: whoIs(me), orgId }, `${queryName} enter`);
// await validAuth(me, orgId, ACTIONS.UPDATE, TYPES.SUBSCRIPTION, queryName, context);
// await validAuth(me, orgId, ACTIONS.UPDATE, TYPES.SUBSCRIPTION, queryName, reqContext);

try{
var subscription = await models.Subscription.findOne({ org_id: orgId, uuid });
const subscription = await models.Subscription.findOne({ org_id: orgId, uuid });
if(!subscription){
throw new NotFoundError(`Subscription { uuid: "${uuid}", orgId:${orgId} } not found.`, context);
throw new NotFoundError(`Subscription { uuid: "${uuid}", orgId:${orgId} } not found.`, reqContext);
}

await validAuth(me, orgId, ACTIONS.UPDATE, TYPES.SUBSCRIPTION, queryName, context, [subscription.uuid, subscription.name]);
reqContext.subscription = subscription;
await validAuth(me, orgId, ACTIONS.UPDATE, TYPES.SUBSCRIPTION, queryName, reqContext, [subscription.uuid, subscription.name]);

// loads the channel
var channel = await models.Channel.findOne({ org_id: orgId, uuid: channel_uuid });
const channel = await models.Channel.findOne({ org_id: orgId, uuid: channel_uuid });
if(!channel){
throw new NotFoundError(`Channel uuid "${channel_uuid}" not found.`, context);
throw new NotFoundError(`Channel uuid "${channel_uuid}" not found.`, reqContext);
}

// validate groups are all exists in label dbs
await validateGroups(orgId, groups, context);
await validateGroups(orgId, groups, reqContext);

// loads the version
var version = channel.versions.find((version)=>{
return (version.uuid == version_uuid);
});
if(!version){
throw new NotFoundError(`Version uuid "${version_uuid}" not found.`, context);
throw new NotFoundError(`Version uuid "${version_uuid}" not found.`, reqContext);
}

var sets = {
Expand All @@ -366,7 +367,7 @@ const subscriptionResolvers = {
};
await models.Subscription.updateOne({ uuid, org_id: orgId, }, { $set: sets });

pubSub.channelSubChangedFunc({ org_id: orgId }, context);
pubSub.channelSubChangedFunc({ org_id: orgId }, reqContext);

return {
uuid,
Expand All @@ -378,7 +379,7 @@ const subscriptionResolvers = {
throw err;
}
logger.error(err);
throw new RazeeQueryError(`Query ${queryName} error. ${err.message}`, context);
throw new RazeeQueryError(`Query ${queryName} error. ${err.message}`, reqContext);
}
},
setSubscription: async (parent, { orgId: org_id, uuid, versionUuid: version_uuid }, context)=>{
Expand Down
Loading