-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [#4908] Add docker compose flask app
Required for simulating a receiving service
- Loading branch information
1 parent
3126061
commit 50e082e
Showing
4 changed files
with
70 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,15 @@ | ||
version: '3.8' | ||
|
||
name: json-registration | ||
|
||
services: | ||
flask_app: | ||
build: ./json-registration | ||
ports: | ||
- "80:80" | ||
volumes: | ||
- ./json-registration/:/app/ | ||
|
||
networks: | ||
open-forms-dev: | ||
name: open-forms-dev |
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,17 @@ | ||
# Use the official Python image from the Docker Hub | ||
FROM python:3.12-slim | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Copy the current directory contents into the container at /app | ||
COPY . /app | ||
|
||
# Install the dependencies | ||
RUN pip install Flask | ||
|
||
# Make port 80 available to the world outside this container | ||
EXPOSE 80 | ||
|
||
# Run app.py when the container launches | ||
CMD ["python", "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,18 @@ | ||
# JSON registration plugin | ||
|
||
The `docker-compose.json-registration.yml` compose file is available to run a mock service intended | ||
to simulate a receiving server to test the JSON registration backend plugin. It contains an endpoint for | ||
sending json data (`json_plugin`) and testing the connection (`test_connection`). | ||
|
||
The `json_plugin` endpoint returns a confirmation message that the data was received, together with the | ||
received data. The `test_connection` endpoint just returns an 'OK' message. | ||
|
||
## docker compose | ||
|
||
Start an instance in your local environment from the project root: | ||
|
||
```bash | ||
docker compose -f docker/docker-compose.json-registration.yml up -d | ||
``` | ||
|
||
This starts a flask application at http://localhost:80/ with the endpoints `json_plugin` and `test_connection`. |
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,20 @@ | ||
from flask import Flask, jsonify, request | ||
|
||
|
||
app = Flask(__name__) | ||
|
||
@app.route("/json_plugin", methods=["POST"]) | ||
def json_plugin_post(): | ||
data = request.get_json() | ||
|
||
message = "No data" if data is None else "Data received" | ||
return jsonify({"message": message, "data": data}), 201 | ||
|
||
|
||
@app.route("/test_connection", methods=["GET"]) | ||
def test_connection(): | ||
return jsonify({"message": "OK"}), 200 | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(host="0.0.0.0", port=80, debug=True) |