-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from artsy/staging
Deploy
- Loading branch information
Showing
21 changed files
with
2,394 additions
and
1,473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,5 @@ node_modules | |
npm-debug.log | ||
.vscode | ||
.circleci | ||
|
||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
NODE_ENV=test | ||
DATADOG_AGENT_HOSTNAME=test-hostname | ||
DATADOG_AGENT_HOSTNAME=test-hostname |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,3 +55,5 @@ typings/ | |
# dotenv environment variables file | ||
.env | ||
|
||
# Dist folder | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,44 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "0.1.0", | ||
"version": "2.0.0", | ||
"command": "yarn", | ||
"isShellCommand": true, | ||
"showOutput": "always", | ||
"suppressTaskName": true, | ||
"tasks": [ | ||
{ | ||
"taskName": "install", | ||
"args": ["install"] | ||
"label": "install", | ||
"type": "shell", | ||
"args": [ | ||
"install" | ||
], | ||
"problemMatcher": [] | ||
}, | ||
{ | ||
"taskName": "update", | ||
"args": ["update"] | ||
"label": "update", | ||
"type": "shell", | ||
"args": [ | ||
"update" | ||
], | ||
"problemMatcher": [] | ||
}, | ||
{ | ||
"taskName": "test", | ||
"args": ["run", "test"] | ||
"label": "test", | ||
"type": "shell", | ||
"args": [ | ||
"run", | ||
"test" | ||
], | ||
"problemMatcher": [], | ||
"group": "test" | ||
}, | ||
{ | ||
"taskName": "build", | ||
"isBuildCommand": true, | ||
"args": ["run", "build"] | ||
"label": "build", | ||
"type": "shell", | ||
"args": [ | ||
"run", | ||
"build" | ||
], | ||
"problemMatcher": [], | ||
"group": "build" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,32 @@ | ||
# Start from alpine | ||
FROM node:12.18-alpine | ||
|
||
WORKDIR /app | ||
# Expose ports | ||
ENV PORT 8080 | ||
EXPOSE 8080 | ||
|
||
# Install dumb-init | ||
# Set up deploy user | ||
RUN apk --no-cache --quiet add \ | ||
dumb-init && \ | ||
adduser -D -g '' deploy | ||
|
||
WORKDIR /app | ||
RUN chown deploy:deploy $(pwd) | ||
|
||
# Switch to deploy user | ||
USER deploy | ||
|
||
# Set up node modules | ||
COPY package.json yarn.lock ./ | ||
COPY --chown=deploy:deploy package.json yarn.lock ./ | ||
RUN yarn install --frozen-lockfile && yarn cache clean | ||
|
||
# Finally, add the rest of our app's code | ||
# (this is done at the end so that changes to our app's code | ||
# don't bust Docker's cache) | ||
COPY . ./ | ||
RUN chown -R deploy:deploy ./ | ||
|
||
# Switch to deploy user | ||
USER deploy | ||
COPY --chown=deploy:deploy . ./ | ||
|
||
ENV PORT 8080 | ||
EXPOSE 8080 | ||
RUN yarn build | ||
|
||
ENTRYPOINT ["/usr/bin/dumb-init", "--"] | ||
CMD ["node", "index.js"] | ||
CMD ["node", "dist/index.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { CalibrePage } from '../common/calibre' | ||
import { VolleyApi } from '../common/volley' | ||
import Koa from 'koa' | ||
import Router from '@koa/router' | ||
import type { postMetric } from './postMetric' | ||
|
||
const CALIBRE_SERVICE_PREFIX = process.env.CALIBRE_SERVICE_PREFIX || 'calibre' | ||
|
||
function sanitize(data: string): string { | ||
return data.replace(/[- ]/g, "_") | ||
} | ||
|
||
export const calibreWebhookRoute = (postMetric: postMetric) => { | ||
return (ctx: Koa.ParameterizedContext<any, Router.RouterParamContext<any, {}>, any>) => { | ||
const siteId = sanitize(ctx.request.body.site_id) | ||
|
||
const pages = ctx.request.body.pages as CalibrePage[] | ||
for (let page of pages) { | ||
const pageId = sanitize(page.id) | ||
const pageDevice = sanitize(page.profile).toLowerCase() | ||
const deviceType = (pageDevice === 'chrome_desktop') ? 'desktop' : 'mobile' | ||
|
||
for (let metric of page.metrics) { | ||
const prefix = `${CALIBRE_SERVICE_PREFIX}.${siteId}` | ||
|
||
const volley = VolleyApi.fromCalibreApi(metric, [ | ||
`form:${deviceType}`, `mode:${pageDevice}`, `page:${pageId}` | ||
]) | ||
|
||
postMetric(prefix, volley, true) | ||
} | ||
} | ||
|
||
ctx.status = 202 | ||
ctx.body = 'OK' | ||
} | ||
} |
Oops, something went wrong.