From 7af404cac7bd759edd82ca6643c86999ab5c3d5d Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Fri, 13 Jan 2017 12:46:41 -0500 Subject: [PATCH] it works --- Hashr/Dockerfile | 12 +++++++----- Worker/Dockerfile | 3 +-- Worker/Program.cs | 20 +++++++++++--------- docker-compose.yml | 31 +++++++++++++++++++++++++++++++ gen/gen.py | 1 - store/Dockerfile | 8 +++----- store/Gemfile | 2 +- store/app.rb | 3 ++- ui/Dockerfile | 6 +++--- ui/app.js | 2 +- ui/bin/www | 2 -- ui/routes/index.js | 15 +++++++-------- ui/views/index.ejs | 2 +- 13 files changed, 68 insertions(+), 39 deletions(-) create mode 100644 docker-compose.yml diff --git a/Hashr/Dockerfile b/Hashr/Dockerfile index 048dfba..57930b0 100644 --- a/Hashr/Dockerfile +++ b/Hashr/Dockerfile @@ -1,13 +1,15 @@ FROM microsoft/dotnet:latest -COPY . /app - WORKDIR /app +ADD project.json project.json + RUN ["dotnet", "restore"] -RUN ["dotnet", "build"] +ADD . . -EXPOSE 5000/tcp +RUN ["dotnet", "build", "-c", "Release"] -CMD ["dotnet", "run", "--server.urls", "http://*:5000"] +EXPOSE 80/tcp + +CMD ["dotnet", "run", "-c", "Release", "--server.urls", "http://*:80"] diff --git a/Worker/Dockerfile b/Worker/Dockerfile index be14092..73fab36 100644 --- a/Worker/Dockerfile +++ b/Worker/Dockerfile @@ -8,5 +8,4 @@ RUN dotnet restore # copy and build everything else ADD . . -RUN dotnet build -C Release -ENTRYPOINT ["dotnet", "run", "-C", "Release"] \ No newline at end of file +ENTRYPOINT ["dotnet", "run", "-c", "Release"] \ No newline at end of file diff --git a/Worker/Program.cs b/Worker/Program.cs index d215470..d43a433 100644 --- a/Worker/Program.cs +++ b/Worker/Program.cs @@ -8,6 +8,7 @@ namespace Worker { public class Program { + static Random rand = new Random(); static HttpClient httpclient = new HttpClient(); public static void Main(string[] args) { @@ -17,19 +18,20 @@ namespace Worker { while(true) { - try - { + // try + // { var bytes = await httpclient.GetByteArrayAsync("http://gen/8"); var results = await httpclient.PostAsync("http://hashr/hashme", new ByteArrayContent(bytes)); results.EnsureSuccessStatusCode(); var hashResults = await results.Content.ReadAsStringAsync(); - var dbResult = await httpclient.GetStringAsync($"http://store/store?dt={DateTime.Now.ToString()}"); - await Task.Delay(1000); - } - catch(Exception e) - { - Console.WriteLine(e.Message); - } + await httpclient.GetStringAsync($"http://store/store"); + await Task.Delay(rand.Next(100, 1000)); + // } + // catch(Exception e) + // { + // Console.WriteLine("WORKER FAILED"); + // Console.WriteLine(e.Message); + // } } } } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6877267 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,31 @@ +version: "2" + +services: + gen: + build: gen + ports: + - "8001:80" + + hashr: + build: Hashr + ports: + - "8002:80" + + ui: + build: ui + ports: + - "8000:80" + links: + - store + + store: + build: store + ports: + - "8003:80" + + worker: + build: worker + links: + - hashr + - gen + - store \ No newline at end of file diff --git a/gen/gen.py b/gen/gen.py index bc94a03..9cd2e05 100644 --- a/gen/gen.py +++ b/gen/gen.py @@ -18,7 +18,6 @@ def index(): @app.route("/") def gen(how_many_bytes): - time.sleep(0.1) return Response( os.read(urandom, how_many_bytes), content_type="application/octet-stream") diff --git a/store/Dockerfile b/store/Dockerfile index c4d3d53..78dc24e 100644 --- a/store/Dockerfile +++ b/store/Dockerfile @@ -1,9 +1,7 @@ FROM ruby:alpine RUN apk add --update build-base -RUN gem install bundle +RUN gem install sinatra RUN gem install thin -ADD Gemfile . -RUN bundle -ADD . . -CMD ["bundle", "exec", "thin", "start"] +ADD app.rb / +CMD ["ruby", "app.rb"] EXPOSE 80 \ No newline at end of file diff --git a/store/Gemfile b/store/Gemfile index 2978655..db38ea8 100644 --- a/store/Gemfile +++ b/store/Gemfile @@ -1,3 +1,3 @@ source "https://rubygems.org" gem 'sinatra' -gem 'nokogiri' \ No newline at end of file +gem 'thin' \ No newline at end of file diff --git a/store/app.rb b/store/app.rb index 515bb40..e5b2995 100644 --- a/store/app.rb +++ b/store/app.rb @@ -1,7 +1,8 @@ require 'sinatra' require 'date' require 'json' - +set :bind, '0.0.0.0' +set :port, 80 get '/' do content_type :json getData.to_json diff --git a/ui/Dockerfile b/ui/Dockerfile index 517584c..c6e9eda 100644 --- a/ui/Dockerfile +++ b/ui/Dockerfile @@ -2,9 +2,9 @@ FROM node:boron-wheezy RUN npm install -g bower ADD package.json . RUN npm install -ADD bower.json -RUN bower install +ADD bower.json bower.json +RUN bower install --allow-root ADD . . -EXPOSE 3000 +EXPOSE 80 CMD ["npm", "run", "start"] diff --git a/ui/app.js b/ui/app.js index 6ddf083..358422e 100644 --- a/ui/app.js +++ b/ui/app.js @@ -16,7 +16,7 @@ app.locals.ENV = env; app.locals.ENV_DEVELOPMENT = env == 'development'; // view engine setup - +app.set('port', process.env.PORT || 80); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); diff --git a/ui/bin/www b/ui/bin/www index f3ef100..f6fd691 100644 --- a/ui/bin/www +++ b/ui/bin/www @@ -1,8 +1,6 @@ #!/usr/bin/env node var app = require('../app'); -app.set('port', process.env.PORT || 3000); - var server = app.listen(app.get('port'), function() { console.log('Express server listening on port ' + server.address().port); }); diff --git a/ui/routes/index.js b/ui/routes/index.js index dd897e1..bcff584 100644 --- a/ui/routes/index.js +++ b/ui/routes/index.js @@ -9,14 +9,13 @@ router.get('/', function(req, res) { }); router.get('/db', (req, res)=>{ - // request('http://store/', function (error, response, body) { - // if (!error && response.statusCode == 200) { - // console.log(body) // Show the HTML for the Google homepage. - // } - // res.set('Content-Type', 'application/json'); - // return res.send(200, body); - // }) - res.json([ { date: '2017-01-01 10:01', value: 20 }, { date: '2017-01-01 11:00', value: 60 }]); + request('http://store/', function (error, response, body) { + if (!error && response.statusCode == 200) { + console.log(body) // Show the HTML for the Google homepage. + } + res.set('Content-Type', 'application/json'); + return res.send(200, body); + }); }); module.exports = router; diff --git a/ui/views/index.ejs b/ui/views/index.ejs index 3683a15..d21dc76 100644 --- a/ui/views/index.ejs +++ b/ui/views/index.ejs @@ -13,7 +13,7 @@ var data = [] var graph = new Rickshaw.Graph({ element: document.querySelector("#chart"), - renderer: 'line', + renderer: 'area', series: [{ data: data, color: 'steelblue'