Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 7548fa2

Browse files
Merge pull request #684 from ndeloof/build-sample
Demonstrate docker app build using dockercoins sample app
2 parents cf8ec17 + c47d4b3 commit 7548fa2

File tree

19 files changed

+368
-0
lines changed

19 files changed

+368
-0
lines changed

examples/dockercoins/LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2015 Jérôme Petazzoni
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

examples/dockercoins/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# dockercoins
2+
3+
This is the demo application originally used in Jérôme Petazzoni's [orchestration workshop](https://github.com/jpetazzo/container.training).
4+
5+
[Kubernetes Hands-on Workshop](https://training.play-with-kubernetes.com/kubernetes-workshop/)
6+
```
7+
rng = web service generating random bytes
8+
hasher = web service computing hash of POSTed data
9+
worker = background process using rng and hasher
10+
webui = web interface to watch progress
11+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: "3.7"
2+
3+
services:
4+
rng:
5+
build: rng
6+
ports:
7+
- "${rng.port}:80"
8+
9+
hasher:
10+
build: hasher
11+
ports:
12+
- "${hasher.port}:80"
13+
14+
webui:
15+
build: webui
16+
ports:
17+
- "${webui.port}:80"
18+
19+
redis:
20+
image: redis
21+
22+
worker:
23+
build: worker
24+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Version of the application
2+
version: 0.1.0
3+
# Name of the application
4+
name: coins
5+
# A short description of the application
6+
description:
7+
# List of application maintainers with name and email for each
8+
maintainers:
9+
- name: Jérôme Petazzoni
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
webui:
2+
port: 8000
3+
rng:
4+
port: 8001
5+
hasher:
6+
port: 8002
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM ruby:alpine
2+
RUN apk add --update build-base curl
3+
RUN gem install sinatra
4+
RUN gem install thin
5+
ADD hasher.rb /
6+
CMD ["ruby", "hasher.rb"]
7+
EXPOSE 80
8+
HEALTHCHECK \
9+
--interval=1s --timeout=2s --retries=3 --start-period=1s \
10+
CMD curl http://localhost/ || exit 1

examples/dockercoins/hasher/hasher.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require 'digest'
2+
require 'sinatra'
3+
require 'socket'
4+
5+
set :bind, '0.0.0.0'
6+
set :port, 80
7+
8+
post '/' do
9+
# Simulate a bit of delay
10+
sleep 0.1
11+
content_type 'text/plain'
12+
"#{Digest::SHA2.new().update(request.body.read)}"
13+
end
14+
15+
get '/' do
16+
"HASHER running on #{Socket.gethostname}\n"
17+
end
18+

examples/dockercoins/rng/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM python:alpine
2+
RUN pip install Flask
3+
COPY rng.py /
4+
CMD ["python", "rng.py"]
5+
EXPOSE 80

examples/dockercoins/rng/rng.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from flask import Flask, Response
2+
import os
3+
import socket
4+
import time
5+
6+
app = Flask(__name__)
7+
8+
# Enable debugging if the DEBUG environment variable is set and starts with Y
9+
app.debug = os.environ.get("DEBUG", "").lower().startswith('y')
10+
11+
hostname = socket.gethostname()
12+
13+
urandom = os.open("/dev/urandom", os.O_RDONLY)
14+
15+
16+
@app.route("/")
17+
def index():
18+
return "RNG running on {}\n".format(hostname)
19+
20+
21+
@app.route("/<int:how_many_bytes>")
22+
def rng(how_many_bytes):
23+
# Simulate a little bit of delay
24+
time.sleep(0.1)
25+
return Response(
26+
os.read(urandom, how_many_bytes),
27+
content_type="application/octet-stream")
28+
29+
30+
if __name__ == "__main__":
31+
app.run(host="0.0.0.0", port=80)
32+

examples/dockercoins/webui/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM node:4-slim
2+
RUN npm install express
3+
RUN npm install redis
4+
COPY files/ /files/
5+
COPY webui.js /
6+
CMD ["node", "webui.js"]
7+
EXPOSE 80

0 commit comments

Comments
 (0)