Created
January 9, 2019 18:57
-
-
Save beatak/9a85b34345820fb87b78b54af31f395a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
diff --git a/bin/run_rspec.sh b/bin/run_rspec.sh | |
index 224a208..2935d5a 100755 | |
--- a/bin/run_rspec.sh | |
+++ b/bin/run_rspec.sh | |
@@ -9,3 +9,5 @@ CURRENT_EPOCH=`date +'%s'` | |
DOCKER_BUILDKIT=1 docker build --tag dev:sinatra-test-$CURRENT_EPOCH --file images/ruby/rspec.Dockerfile --no-cache --progress plain images/ruby | |
docker run -it dev:sinatra-test-$CURRENT_EPOCH | |
+ | |
+echo "Don't forget to run the following command to clean up test images: docker rmi \$(docker images dev:sinatra* -q)" | |
diff --git a/docker-compose.yml b/docker-compose.yml | |
index c1852fb..2909c2e 100644 | |
--- a/docker-compose.yml | |
+++ b/docker-compose.yml | |
@@ -57,6 +57,23 @@ services: | |
stdin_open: true | |
tty: true | |
+ sourcemaps: | |
+ build: | |
+ context: . | |
+ dockerfile: images/sourcemaps_worker/Dockerfile.sourcemaps_worker | |
+ args: | |
+ IMAGE_NAME: "dev" | |
+ networks: | |
+ - app-network | |
+ restart: always | |
+ env_file: | |
+ - ./env/local.env | |
+ environment: | |
+ REDIS_URL: redis://redis:6379/ | |
+ RUN_UNDER: docker | |
+ stdin_open: true | |
+ tty: true | |
+ | |
# travis_worker: | |
# build: | |
# context: images/travis_worker | |
@@ -73,20 +90,6 @@ services: | |
# environment: | |
# REDIS_URL: redis://redis:6379/ | |
- # sm_worker: | |
- # build: | |
- # context: images/sm_worker | |
- # dockerfile: Dockerfile.sm_worker | |
- # args: | |
- # IMAGE_NAME: "dev" | |
- # networks: | |
- # - app-network | |
- # restart: always | |
- # env_file: | |
- # - ./env/local.env | |
- # environment: | |
- # REDIS_URL: redis://redis:6379/ | |
- | |
redis: | |
image: redis:3.2 | |
command: ["redis-server", "--appendonly", "yes"] | |
diff --git a/images/node/Dockerfile b/images/node/Dockerfile | |
index 09c4cc8..4a92fc9 100644 | |
--- a/images/node/Dockerfile | |
+++ b/images/node/Dockerfile | |
@@ -4,7 +4,7 @@ FROM heroku/heroku:18-build | |
# https://nodebin.herokai.com | |
# INSTALL NODE | |
-ENV NODE_VERSION 10.13.0 | |
+ENV NODE_VERSION 10.12.0 | |
ARG NODE_INSTALL_DIR="/app/.heroku/node" | |
RUN mkdir -p $NODE_INSTALL_DIR \ | |
&& curl "https://s3.amazonaws.com/heroku-nodebin/node/release/linux-x64/node-v${NODE_VERSION}-linux-x64.tar.gz" -L --silent --fail --retry 5 --retry-max-time 15 -o /tmp/node.tar.gz \ | |
@@ -20,7 +20,7 @@ ENV NPM_VERSION 6.4.1 | |
RUN npm install -g npm@$NPM_VERSION --save | |
# INSTALL YARN | |
-ENV YARN_VERSION 1.12.3 | |
+ENV YARN_VERSION 1.10.1 | |
ARG YARN_INSTALL_DIR="/app/.heroku/yarn" | |
RUN mkdir -p $YARN_INSTALL_DIR \ | |
&& curl "https://s3.amazonaws.com/heroku-nodebin/yarn/release/yarn-v${YARN_VERSION}.tar.gz" -L --silent --fail --retry 5 --retry-max-time 15 -o /tmp/yarn.tar.gz \ | |
diff --git a/images/ruby/Dockerfile b/images/ruby/Dockerfile | |
index 151cf1a..8b45fdb 100644 | |
--- a/images/ruby/Dockerfile | |
+++ b/images/ruby/Dockerfile | |
@@ -1,5 +1,7 @@ | |
FROM heroku/heroku:18 | |
+# it comes with `ruby 2.5.1p57` | |
+ | |
WORKDIR /app | |
COPY config.ru Gemfile Gemfile.lock src/ /app/ | |
diff --git a/images/ruby/spec/web_spec.rb b/images/ruby/spec/web_spec.rb | |
index 07c6454..58e6a04 100644 | |
--- a/images/ruby/spec/web_spec.rb | |
+++ b/images/ruby/spec/web_spec.rb | |
@@ -174,4 +174,43 @@ describe 'Harriot' do | |
expect(nil).to be(nil) | |
end | |
end | |
+ | |
+ describe 'Ecr' do | |
+ let(:my_commit_id) do | |
+ generate_random_sha1 | |
+ end | |
+ let(:request_body) do | |
+ { | |
+ commit: my_commit_id, | |
+ data: { | |
+ description: 'hello my friend', | |
+ version: 'oo baoaekajlreal kj' | |
+ } | |
+ } | |
+ end | |
+ let(:ecr_request_path) { "/ecr/alx-blanc/master-#{my_commit_id}" } | |
+ | |
+ it 'should be able to process a master-* push' do | |
+ post( | |
+ ecr_request_path, | |
+ request_body.to_json, | |
+ 'CONTENT_TYPE' => 'application/json' | |
+ ) | |
+ expect(JSON.parse(last_response.body)['path']).to eq(ecr_request_path) | |
+ expect(JSON.parse(last_slack_arg['payload'])['text']).to eq("[TESTING] image pushed to ECR \"alx-blanc:master-#{my_commit_id}\"") | |
+ end | |
+ | |
+ it 'should still process ok even if the input is not well-formed' do | |
+ repo_name = 'foo' | |
+ tag_name = 'bar' | |
+ non_master_push_path = "/ecr/#{repo_name}/#{tag_name}" | |
+ post( | |
+ non_master_push_path, | |
+ nil, | |
+ 'CONTENT_TYPE' => 'application/json' | |
+ ) | |
+ expect(JSON.parse(last_response.body)['path']).to eq(non_master_push_path) | |
+ expect(JSON.parse(last_slack_arg['payload'])['text']).to eq("[TESTING] image pushed to ECR \"#{repo_name}:#{tag_name}\"") | |
+ end | |
+ end | |
end | |
diff --git a/images/ruby/src/background_job.rb b/images/ruby/src/background_job.rb | |
index 771b38c..c1b223d 100644 | |
--- a/images/ruby/src/background_job.rb | |
+++ b/images/ruby/src/background_job.rb | |
@@ -57,8 +57,10 @@ class BackgroundJob | |
# ) | |
# Assuming you run with docker-composer: | |
+ # system( | |
+ # 'echo "Run the following command in your terminal!: docker exec -t \$(docker ps -a -q --filter \"ancestor=harriot_lci\") bash -c \"/app/legacy_code.sh && /app/send_to_librato.js --only-display\""' | |
+ # ) | |
system( | |
- 'echo "Run the following command in your terminal!: docker exec -t \$(docker ps -a -q --filter \"ancestor=harriot_lci\") bash -c \"/app/legacy_code.sh && /app/send_to_librato.js --only-display\""' | |
) | |
end | |
else | |
diff --git a/images/ruby/src/web.rb b/images/ruby/src/web.rb | |
index 0739e0e..2cc0e01 100644 | |
--- a/images/ruby/src/web.rb | |
+++ b/images/ruby/src/web.rb | |
@@ -7,13 +7,13 @@ require 'sinatra/base' | |
require 'slack-notifier' | |
require 'redis' | |
-require_relative 'incoming/github' | |
-require_relative 'incoming/heroku' | |
-require_relative 'incoming/travis' | |
+# require_relative 'incoming/github' | |
+# require_relative 'incoming/heroku' | |
+# require_relative 'incoming/travis' | |
+Dir[File.join(__dir__, 'incoming', '*.rb')].each { |file| require file } | |
RUN_UNDER ||= ENV['RUN_UNDER'] | |
SLACK_WEBHOOK_URL ||= ENV['SLACK_WEBHOOK_URL'] | |
-SM_CHANNEL ||= ENV['HARRIOT_SM_CHANNEL'] | |
TRAVIS_CHANNEL ||= ENV['HARRIOT_TRAVIS_CHANNEL'] | |
URL_TRAVIS_CONFIG ||= 'https://api.travis-ci.com/' | |
@@ -48,6 +48,7 @@ class Harriot < Sinatra::Base | |
register Sinatra::Harriot::Github | |
register Sinatra::Harriot::Heroku | |
register Sinatra::Harriot::Travis | |
+ register Sinatra::Harriot::Ecr | |
before do | |
headers 'Content-Type' => 'text/json; charset=utf8' | |
@@ -61,7 +62,6 @@ class Harriot < Sinatra::Base | |
get '/_test_redis' do | |
@@redis.publish TRAVIS_CHANNEL, 'test' | |
- @@redis.publish SM_CHANNEL, 'test' | |
Harriot.log '/_test_redis' | |
status 200 | |
{ path: '/_test_redis', status: 'success' }.to_json | |
diff --git a/images/sm_worker/Dockerfile.sm_worker b/images/sm_worker/Dockerfile.sm_worker | |
index 5584ca5..981edd9 100644 | |
--- a/images/sm_worker/Dockerfile.sm_worker | |
+++ b/images/sm_worker/Dockerfile.sm_worker | |
@@ -1,11 +1,24 @@ | |
ARG IMAGE_NAME="YOU_NEED_TO_PASS_THIS" | |
FROM ${IMAGE_NAME}:harriot-node | |
-ENV NODE_ENV production | |
+# BIG NOTE: ----------------------------------------------- | |
+# In order to build this Dockerfile, its build context | |
+# needs to be at the root of this repository because it | |
+# requires to use the subrepos. | |
+# --------------------------------------------------------- | |
+ | |
WORKDIR /app | |
+ENV NODE_ENV="production" \ | |
+ PATH="/app/goat/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" | |
+ | |
+# To run the following, you need to run | |
+# `bin/setup_subrepo.sh` before. | |
+COPY vendor/github-app-oauth-access-token ./goat | |
+RUN cd goat && npm install --production | |
COPY package*.json ./ | |
-COPY src/ ./src | |
RUN npm install --production | |
-CMD ["node", "src/worker.js"] | |
+# CMD ["node", "src/worker.js"] | |
+# There's no need to run the server, so I'll make it | |
+# one off dyno. | |
diff --git a/images/sm_worker/package.json b/images/sm_worker/package.json | |
index 1251013..907fc2e 100644 | |
--- a/images/sm_worker/package.json | |
+++ b/images/sm_worker/package.json | |
@@ -1,16 +1,14 @@ | |
{ | |
"name": "sm_worker", | |
- "version": "0.0.1", | |
+ "version": "0.0.2", | |
"description": "SourceMap builder", | |
"author": "Takashi Mizohata <[email protected]>", | |
- "license": "Fair", | |
"private": true, | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"dependencies": { | |
- "redis": "2.8.0", | |
"@sentry/cli": "1.33.0", | |
"request": "2.87.0" | |
}, | |
diff --git a/images/sm_worker/src/worker.js b/images/sm_worker/src/worker.js | |
index aaeb573..28424e1 100644 | |
--- a/images/sm_worker/src/worker.js | |
+++ b/images/sm_worker/src/worker.js | |
@@ -3,18 +3,12 @@ | |
const cp = require('child_process'); | |
const os = require('os'); | |
const path = require('path'); | |
-const Redis = require('redis'); | |
const request = require('request'); | |
const PROJECT_ROOT_DIR = path.join(__dirname, '..'); | |
-const REDIS_URL = process.env.REDIS_URL; | |
-const REDIS_CHANNEL = process.env.HARRIOT_SM_CHANNEL; | |
const SENTRY_CLI_PATH = path.join(PROJECT_ROOT_DIR, 'node_modules', '.bin', 'sentry-cli'); | |
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL; | |
-const redisClient = Redis.createClient(REDIS_URL); | |
-let globalLockQueue = []; | |
- | |
const messageSlack = function (text) { | |
const messageBody = { | |
text: text, | |
@@ -37,10 +31,6 @@ const messageSlack = function (text) { | |
}; | |
const processSourceMap = function (jsonObj) { | |
- globalLockQueue.push(jsonObj); | |
- if (globalLockQueue.length > 1) { | |
- return; | |
- } | |
const dateStart = Date.now(); | |
const baseDirName = `web-${dateStart}`; | |
@@ -143,17 +133,5 @@ const processSourceMap = function (jsonObj) { | |
} | |
}; | |
-redisClient.on('message', (channel, message) => { | |
- console.log(`[${Date.now()}] On ${channel}: ${message}`); | |
- if (message !== 'test') { | |
- try { | |
- const obj = JSON.parse(message); | |
- setImmediate(processSourceMap, obj); | |
- } catch (err) { | |
- console.log(`[${Date.now()}] json parse error ${err}`); | |
- } | |
- } | |
-}); | |
-redisClient.subscribe(REDIS_CHANNEL); | |
console.log(`[${Date.now()}] Harriot SourceMap Worker is listening to "${REDIS_CHANNEL}" on redis`); | |
messageSlack('Ping from Harriot SourceMap Worker'); | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment