Created
March 28, 2019 13:20
-
-
Save kdjomeda/19aabb2095fc2fd52e992ebd117baa2b to your computer and use it in GitHub Desktop.
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
###docker-compose | |
version: '3' | |
services: | |
redis: | |
image: "redis:alpine" | |
networks: | |
- envoymesh | |
proxy: | |
build: | |
context: . | |
dockerfile: Dockerfile-envoy | |
ports: | |
- "8080:80" | |
- "8001:8001" | |
expose: | |
- "80" | |
- "8001" | |
volumes: | |
- ./front-envoy.yaml:/etc/front-envoy.yaml | |
networks: | |
- envoymesh | |
flaskweb: | |
build: | |
context: . | |
dockerfile: Dockerfile-flask | |
volumes: | |
- .:/code | |
ports: | |
- "5000:5000" | |
expose: | |
- "5000" | |
depends_on: | |
- redis | |
networks: | |
envoymesh: | |
aliases: | |
- flaskservice | |
networks: | |
envoymesh: {} | |
################################################################################################################ | |
###front-envoy.yaml | |
static_resources: | |
listeners: | |
- address: | |
socket_address: | |
address: 0.0.0.0 | |
port_value: 80 | |
filter_chains: | |
- filters: | |
- name: envoy.http_connection_manager | |
config: | |
# "@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager | |
codec_type: auto | |
stat_prefix: ingress_http | |
route_config: | |
name: local_route | |
virtual_hosts: | |
- name: flask_backend | |
domains: | |
- "*" | |
routes: | |
- match: | |
prefix: "/flask/home" | |
route: | |
cluster: flask | |
http_filters: | |
- name: envoy.router | |
typed_config: {} | |
clusters: | |
- name: flask | |
connect_timeout: 0.25s | |
type: strict_dns | |
lb_policy: round_robin | |
http2_protocol_options: {} | |
load_assignment: | |
cluster_name: flaskcluster | |
endpoints: | |
- lb_endpoints: | |
- endpoint: | |
address: | |
socket_address: | |
address: flaskservice | |
port_value: 5000 | |
admin: | |
access_log_path: "/dev/null" | |
address: | |
socket_address: | |
address: 0.0.0.0 | |
port_value: 8001 | |
### Dockerfile-envoy | |
FROM envoyproxy/envoy:latest | |
RUN apt-get update && apt-get -q install -y \ | |
curl | |
CMD /usr/local/bin/envoy -c /etc/front-envoy.yaml --service-cluster front-proxy | |
################################################################################################################ | |
###Dockerfile-flask | |
FROM python:3.4-alpine | |
ADD . /code | |
WORKDIR /code | |
RUN pip install -r requirements.txt | |
CMD ["python", "app.py"] | |
################################################################################################################ | |
### requirements.txt | |
flask | |
redis | |
################################################################################################################ | |
### app.py | |
import time | |
import redis | |
from flask import Flask | |
app = Flask(__name__) | |
cache = redis.Redis(host='redis', port=6379) | |
def get_hit_count(): | |
retries = 5 | |
while True: | |
try: | |
return cache.incr('hits') | |
except redis.exceptions.ConnectionError as exc: | |
if retries == 0: | |
raise exc | |
retries -= 1 | |
time.sleep(0.5) | |
@app.route('/') | |
def hello(): | |
count = get_hit_count() | |
return 'Hello from Docker! I have been seen {} times.\n'.format(count) | |
if __name__ == "__main__": | |
app.run(host="0.0.0.0", debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment