Skip to content

Commit

Permalink
Se agrega proyecto dockercoins
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosnils committed Feb 24, 2019
0 parents commit 11cfb2f
Show file tree
Hide file tree
Showing 17 changed files with 405 additions and 0 deletions.
30 changes: 30 additions & 0 deletions dockercoins/docker-compose.images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "2"

services:
rng:
build: rng
image: ${REGISTRY_SLASH}rng${COLON_TAG}
ports:
- "8001:80"

hasher:
build: hasher
image: ${REGISTRY_SLASH}hasher${COLON_TAG}
ports:
- "8002:80"

webui:
build: webui
image: ${REGISTRY_SLASH}webui${COLON_TAG}
ports:
- "8000:80"
volumes:
- "./webui/files/:/files/"

redis:
image: redis

worker:
build: worker
image: ${REGISTRY_SLASH}worker${COLON_TAG}

47 changes: 47 additions & 0 deletions dockercoins/docker-compose.logging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: "2"

services:

rng:
build: rng
ports:
- "8001:80"
logging:
driver: gelf
options:
gelf-address: udp://localhost:12201

hasher:
build: hasher
ports:
- "8002:80"
logging:
driver: gelf
options:
gelf-address: udp://localhost:12201

webui:
build: webui
ports:
- "8000:80"
volumes:
- "./webui/files/:/files/"
logging:
driver: gelf
options:
gelf-address: udp://localhost:12201

redis:
image: redis
logging:
driver: gelf
options:
gelf-address: udp://localhost:12201

worker:
build: worker
logging:
driver: gelf
options:
gelf-address: udp://localhost:12201

26 changes: 26 additions & 0 deletions dockercoins/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: "2"

services:
rng:
build: rng
ports:
- "8001:80"

hasher:
build: hasher
ports:
- "8002:80"

webui:
build: webui
ports:
- "8000:80"
volumes:
- "./webui/files/:/files/"

redis:
image: redis

worker:
build: worker

7 changes: 7 additions & 0 deletions dockercoins/hasher/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM ruby:alpine
RUN apk add --update build-base curl
RUN gem install sinatra
RUN gem install thin
ADD hasher.rb /
CMD ["ruby", "hasher.rb"]
EXPOSE 80
18 changes: 18 additions & 0 deletions dockercoins/hasher/hasher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'digest'
require 'sinatra'
require 'socket'

set :bind, '0.0.0.0'
set :port, 80

post '/' do
# Simulate a bit of delay
sleep 0.1
content_type 'text/plain'
"#{Digest::SHA2.new().update(request.body.read)}"
end

get '/' do
"HASHER running on #{Socket.gethostname}\n"
end

5 changes: 5 additions & 0 deletions dockercoins/rng/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM python:alpine
RUN pip install Flask
COPY rng.py /
CMD ["python", "rng.py"]
EXPOSE 80
32 changes: 32 additions & 0 deletions dockercoins/rng/rng.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from flask import Flask, Response
import os
import socket
import time

app = Flask(__name__)

# Enable debugging if the DEBUG environment variable is set and starts with Y
app.debug = os.environ.get("DEBUG", "").lower().startswith('y')

hostname = socket.gethostname()

urandom = os.open("/dev/urandom", os.O_RDONLY)


@app.route("/")
def index():
return "RNG running on {}\n".format(hostname)


@app.route("/<int:how_many_bytes>")
def rng(how_many_bytes):
# Simulate a little bit of delay
time.sleep(0.1)
return Response(
os.read(urandom, how_many_bytes),
content_type="application/octet-stream")


if __name__ == "__main__":
app.run(host="0.0.0.0", port=80, threaded=False)

7 changes: 7 additions & 0 deletions dockercoins/webui/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:4-slim
RUN npm install express
RUN npm install redis
COPY files/ /files/
COPY webui.js /
CMD ["node", "webui.js"]
EXPOSE 80
5 changes: 5 additions & 0 deletions dockercoins/webui/files/d3.min.js

Large diffs are not rendered by default.

111 changes: 111 additions & 0 deletions dockercoins/webui/files/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<!doctype html>
<html>
<head>
<title>DockerCoin Miner WebUI</title>
<link rel="stylesheet" type="text/css" href="rickshaw.min.css">
<style>
#graph {
background-color: #eee;
width: 800px;
height: 400px;
}
#tweet {
color: royalblue;
}
</style>
<script src="jquery.js"></script>
<script src="d3.min.js"></script>
<script src="rickshaw.min.js"></script>
<script>

String.prototype.format = function () {
var args = arguments;
return this.replace(/\{(\d+)\}/g, function (m, n) { return args[n]; });
};

var series = [];
var points = []
var graph = null;

function refresh () {
$.ajax({ url: "json" }).done(function (data) {
series.push(data);
while (series.length < 250) {
data = JSON.parse(JSON.stringify(data));
data.now -= 1;
series.unshift(data);
}
while (series.length > 250) {
series.shift();
}
while (points.length > 0) {
points.pop();
}
var speed;
for (var i=0; i<series.length-1; i++) {
// Compute instantaneous speed
var s1 = series[i];
var s2 = series[i+1];
speed = (s2.hashes-s1.hashes)/(s2.now-s1.now);
points.push({ x: s2.now, y: speed });
}
$("#speed").text("~" + speed.toFixed(1) + " hashes/second");
var msg = ("I'm attending a @docker orchestration workshop, "
+ "and my #DockerCoins mining rig is crunching "
+ speed.toFixed(1) + " hashes/second! W00T!");
$("#tweet").attr(
"href",
"https://twitter.com/intent/tweet?text="+encodeURIComponent(msg)
);
if (graph == null) {
graph = new Rickshaw.Graph({
renderer: "area",
stroke: true,
width: 800,
height: 400,
element: $("#graph")[0],
preserve: true,
series: [
{ name: "Coins",
color: "steelblue",
data: points
}
]
});
graph.render();
var yAxis = new Rickshaw.Graph.Axis.Y({
graph: graph,
tickFormat: Rickshaw.Fixtures.Number.formatKMBT,
ticksTreatment: "glow"
});
yAxis.render();
} else {
graph.update();
$("text").css({
"font-size": "15px",
"font-weight": "normal",
"opacity": 0.5,
});
}
});
}

$(function () {
setInterval(refresh, 1000);
});
</script>
</head>
<body>

<h1>DockerCoin Miner WebUI</h1>

<div id="graph"></div>

<h2>
Current mining speed:
<span id="speed">-</span>
<a id="tweet" href="#">(Tweet this!)</a>
</h2>

</body>
</html>
5 changes: 5 additions & 0 deletions dockercoins/webui/files/jquery-1.11.3.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dockercoins/webui/files/jquery.js
1 change: 1 addition & 0 deletions dockercoins/webui/files/rickshaw.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions dockercoins/webui/files/rickshaw.min.js

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions dockercoins/webui/webui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var express = require('express');
var app = express();
var redis = require('redis');

var client = redis.createClient(6379, 'redis');
client.on("error", function (err) {
console.error("Redis error", err);
});

app.get('/', function (req, res) {
res.redirect('/index.html');
});

app.get('/json', function (req, res) {
client.hlen('wallet', function (err, coins) {
client.get('hashes', function (err, hashes) {
var now = Date.now() / 1000;
res.json( {
coins: coins,
hashes: hashes,
now: now
});
});
});
});

app.use(express.static('files'));

var server = app.listen(80, function () {
console.log('WEBUI running on port 80');
});

5 changes: 5 additions & 0 deletions dockercoins/worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM python:alpine
RUN pip install redis
RUN pip install requests
COPY worker.py /
CMD ["python", "worker.py"]
Loading

0 comments on commit 11cfb2f

Please sign in to comment.