diff --git a/Dockerfile b/Dockerfile index 4d0fea440..0b7c8caa4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,10 @@ COPY . /usr/src/app # Ensure the runtime of the container is in production mode. ENV NODE_ENV production +# Store the current git revision. +ARG REVISION_HASH +ENV REVISION_HASH=${REVISION_HASH} + # Install app dependencies and build static assets. RUN yarn global add node-gyp && \ yarn install --frozen-lockfile && \ diff --git a/config.js b/config.js index 956e7ac8f..b24c5dfc9 100644 --- a/config.js +++ b/config.js @@ -55,6 +55,10 @@ const CONFIG = { ? process.env.TALK_LOGGING_LEVEL : 'info', + // REVISION_HASH when using the docker build will contain the build hash that + // it was built at. + REVISION_HASH: process.env.REVISION_HASH, + //------------------------------------------------------------------------------ // JWT based configuration //------------------------------------------------------------------------------ diff --git a/graph/mutators/asset.js b/graph/mutators/asset.js index 6524331e1..3d018658e 100644 --- a/graph/mutators/asset.js +++ b/graph/mutators/asset.js @@ -56,12 +56,25 @@ const closeNow = async (ctx, id) => } ); +/** + * scrapeAsset will force scrape an asset. + * + * @param {Object} ctx graphql context + * @param {String} id the asset's id to scrape + */ +const scrapeAsset = async (ctx, id) => { + const { services: { Scraper } } = ctx; + + return Scraper.create({ id }); +}; + module.exports = ctx => { let mutators = { Asset: { updateSettings: () => Promise.reject(errors.ErrNotAuthorized), updateStatus: () => Promise.reject(errors.ErrNotAuthorized), closeNow: () => Promise.reject(errors.ErrNotAuthorized), + scrape: () => Promise.reject(errors.ErrNotAuthorized), }, }; @@ -75,6 +88,7 @@ module.exports = ctx => { mutators.Asset.updateStatus = (id, status) => updateStatus(ctx, id, status); mutators.Asset.closeNow = id => closeNow(ctx, id); + mutators.Asset.scrape = id => scrapeAsset(ctx, id); } } diff --git a/graph/resolvers/root_mutation.js b/graph/resolvers/root_mutation.js index 8a638f589..e27d217fe 100644 --- a/graph/resolvers/root_mutation.js +++ b/graph/resolvers/root_mutation.js @@ -133,6 +133,9 @@ const RootMutation = { revokeToken: async (_, { input }, { mutators: { Token } }) => { await Token.revoke(input); }, + forceScrapeAsset: async (_, { id }, { mutators: { Asset } }) => { + await Asset.scrape(id); + }, }; module.exports = RootMutation; diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql index 79d259122..ea574ee6b 100644 --- a/graph/typeDefs.graphql +++ b/graph/typeDefs.graphql @@ -1420,6 +1420,12 @@ type SetUserRoleResponse implements Response { errors: [UserError!] } +type ForceScrapeAssetResponse implements Response { + + # An array of errors relating to the mutation that occurred. + errors: [UserError!] +} + # All mutations for the application are defined on this object. type RootMutation { @@ -1514,6 +1520,9 @@ type RootMutation { # Stop Ignoring comments by another user. stopIgnoringUser(id: ID!): StopIgnoringUserResponse + + # forceScrapeAsset will force scrape the Asset with the given ID. + forceScrapeAsset(id: ID!): ForceScrapeAssetResponse } type UsernameChangedPayload { diff --git a/routes/api/v1/index.js b/routes/api/v1/index.js index e331d09d8..46d5c0278 100644 --- a/routes/api/v1/index.js +++ b/routes/api/v1/index.js @@ -1,10 +1,11 @@ const express = require('express'); -const pkg = require('../../../package.json'); +const { version } = require('../../../package.json'); +const { REVISION_HASH } = require('../../../config'); const router = express.Router(); // Return the current version. router.get('/', (req, res) => { - res.json({ version: pkg.version }); + res.json({ version, revision: REVISION_HASH }); }); router.use('/account', require('./account')); diff --git a/scripts/docker.sh b/scripts/docker.sh index f11aeb208..dc5759e5e 100755 --- a/scripts/docker.sh +++ b/scripts/docker.sh @@ -54,9 +54,16 @@ deploy_branch() { docker push coralproject/talk:$CIRCLE_BRANCH-onbuild } +ARGS="" + +if [[ -n "$CIRCLE_SHA1" ]] +then + ARGS="--build-arg REVISION_HASH=${CIRCLE_SHA1}" +fi + # build the repo, including the onbuild tagged versions. -docker build -t coralproject/talk:latest -f Dockerfile . -docker build -t coralproject/talk:latest-onbuild -f Dockerfile.onbuild . +docker build -t coralproject/talk:latest ${ARGS} -f Dockerfile . +docker build -t coralproject/talk:latest-onbuild ${ARGS} -f Dockerfile.onbuild . if [ "$1" = "deploy" ] then @@ -80,4 +87,4 @@ then deploy_branch fi fi -fi \ No newline at end of file +fi