From a090e9ab4763df988fd1a59aabd09c2b72efac6f Mon Sep 17 00:00:00 2001 From: Olivier Corradi Date: Tue, 22 Nov 2016 19:26:36 +0100 Subject: [PATCH] Added opbeat and initial circle ci --- api/package.json | 3 +- api/server.js | 12 +++ api/yarn.lock | 177 +++++++++++++++++++++++++++++++++++++++++++-- circle.yml | 15 ++++ docker-compose.yml | 2 +- production.yaml | 29 ++++---- 6 files changed, 217 insertions(+), 21 deletions(-) create mode 100644 circle.yml diff --git a/api/package.json b/api/package.json index 7127a2cec1..700f9b6eb9 100644 --- a/api/package.json +++ b/api/package.json @@ -10,7 +10,8 @@ "memcached": "^2.2.2", "moment": "^2.15.2", "mongodb": "^2.2.9", - "node-statsd": "^0.1.1" + "node-statsd": "^0.1.1", + "opbeat": "^3.21.0" }, "devDependencies": { "nodemon": "^1.10.2" diff --git a/api/server.js b/api/server.js index 26da65a360..2ab626d66f 100644 --- a/api/server.js +++ b/api/server.js @@ -11,6 +11,8 @@ var MongoClient = require('mongodb').MongoClient; var app = express(); var server = http.Server(app); +var isProduction = process.env.ENV === 'production'; + // * Common app.use(function(req, res, next) { res.header('Access-Control-Allow-Origin', '*'); @@ -18,6 +20,16 @@ app.use(function(req, res, next) { next(); }); +// * Opbeat +if (isProduction) { + var opbeat = require('opbeat').start({ + appId: 'c36849e44e', + organizationId: '093c53b0da9d43c4976cd0737fe0f2b1', + secretToken: process.env['OPBEAT_SECRET'] + }) + app.use(opbeat.middleware.express()) +} + // * Cache var memcachedClient = new Memcached(process.env['MEMCACHED_HOST']); diff --git a/api/yarn.lock b/api/yarn.lock index 2fbf2cf2bb..522d82c07e 100644 --- a/api/yarn.lock +++ b/api/yarn.lock @@ -11,6 +11,16 @@ accepts@~1.3.3: mime-types "~2.1.11" negotiator "0.6.1" +after-all-results@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/after-all-results/-/after-all-results-2.0.0.tgz#6ac2fc202b500f88da8f4f5530cfa100f4c6a2d0" + +after-all@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/after-all/-/after-all-2.0.2.tgz#20300298ed6094b4c85c98e7c8ad4dca628f9f73" + dependencies: + once "^1.3.0" + ansi-regex@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.0.0.tgz#c5061b6e0ef8a81775e50f5d66151bf6bf371107" @@ -71,6 +81,12 @@ assert-plus@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525" +async-cache@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/async-cache/-/async-cache-1.1.0.tgz#4a9a5a89d065ec5d8e5254bd9ee96ba76c532b5a" + dependencies: + lru-cache "^4.0.0" + async-each@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.1.tgz#19d386a1d9edc6e7c1c85d388aedbcc56d33602d" @@ -216,6 +232,10 @@ console-control-strings@^1.0.0, console-control-strings@~1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e" +console-log-level@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/console-log-level/-/console-log-level-1.3.0.tgz#9d249f6eaa3aaf33f27fc0bf293259bc5340c1b3" + content-disposition@0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.1.tgz#87476c6a67c8daa87e32e87616df883ba7fb071b" @@ -228,7 +248,7 @@ cookie-signature@1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c" -cookie@0.3.1: +cookie@^0.3.1, cookie@0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb" @@ -464,6 +484,12 @@ debug@^2.2.0: dependencies: ms "0.7.2" +debug@^2.3.0: + version "2.3.3" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.3.3.tgz#40c453e67e6e13c901ddec317af8986cda9eff8c" + dependencies: + ms "0.7.2" + debug@~2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da" @@ -521,12 +547,22 @@ encodeurl@~1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.1.tgz#79e3d58655346909fe6f0f45a5de68103b294d20" +end-of-stream@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.1.0.tgz#e9353258baa9108965efc41cb0ef8ade2f3cfb07" + dependencies: + once "~1.3.0" + end-of-stream@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.0.0.tgz#d4596e702734a93e40e9af864319eabd99ff2f0e" dependencies: once "~1.3.0" +error-callsites@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/error-callsites/-/error-callsites-1.0.1.tgz#4286169adf8fc12482f556111724c5aed873a692" + es6-promise@^3.0.2: version "3.3.1" resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-3.3.1.tgz#a08cdde84ccdbf34d027a1451bc91d4bcd28a613" @@ -927,6 +963,12 @@ is-glob@^2.0.0, is-glob@^2.0.1: dependencies: is-extglob "^1.0.0" +is-integer@^1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/is-integer/-/is-integer-1.0.6.tgz#5273819fada880d123e1ac00a938e7172dd8d95e" + dependencies: + is-finite "^1.0.0" + is-my-json-valid@^2.12.4: version "2.15.0" resolved "https://registry.yarnpkg.com/is-my-json-valid/-/is-my-json-valid-2.15.0.tgz#936edda3ca3c211fd98f3b2d3e08da43f7b2915b" @@ -936,6 +978,17 @@ is-my-json-valid@^2.12.4: jsonpointer "^4.0.0" xtend "^4.0.0" +is-native@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-native/-/is-native-1.0.1.tgz#cd18cc162e8450d683b5babe79ac99c145449675" + dependencies: + is-nil "^1.0.0" + to-source-code "^1.0.0" + +is-nil@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-nil/-/is-nil-1.0.1.tgz#2daba29e0b585063875e7b539d071f5b15937969" + is-npm@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-npm/-/is-npm-1.0.0.tgz#f2fb63a65e4905b406c86072765a1a4dc793b9f4" @@ -962,6 +1015,10 @@ is-redirect@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-redirect/-/is-redirect-1.0.0.tgz#1d03dded53bd8db0f30c26e4f95d36fc7c87dc24" +is-secret@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/is-secret/-/is-secret-1.0.2.tgz#06795a70e945558d1dac739b93e640fad175df84" + is-stream@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" @@ -1004,7 +1061,7 @@ json-schema@0.2.3: version "0.2.3" resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13" -json-stringify-safe@~5.0.1: +json-stringify-safe@^5.0.0, json-stringify-safe@~5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" @@ -1106,6 +1163,13 @@ lowercase-keys@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-1.0.0.tgz#4e3366b39e7f5457e35f1324bdf6f88d0bfc7306" +lru-cache@^4.0.0, lru-cache@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.0.1.tgz#1343955edaf2e37d9b9e7ee7241e27c4b9fb72be" + dependencies: + pseudomap "^1.0.1" + yallist "^2.0.0" + map-stream@~0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/map-stream/-/map-stream-0.1.0.tgz#e56aa94c4c8055a16404a0674b78f215f7c8e194" @@ -1191,6 +1255,10 @@ mkdirp@^0.5.0, "mkdirp@>=0.5 0", mkdirp@~0.5.1: dependencies: minimist "0.0.8" +module-details-from-path@^1.0.2: + version "1.0.3" + resolved "https://registry.yarnpkg.com/module-details-from-path/-/module-details-from-path-1.0.3.tgz#114c949673e2a8a35e9d35788527aa37b679da2b" + moment: version "2.15.2" resolved "https://registry.yarnpkg.com/moment/-/moment-2.15.2.tgz#1bfdedf6a6e345f322fe956d5df5bd08a8ce84dc" @@ -1250,7 +1318,7 @@ node-statsd@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/node-statsd/-/node-statsd-0.1.1.tgz#27a59348763d0af7a037ac2a031fef3f051013d3" -node-uuid@~1.4.7: +node-uuid@^1.4.7, node-uuid@~1.4.7: version "1.4.7" resolved "https://registry.yarnpkg.com/node-uuid/-/node-uuid-1.4.7.tgz#6da5a17668c4b3dd59623bda11cf7fa4c1f60a6f" @@ -1335,6 +1403,42 @@ once@~1.3.0, once@~1.3.3: dependencies: wrappy "1" +opbeat: + version "3.21.0" + resolved "https://registry.yarnpkg.com/opbeat/-/opbeat-3.21.0.tgz#6836eff78ff63c52bda5ef67eaf5d0200221df3c" + dependencies: + after-all "^2.0.2" + console-log-level "^1.3.0" + cookie "^0.3.1" + debug "^2.3.0" + end-of-stream "^1.1.0" + is-native "^1.0.1" + json-stringify-safe "^5.0.0" + lru-cache "^4.0.1" + node-uuid "^1.4.7" + object-assign "^4.1.0" + opbeat-http-client "^1.2.0" + opbeat-release-tracker "^1.1.1" + redact-secrets "^1.0.0" + require-in-the-middle "^2.1.2" + semver "^5.3.0" + sql-summary "^1.0.0" + stackman "^1.2.7" + unicode-byte-truncate "^1.0.0" + +opbeat-http-client@^1.0.3, opbeat-http-client@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/opbeat-http-client/-/opbeat-http-client-1.2.0.tgz#f63d93ecdc6da43189317ad083245be04851ccbe" + dependencies: + json-stringify-safe "^5.0.0" + +opbeat-release-tracker@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/opbeat-release-tracker/-/opbeat-release-tracker-1.1.1.tgz#2f65767250b955ae988edca875acd836120e7e0a" + dependencies: + after-all-results "^2.0.0" + opbeat-http-client "^1.0.3" + os-homedir@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3" @@ -1370,7 +1474,7 @@ parseurl@~1.3.1: version "1.3.1" resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.1.tgz#c8ab8c9223ba34888aa64a297b28853bec18da56" -path-is-absolute@^1.0.0: +path-is-absolute@^1.0.0, path-is-absolute@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" @@ -1419,6 +1523,10 @@ ps-tree@^1.0.1: dependencies: event-stream "~3.3.0" +pseudomap@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" + punycode@^1.4.1: version "1.4.1" resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e" @@ -1479,6 +1587,13 @@ readdirp@^2.0.0: readable-stream "^2.0.2" set-immediate-shim "^1.0.1" +redact-secrets@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/redact-secrets/-/redact-secrets-1.0.0.tgz#60f1db56924fe90a203ba8ccb39283cdbb0d907c" + dependencies: + is-secret "^1.0.0" + traverse "^0.6.6" + regex-cache@^0.4.2: version "0.4.3" resolved "https://registry.yarnpkg.com/regex-cache/-/regex-cache-0.4.3.tgz#9b1a6c35d4d0dfcef5711ae651e8e9d3d7114145" @@ -1538,10 +1653,21 @@ require_optional@~1.0.0: resolve-from "^2.0.0" semver "^5.1.0" +require-in-the-middle@^2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/require-in-the-middle/-/require-in-the-middle-2.1.2.tgz#bddb89316d45bcdb08e2c6186bd2e6e819a8eeae" + dependencies: + module-details-from-path "^1.0.2" + resolve "^1.1.7" + resolve-from@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-2.0.0.tgz#9480ab20e94ffa1d9e80a804c7ea147611966b57" +resolve@^1.1.7: + version "1.1.7" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" + retry@0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/retry/-/retry-0.6.0.tgz#1c010713279a6fd1e8def28af0c3ff1871caa537" @@ -1562,7 +1688,7 @@ semver-diff@^2.0.0: dependencies: semver "^5.0.3" -semver@^5.0.3, semver@^5.1.0, semver@~5.3.0: +semver@^5.0.3, semver@^5.1.0, semver@^5.3.0, semver@~5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f" @@ -1629,6 +1755,10 @@ split@0.3: dependencies: through "2" +sql-summary@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/sql-summary/-/sql-summary-1.0.0.tgz#39e3a51d8d85e46739836fc7d67d0654b173a39f" + sshpk@^1.7.0: version "1.10.1" resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.10.1.tgz#30e1a5d329244974a1af61511339d595af6638b0" @@ -1644,6 +1774,18 @@ sshpk@^1.7.0: jsbn "~0.1.0" tweetnacl "~0.14.0" +stackman@^1.2.7: + version "1.2.7" + resolved "https://registry.yarnpkg.com/stackman/-/stackman-1.2.7.tgz#cea847b01e8078db2493777722d3ba635846d593" + dependencies: + after-all "^2.0.2" + async-cache "^1.1.0" + debug "^2.2.0" + error-callsites "^1.0.1" + lru-cache "^4.0.1" + path-is-absolute "^1.0.1" + semver "^5.3.0" + "statuses@>= 1.3.0 < 2", statuses@~1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.0.tgz#8e55758cb20e7682c1f4fce8dcab30bf01d1e07a" @@ -1727,6 +1869,12 @@ tiny-emitter@1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/tiny-emitter/-/tiny-emitter-1.0.2.tgz#8e49470d3f55f89e247210368a6bb9fb51aa1601" +to-source-code@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/to-source-code/-/to-source-code-1.0.2.tgz#dd136bdb1e1dbd80bbeacf088992678e9070bfea" + dependencies: + is-nil "^1.0.0" + touch@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/touch/-/touch-1.0.0.tgz#449cbe2dbae5a8c8038e30d71fa0ff464947c4de" @@ -1739,6 +1887,10 @@ tough-cookie@~2.3.0: dependencies: punycode "^1.4.1" +traverse@^0.6.6: + version "0.6.6" + resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.6.6.tgz#cbdf560fd7b9af632502fed40f918c157ea97137" + tunnel-agent@~0.4.1: version "0.4.3" resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.4.3.tgz#6373db76909fe570e08d73583365ed828a74eeeb" @@ -1766,6 +1918,17 @@ undefsafe@0.0.3: version "0.0.3" resolved "https://registry.yarnpkg.com/undefsafe/-/undefsafe-0.0.3.tgz#ecca3a03e56b9af17385baac812ac83b994a962f" +unicode-byte-truncate@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/unicode-byte-truncate/-/unicode-byte-truncate-1.0.0.tgz#aa6f0f3475193fe20c320ac9213e36e62e8764a7" + dependencies: + is-integer "^1.0.6" + unicode-substring "^0.1.0" + +unicode-substring@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/unicode-substring/-/unicode-substring-0.1.0.tgz#6120ce3c390385dbcd0f60c32b9065c4181d4b36" + unpipe@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" @@ -1836,3 +1999,7 @@ xtend@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af" +yallist@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.0.0.tgz#306c543835f09ee1a4cb23b7bce9ab341c91cdd4" + diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000000..2bb2837157 --- /dev/null +++ b/circle.yml @@ -0,0 +1,15 @@ +machine: + pre: + - curl -sSL https://s3.amazonaws.com/circle-downloads/install-circleci-docker.sh | bash -s -- 1.10.0 + - sudo curl -L -o /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/1.8.0/docker-compose-`uname -s`-`uname -m` + - sudo chmod +x /usr/local/bin/docker-compose + post: + - echo "we should docker-login here" + services: + - docker +dependencies: + override: + - docker-compose build +test: + override: + - echo "no test" diff --git a/docker-compose.yml b/docker-compose.yml index d8841c09c9..1e56683439 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,8 +16,8 @@ services: feeder: build: feeder depends_on: [mongo] + env_file: ./secrets.env environment: - - 'ENTSOE_TOKEN=${ENTSOE_TOKEN}' - ENV=development - MEMCACHED_HOST=memcached - 'MONGO_URL=mongodb://mongo:27017/electricity' diff --git a/production.yaml b/production.yaml index 79fdfe5faa..ee27b3435e 100644 --- a/production.yaml +++ b/production.yaml @@ -2,26 +2,27 @@ version: '2' services: api: build: api - environment: - - ENV=production - - MEMCACHED_HOST=memcached - - MONGO_URL=mongodb://mongo:27017/electricity - - STATSD_HOST=grafana-graphite-statsd.infrastructure_default - - VIRTUAL_HOST=electricitymap-api.tmrow.co - env_file: ./mailgun.env depends_on: [mongo, memcached] + env_file: [./mailgun.env, ./secrets.env] + environment: + - ENV=production + - MEMCACHED_HOST=memcached + - MONGO_URL=mongodb://mongo:27017/electricity + - STATSD_HOST=grafana-graphite-statsd.infrastructure_default + - VIRTUAL_HOST=electricitymap-api.tmrow.co + image: corradio/electricitymap_api networks: [default, infrastructure] # required to be able to com' with statsd & nginx volumes: ['/home/shared/electricitymap/data:/home/data'] feeder: build: feeder - environment: - - 'ENTSOE_TOKEN=${ENTSOE_TOKEN}' - - ENV=production - - MEMCACHED_HOST=memcached - - MONGO_URL=mongodb://mongo:27017 - - STATSD_HOST=grafana-graphite-statsd.infrastructure_default - env_file: ./mailgun.env depends_on: [mongo] + env_file: [./mailgun.env, ./secrets.env] + environment: + - ENV=production + - MEMCACHED_HOST=memcached + - MONGO_URL=mongodb://mongo:27017 + - STATSD_HOST=grafana-graphite-statsd.infrastructure_default + image: corradio/electricitymap_feeder networks: [default, infrastructure] # required to be able to com' with statsd volumes: ['/home/shared/electricitymap/data:/home/data'] memcached: