Skip to content

Commit 42fc26e

Browse files
committed
initial commit
1 parent 7327292 commit 42fc26e

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: '3'
2+
3+
services:
4+
product-service:
5+
build: ./product-service
6+
volumes:
7+
- ./product-service:/usr/src/app
8+
ports:
9+
- 5001:80
10+
11+
website:
12+
image: php:apache
13+
volumes:
14+
- ./webapp:/var/www/html
15+
ports:
16+
- 5000:80
17+
depends_on:
18+
- product-service

product-service/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM python:3
2+
WORKDIR /usr/src/app
3+
COPY requirements.txt ./
4+
RUN pip install --no-cache-dir -r requirements.txt
5+
COPY . .
6+
CMD ["python", "api.py"]

product-service/api.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Product Service API
2+
3+
from flask import Flask
4+
from flask_restful import Resource, Api
5+
6+
app = Flask(__name__)
7+
api = Api(app)
8+
9+
class Product(Resource):
10+
def get(self):
11+
return {
12+
'products': [
13+
'Ice cream',
14+
'Chocolate',
15+
'Fruits'
16+
]
17+
}
18+
19+
api.add_resource(Product, '/')
20+
21+
if __name__ == '__main__':
22+
app.run(host='0.0.0.0', port=80, debug=True)

product-service/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Flask==0.12
2+
flask-restful==0.3.5

webapp/index.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<html>
2+
<head>
3+
<title>My Shop</title>
4+
</head>
5+
<body>
6+
<h1>Welcome</h1>
7+
<ul>
8+
<?php
9+
$json = file_get_contents('http://product-service');
10+
$obj = json_decode($json);
11+
$products = $obj->products;
12+
foreach($products as $product) {
13+
echo "<li>$product</li>";
14+
}
15+
?>
16+
</ul>
17+
</body>
18+
</html>

0 commit comments

Comments
 (0)