Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
flask | ||
requests | ||
boto3 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
flask |