From e8c55d717e413bf5b772aff367a1256b3c98d81e Mon Sep 17 00:00:00 2001 From: picard-remi Date: Sat, 13 Jan 2024 21:23:32 +0100 Subject: [PATCH 1/2] #21 Add examples --- README.md | 18 +++++++++--------- RobotFrameworkService/Config.py | 2 +- {tasks => examples/tasks}/anothertask.robot | 2 +- {tasks => examples/tasks}/demotask.robot | 2 +- {tasks => examples/tasks}/evenmore.robot | 0 examples/tests/demotest.robot | 7 +++++++ examples/variables/variables.py | 1 + examples/variables/variables2.py | 1 + 8 files changed, 21 insertions(+), 12 deletions(-) rename {tasks => examples/tasks}/anothertask.robot (69%) rename {tasks => examples/tasks}/demotask.robot (75%) rename {tasks => examples/tasks}/evenmore.robot (100%) create mode 100644 examples/tests/demotest.robot create mode 100644 examples/variables/variables.py create mode 100644 examples/variables/variables2.py diff --git a/README.md b/README.md index 78a2a96..b767e5b 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ # Robot Task Webservice -A web service managing Robot Framework tasks. +A web service managing Robot Framework tasks/tests. # Goal -This web service shall start Robot Framework tasks and return and cache the according reports. +This web service shall start Robot Framework tasks/tests and return and cache the according reports. # Installation and Execution *Default docker image does not support variable files, yet* @@ -23,7 +23,7 @@ docker run -v :/robot/tests --env SUITE_FOLDER=tes ## Podman Almost as Docker, but you might need to attach the webservice to the host network: ``` -podman run --network host -v ./tasks:/robot/tasks --env SUITE_FOLDER=tasks rf-webservice:latest +podman run --network host -v ./examples:/robot/tasks --env SUITE_FOLDER=tasks rf-webservice:latest ``` ## Local @@ -43,13 +43,13 @@ There are 2 types of endpoints: 2. Reporting ## Execution -Endpoints that trigger execution of a robot task, for instance: +Endpoints that trigger execution of a robot task/test, for instance: -Call robot task: +Call robot task/test: http://localhost:5003/robotframework/run/mytask -Call robot task with variables: +Call robot task/test with variables: http://localhost:5003/robotframework/run/mytask?myVariable1=42&anotherVariable=Mustermann @@ -58,7 +58,7 @@ Response contains a header field `x-request-id` that can be used to retrieve log There are endpoints for synchronous and asynchronous request: ``` -# connection remains open for duration of my task +# connection remains open for duration of my task/test http://localhost:5003/robotframework/run/mytask # connection closes immediately - result must be requested with the x-request-id @@ -107,8 +107,8 @@ Swagger-UI is available under `http://localhost:5003/docs` # Demo-Tasks -This project contains some tasks for demonstration. They are located in ``tasks`` folder. You may add -your own task suites in that directory, if you like. +This project contains some tasks, tests and variables for demonstration. They are located in ``examples`` folder. You may add +your own task/test suites in that directory, if you like. # Task name with spaces in URL diff --git a/RobotFrameworkService/Config.py b/RobotFrameworkService/Config.py index 8ed5c30..45344bf 100644 --- a/RobotFrameworkService/Config.py +++ b/RobotFrameworkService/Config.py @@ -1,6 +1,6 @@ class Config: class Default: - taskfolder = "tasks" + taskfolder = "examples" variablefiles = None debugfile = None diff --git a/tasks/anothertask.robot b/examples/tasks/anothertask.robot similarity index 69% rename from tasks/anothertask.robot rename to examples/tasks/anothertask.robot index 22fe1e1..7b4cb56 100644 --- a/tasks/anothertask.robot +++ b/examples/tasks/anothertask.robot @@ -1,3 +1,3 @@ -*** Task *** +*** Tasks *** Another task Log ABCDEFG diff --git a/tasks/demotask.robot b/examples/tasks/demotask.robot similarity index 75% rename from tasks/demotask.robot rename to examples/tasks/demotask.robot index ec76b66..5930ecd 100644 --- a/tasks/demotask.robot +++ b/examples/tasks/demotask.robot @@ -1,3 +1,3 @@ -*** Task *** +*** Tasks *** Demonstration Task Log Hello World! diff --git a/tasks/evenmore.robot b/examples/tasks/evenmore.robot similarity index 100% rename from tasks/evenmore.robot rename to examples/tasks/evenmore.robot diff --git a/examples/tests/demotest.robot b/examples/tests/demotest.robot new file mode 100644 index 0000000..1577c02 --- /dev/null +++ b/examples/tests/demotest.robot @@ -0,0 +1,7 @@ +*** Variables *** +${hello} Hello +${who} John Doe + +*** Test Cases *** +Demonstration Test + Log ${hello} ${who} diff --git a/examples/variables/variables.py b/examples/variables/variables.py new file mode 100644 index 0000000..049e005 --- /dev/null +++ b/examples/variables/variables.py @@ -0,0 +1 @@ +hello = "Hi" diff --git a/examples/variables/variables2.py b/examples/variables/variables2.py new file mode 100644 index 0000000..21bfc22 --- /dev/null +++ b/examples/variables/variables2.py @@ -0,0 +1 @@ +who = "World!" From 88be073326774903b1866819ad226a6eca13ed92 Mon Sep 17 00:00:00 2001 From: picard-remi Date: Sat, 13 Jan 2024 21:22:58 +0100 Subject: [PATCH 2/2] #21 Integate variablefiles in docker image --- Dockerfile | 5 ++++- README.md | 16 ++++++++++++---- docker-entrypoint.sh | 9 +++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 0a18201..5714033 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM python:3.11 ENV SUITE_FOLDER . +ENV VARIABLE_FILES "" ENV PORT 5003 WORKDIR robot @@ -10,4 +11,6 @@ RUN pip install robotframework-webservice EXPOSE ${PORT} -ENTRYPOINT exec python -m RobotFrameworkService.main -p ${PORT} -t ${SUITE_FOLDER} \ No newline at end of file +COPY docker-entrypoint.sh entrypoint.sh +RUN chmod +x entrypoint.sh +ENTRYPOINT ["/robot/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index b767e5b..9e58a89 100644 --- a/README.md +++ b/README.md @@ -9,15 +9,23 @@ A web service managing Robot Framework tasks/tests. This web service shall start Robot Framework tasks/tests and return and cache the according reports. # Installation and Execution -*Default docker image does not support variable files, yet* ## Docker +You can run the image and map your test cases into the webservice with a volume : ``` -docker pull ghcr.io/marketsquare/robotframework-webservice:master +docker run --rm --publish 5003:5003 \ + --volume :/robot/tests \ + --env SUITE_FOLDER=tests \ + ghcr.io/marketsquare/robotframework-webservice:master ``` -After that you can run the image and map your test cases in to the webservice with a volumen: +You can also run the image and map your test cases and your variable files (separated by spaces) into the webservice with volumes : ``` -docker run -v :/robot/tests --env SUITE_FOLDER=tests rf-webservice:latest +docker run --rm --publish 5003:5003 \ + --volume :/robot/tests \ + --volume :/robot/variables \ + --env SUITE_FOLDER=tests \ + --env "VARIABLE_FILES=variables/variables.py variables/variables2.py" \ + ghcr.io/marketsquare/robotframework-webservice:master ``` ## Podman diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..645c469 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +if [ -n "${VARIABLE_FILES}" ]; then + variablefiles="--variablefiles ${VARIABLE_FILES}" +else + variablefiles="" +fi + +exec python -m RobotFrameworkService.main --port "${PORT}" --taskfolder "${SUITE_FOLDER}" ${variablefiles} \ No newline at end of file