Skip to content

Commit

Permalink
Merge pull request #84 from artsy/staging
Browse files Browse the repository at this point in the history
Deploy
  • Loading branch information
icirellik authored May 20, 2021
2 parents 7d4a779 + 1c12aaa commit a26236c
Show file tree
Hide file tree
Showing 21 changed files with 2,394 additions and 1,473 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ node_modules
npm-debug.log
.vscode
.circleci

dist/
2 changes: 1 addition & 1 deletion .env.test
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ typings/
# dotenv environment variables file
.env

# Dist folder
dist/
42 changes: 29 additions & 13 deletions .vscode/tasks.json
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"
}
]
}
24 changes: 14 additions & 10 deletions Dockerfile
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"]
2 changes: 1 addition & 1 deletion hokusai/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: '2'
services:
volley:
command: node index.js
command: yarn dev
environment:
- NODE_ENV=development
- PORT=5500
Expand Down
45 changes: 30 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,17 @@
"repository": "https://github.com/artsy/volley",
"author": "Alan Johnson",
"scripts": {
"start": "node index.js",
"build": "tsc",
"start": "node dist/index.js",
"start:debug": "node --inspect dist/index.js",
"dev": "yarn build && yarn start",
"test": "jest"
},
"license": "MIT",
"private": true,
"engines": {
"node": "12"
},
"dependencies": {
"@koa/cors": "2.2.1",
"@sentry/node": "5.11.1",
"dd-trace": "0.16.3",
"dotenv": "8.2.0",
"ip-address": "6.1.0",
"koa": "2.5.1",
"koa-body": "2.5.0",
"koa-router": "7.4.0",
"koa-sslify": "4.0.3",
"node-dogstatsd": "0.0.7"
},
"prettier": {
"bracketSpacing": true,
"semi": false,
Expand All @@ -38,12 +29,33 @@
"git add"
]
},
"dependencies": {
"@koa/cors": "2.2.1",
"@koa/router": "10.0.0",
"@sentry/node": "5.11.1",
"dd-trace": "0.16.3",
"dotenv": "8.2.0",
"ip-address": "6.1.0",
"koa": "2.5.1",
"koa-body": "2.5.0",
"koa-sslify": "5.0.0",
"node-dogstatsd": "0.0.7"
},
"devDependencies": {
"jest": "24.9.0",
"@types/jest": "26.0.23",
"@types/koa": "2.13.1",
"@types/koa-sslify": "4.0.1",
"@types/koa__cors": "3.0.2",
"@types/koa__router": "8.0.4",
"@types/supertest": "2.0.11",
"jest": "26.6.3",
"jest-junit": "10.0.0",
"supertest": "4.0.2"
"supertest": "4.0.2",
"ts-jest": "26.5.6",
"typescript": "4.2.4"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"setupFiles": [
"dotenv/config",
Expand All @@ -60,6 +72,9 @@
"reporters": [
"default",
"jest-junit"
],
"testPathIgnorePatterns": [
"<rootDir>/dist"
]
},
"jest-junit": {
Expand Down
8 changes: 4 additions & 4 deletions __test__/index.test.js → src/__test__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const request = require('supertest')
const server = require('../index')
import request from 'supertest'
import { server } from '../index'

describe("the server's reporting capabilities", () => {
beforeEach(() => {
console.error = jest.fn()
})

afterEach(() => {
server.close()
console.error.mockClear()
server.close(() => {})
;(console.error as any).mockClear()
})

it('responds that the server is healthy', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const initializePostMetric = require('../postMetric')
import { initialize as initializePostMetric } from '../postMetric'

describe('postMetric', () => {
let statsdClient
let postMetric
let statsdClient: any
let postMetric: any

beforeEach(() => {
statsdClient = {
Expand All @@ -19,7 +19,7 @@ describe('postMetric', () => {
})

afterEach(() => {
console.error.mockClear()
(console.error as any).mockClear()
})

describe('with no whitelists', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const tracer = require('dd-trace')
const initDataDogTracer = require('../tracer')
const { initDataDogTracer } = require('../tracer')

jest.mock('dd-trace', () => ({
init: jest.fn(),
Expand Down
37 changes: 37 additions & 0 deletions src/app/calibreWebhookRoute.ts
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'
}
}
Loading

0 comments on commit a26236c

Please sign in to comment.