Skip to content

Commit

Permalink
✨ [#4908] Add docker compose flask app
Browse files Browse the repository at this point in the history
Required for simulating a receiving service
  • Loading branch information
viktorvanwijk committed Dec 20, 2024
1 parent 3126061 commit 50e082e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docker/docker-compose.json-registration.yml
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
17 changes: 17 additions & 0 deletions docker/json-registration/Dockerfile
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"]
18 changes: 18 additions & 0 deletions docker/json-registration/README.md
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`.
20 changes: 20 additions & 0 deletions docker/json-registration/app.py
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)

0 comments on commit 50e082e

Please sign in to comment.