Skip to content

Commit

Permalink
simple app readme next
Browse files Browse the repository at this point in the history
  • Loading branch information
ranman committed Mar 27, 2018
1 parent d3f9105 commit 50ce1f4
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 0 deletions.
8 changes: 8 additions & 0 deletions backend/Dockerfile
@@ -0,0 +1,8 @@
FROM python:3.6
WORKDIR /app
COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
COPY . /app
EXPOSE 5000
ENTRYPOINT ["python"]
CMD ["app.py"]
31 changes: 31 additions & 0 deletions backend/app.py
@@ -0,0 +1,31 @@
from flask import Flask, render_template
import socket
import requests
import boto3
app = Flask(__name__)
servicediscovery = boto3.client("servicediscovery")


@app.route("/ping")
def ping():
return "", 200


@app.route("/")
def hello():
resp = servicediscovery.list_services(
Filters=[{'Name': 'NAMESPACE_ID', 'Values': ['SUPER_COOL_VALUE_HERE']}]
)
service_obj = [service for service in resp.get('Services', []) if service['Name'] != "backend"]
services = []
for service in service_obj:
services.append({
'name': service['Name'],
'addr': socket.gethostbyname(service['Name']+".corp"),
'num_hosts': len(servicediscovery.list_instances(ServiceId=service['Id'])['Instances']),
'text': requests.get("http://"+service['Name']+".corp").content.decode("utf-8")
})
return render_template("index.html", services=services)

if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0')
3 changes: 3 additions & 0 deletions backend/requirements.txt
@@ -0,0 +1,3 @@
flask
requests
boto3
Binary file added backend/static/dust_scratches.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/static/favicon.ico
Binary file not shown.
Binary file added backend/static/sd.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions backend/templates/index.html
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<style>
body {
background: url({{ url_for('static', filename='dust_scratches.png') }}) repeat 0 0;
}
</style>
<title>Service Discovery</title>
</head>
<body>
<div class="container">
<div class="row justify-content-md-center">
<h1 class="display">Amazon ECS Service Discovery</h1>
</div>
<div>
<img src="{{url_for('static', filename='sd.png')}}" class="img-fluid" alt="architecture diagram">
</div>
<div class="row justify-content-md-center">
<div class="col">
<p>This is a short demo of service discovery in <a href="https://aws.amazon.com/ecs/">Amazon ECS</a>.</p>

<p>You can find more details in the <a href="https://aws.amazon.com/blogs/aws/amazon-ecs-service-discovery/">blog post</a>.</p>
</div>
</div>
<hr>
<div class="row justify-content-md-center">
<div class="col">
<p>These are the services I found, if you refresh the page the IPs of the workers should change:</p>
<ul>
{% for service in services %}
<li><h2>{{service.name}} - {{service.addr}}</h2><strong>Worker Response:</strong>{{service.text|safe}}
<p>Chose one out of {{service.num_hosts}} posible hosts</p>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</body>
</html>
8 changes: 8 additions & 0 deletions workers/Dockerfile
@@ -0,0 +1,8 @@
FROM python:3.6
WORKDIR /app
COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
COPY . /app
EXPOSE 80
ENTRYPOINT ["python"]
CMD ["app.py"]
10 changes: 10 additions & 0 deletions workers/app.py
@@ -0,0 +1,10 @@
from flask import Flask
import socket
app = Flask(__name__)

@app.route("/")
def do_work():
return "I'm a worker and I'm doing some work!"

if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0', port=80)
1 change: 1 addition & 0 deletions workers/requirements.txt
@@ -0,0 +1 @@
flask

0 comments on commit 50ce1f4

Please sign in to comment.