Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 921e2b4

Browse files
committedJun 19, 2024
refactor: Updated to most recent versions and production use
1 parent 1501b35 commit 921e2b4

File tree

4 files changed

+27
-53
lines changed

4 files changed

+27
-53
lines changed
 

‎Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
FROM python:alpine3.6
1+
FROM python:alpine
22

33
COPY application.py /
4-
RUN pip install flask==0.10.1
4+
RUN pip install flask waitress
55

66
ENTRYPOINT ["python"]
77
CMD ["-u", "application.py"]

‎README.md

+2-40
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,6 @@
11
# Hello World of Cumulocity IoT Microservices
22

3-
Cumulocity IoT microservice example developed using Python and Docker.
4-
5-
### Prerequisites
6-
7-
* Local Docker installation
8-
* An account on [cumulocity.com](https://cumulocity.com). Create a free trial to test this example.
9-
10-
### Build
11-
12-
Execute the following commands to build the Docker image and save it as *image.tar*:
13-
14-
```shell
15-
$ docker build -t python-microservice .
16-
$ docker save python-microservice > "image.tar"
17-
```
18-
19-
Then pack *image.tar* together with the manifest *cumulocity.json* into a ZIP file.
20-
21-
```shell
22-
$ zip python-microservice cumulocity.json image.tar
23-
```
24-
25-
The resulting *python-microservice.zip* file contains the microservice and it is ready to be uploaded to the Cumulocity IoT platform.
26-
27-
### Deployment
28-
29-
Deploy the microservice application (refer to [Adding own applications](https://cumulocity.com/guides/users-guide/administration/#a-name-adding-applications-a-adding-own-applications) in the Cumulocity IoT's User guide) and subscribe it afterwards.
30-
31-
It may take some minutes for the ZIP file to be uploaded. Once completed, the three endpoints of the microservice application can be tested.
32-
33-
### Execution
34-
35-
Use a web browser or a terminal command (e.g. cURL) to make a GET request to the microservice endpoints providing your user credentials.
36-
37-
```http
38-
GET /service/python-microservice/environment
39-
Host: <TENANT_DOMAIN>
40-
Authorization: <AUTHORIZATION>
41-
```
3+
Cumulocity IoT microservice example developed using Python and Docker. For documentation and more information on running the example, please visit the [Cumulocity documentation](https://cumulocity.com/docs/microservice-sdk/http/#python-microservice).
424

435
______________________
44-
These tools are provided as-is and without warranty or support. They do not constitute part of the Software AG product suite. Users are free to use, fork and modify them, subject to the license agreement. While Software AG welcomes contributions, we cannot guarantee to include every contribution in the master project.
6+
These tools are provided as-is and without warranty or support. They do not constitute part of the Software AG product suite. Users are free to use, fork and modify them, subject to the license agreement. While Software AG welcomes contributions, we cannot guarantee to include every contribution in the master project.

‎application.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ def environment():
2828
return jsonify(environment_data)
2929

3030
if __name__ == '__main__':
31-
app.run(host='0.0.0.0', port=80)
31+
import logging
32+
logging.basicConfig(level=logging.INFO)
33+
from waitress import serve
34+
serve(app, host="0.0.0.0", port=80)

‎cumulocity.json

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
{
2-
"apiVersion": "1",
3-
"version": "1.0.0",
4-
"provider": {
5-
"name": "Cumulocity GmbH"
6-
},
7-
"isolation": "MULTI_TENANT",
8-
"requiredRoles": [
9-
],
10-
"roles": [
11-
]
2+
"apiVersion": "2",
3+
"version": "1.0.0",
4+
"provider": {
5+
"name": "Cumulocity"
6+
},
7+
"isolation": "MULTI_TENANT",
8+
"replicas": 2,
9+
"livenessProbe": {
10+
"httpGet": {
11+
"path": "/health"
12+
}
13+
},
14+
"readinessProbe": {
15+
"httpGet": {
16+
"path": "/health"
17+
}
18+
},
19+
"requiredRoles": [],
20+
"roles": []
1221
}

0 commit comments

Comments
 (0)
Please sign in to comment.