Skip to content

Commit 9a8a422

Browse files
author
Rob Tjalma
authored
Merge pull request #31 from com-pas/robot-test-cim
Initial Setup Robot framework + Basic Robot Tests
2 parents 44404bb + 45a61b8 commit 9a8a422

25 files changed

+5844
-125
lines changed

.github/dependabot.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-FileCopyrightText: 2021 Alliander N.V.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
version: 2
6+
7+
updates:
8+
# Maintain dependencies for GitHub Actions
9+
- package-ecosystem: "github-actions"
10+
directory: "/"
11+
schedule:
12+
interval: "daily"
13+
open-pull-requests-limit: 5
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# SPDX-FileCopyrightText: 2021 Alliander N.V.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
name: Run integration tests
6+
7+
on: push
8+
9+
jobs:
10+
integration-tests:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 30
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v1
17+
- name: Set up Docker Buildx
18+
id: buildx
19+
uses: docker/setup-buildx-action@v1
20+
- name: Cache register
21+
uses: actions/cache@v2
22+
with:
23+
path: /tmp/.buildx-cache
24+
key: ${{ runner.os }}-buildx-${{ hashFiles('**/Dockerfile') }}
25+
26+
- name: Start containers
27+
run: docker-compose -f "compas/docker-compose.yml" up -d --build
28+
env:
29+
COMPAS_HOSTNAME: compas_reverse-proxy_1
30+
- name: Wait until containers started
31+
run: sh ./bin/docker-wait-on-containers.sh
32+
33+
- name: Created output directory (firefox)
34+
run: mkdir -p target/firefox
35+
- name: Execute integration tests (firefox)
36+
# Using the Docker Image from ppodgorsek (https://github.com/ppodgorsek/docker-robot-framework)
37+
# to run the Robot Framework Test Scripts.
38+
# To connect with the Docker Compose and use http://compas_reverse-proxy_1/ as URL we are
39+
# connecting to the same network "compas_default" that's started bij Docker Compose.
40+
run: |
41+
docker run --rm -e BROWSER=firefox \
42+
-e ROBOT_OPTIONS="-v url:http://compas_reverse-proxy_1/" \
43+
-v $(pwd)/target/firefox:/opt/robotframework/reports:Z \
44+
-v $(pwd)/integration-testing:/opt/robotframework/tests:Z \
45+
--user $(id -u):$(id -g) \
46+
--network=compas_default \
47+
ppodgorsek/robot-framework:latest
48+
49+
# We need to wait for a new version of the Docker Image.
50+
# There is an issue with Chromium (https://github.com/ppodgorsek/docker-robot-framework/issues/372)
51+
# - name: Created output directory (chromium)
52+
# run: mkdir -p target/chromium
53+
# - name: Execute integration tests (chromium)
54+
# run: |
55+
# docker run --rm -e BROWSER=chromium \
56+
# -e ROBOT_OPTIONS="-v url:http://compas_reverse-proxy_1/" \
57+
# -v $(pwd)/target/firefox:/opt/robotframework/reports:Z \
58+
# -v $(pwd)/integration-testing:/opt/robotframework/tests:Z \
59+
# --user $(id -u):$(id -g) \
60+
# --network=compas_default \
61+
# ppodgorsek/robot-framework:latest
62+
63+
- name: Stop containers
64+
if: always()
65+
run: docker-compose -f "compas/docker-compose.yml" down -v

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
# Output directory
6+
target
7+
58
# IDE specific
69
.idea
710
*.iml

README.md

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,39 @@ SPDX-License-Identifier: Apache-2.0
1010
# CoMPAS Deployment Repository
1111
Containing tools / configurations for deploying CoMPAS services.
1212

13+
## Docker Compose
14+
There is a pre configured [Docker Compose](compas/docker-compose.yml) file, which starts all the given CoMPAS services.
15+
To start all configured services, go to the `compas` directory and run the following two commands:
16+
17+
```
18+
# Build (if needed) and start all the containers in the background.
19+
docker-compose up -d --build
20+
```
21+
22+
This first command builds 2 containers (keycloak and reverse proxy) and next command starts all CoMPAS services at the same time.
23+
Now, the following services are available:
24+
25+
- open-scd, available at [http://localhost/](http://localhost/).
26+
- logout, available at [http://localhost/logout](http://localhost/logout).
27+
- scl-data-service, available at [http://localhost/compas-scl-data-service](http://localhost/compas-scl-data-service).
28+
- cim-mapping - IEC 61850 mapping, available at [http://localhost/compas-cim-mapping/](http://localhost/compas-cim-mapping/).
29+
- basex, available at [http://localhost:1984/](http://localhost:1984/)
30+
- keycloak, available at [http://localhost/auth/](http://localhost/auth/) or directly if needed [http://localhost:8089/auth/](http://localhost:8089/auth/).
31+
- Imports the demo configuration.
32+
- reverse-proxy, OpenResty instance that works as a reverse proxy so all services are available through a single port.
33+
- The JWT Access Token is added to the header for all Services, like the SCL Data Service.
34+
35+
To stop and remove all the containers run the command:
36+
37+
```
38+
# Stop all containers and remove the volumes.
39+
docker-compose down -v
40+
```
41+
42+
The option '-v' also removes the volumes created, so all data is lost with this option.
43+
1344
## Keycloak Demo Configuration
14-
For demo purposes, a [demo Keycloak configuration](docker/keycloak/keycloak_compas_realm.json) is created which can be imported when
45+
For demo purposes, a [demo Keycloak configuration](compas/keycloak/keycloak_compas_realm.json) is created which can be imported when
1546
running a Keycloak instance.
1647

1748
The following Keycloak attributes have been added:
@@ -34,27 +65,39 @@ When interacting with the SCL Data Service, a JWT token needs to have certain ro
3465
- Username: scd-reader
3566
- Password: reader
3667

37-
## Docker Compose
38-
There is a pre configured [Docker Compose](docker/docker-compose.yml) file, which starts all the given CoMPAS services.
39-
To start all configured services, go to the `docker` directory and run the following two commands:
68+
## Integration Testing
4069

41-
`docker-compose build`
70+
To improve the quality of the application more beside the testing in the separate repositories we also created some integration
71+
tests to test all components together. The integration tests are executed against the Docker Compose version in this project.
4272

43-
`docker-compose up -d`
73+
We are using the [Robot Framework](https://robotframework.org/) to execute the integration tests. For the Robot Framework we are
74+
using the [Browser Library](https://github.com/MarketSquare/robotframework-browser) to do the Web testing. this Library is based
75+
on [Playwright](https://playwright.dev/). All Integration Tests and data can be found in the directory 'integration-testing'.
76+
Output can be found in the directory 'target' is below commands and Github Actions are used.
4477

45-
This first command builds 2 containers (keycloak and reverse proxy) and next command starts all CoMPAS services at the same time.
46-
Now, the following services are available:
78+
Some useful links:
79+
- [Robot Framework](https://robotframework.org/)
80+
- [Robot Framework User Guid](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html)
81+
- [Robot Framework BuildIn Keywords](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html)
82+
- [Browser Library](https://github.com/MarketSquare/robotframework-browser)
83+
- [Browser Library Keywords](https://marketsquare.github.io/robotframework-browser/Browser.html)
84+
- [Playwright](https://playwright.dev/)
85+
- [Playwright Documentation](https://playwright.dev/docs/intro/)
4786

48-
- open-scd, available at [http://localhost/](http://localhost/).
49-
- logout, available at [http://localhost/logout](http://localhost/logout).
50-
- scl-data-service, available at [http://localhost/compas-scl-data-service](http://localhost/compas-scl-data-service).
51-
- cim-mapping - IEC 61850 mapping, available at [http://localhost/compas-cim-mapping/](http://localhost/compas-cim-mapping/).
52-
- basex, available at [http://localhost:1984/](http://localhost:1984/)
53-
- keycloak, available at [http://localhost/auth/](http://localhost/auth/) or directly if needed [http://localhost:8089/auth/](http://localhost:8089/auth/).
54-
- Imports the demo configuration.
55-
- reverse-proxy, OpenResty instance that works as a reverse proxy so all services are available through a single port.
56-
- The JWT Access Token is added to the header for all Services, like the SCL Data Service.
87+
Some useful commands to execute the Robot Framework locally.
88+
Please follow the instructions of [Robot Framework](https://robotframework.org/) to install the Framework.
89+
And also follow the instruction of [Browser Library](https://github.com/MarketSquare/robotframework-browser) to install this needed library.
5790

58-
To stop and remove all the containers run the command:
91+
```
92+
# Prefer to remove the target directory before starting.
93+
rm -r target
94+
95+
# Normal run of all the test suites (with firefox, headless).
96+
robot -d target/firefox integration-testing/
97+
98+
# Run of all the test suites (with firefox in presenter mode to better follow what happens).
99+
robot -d target/firefox -v browser:firefox -v enable_presenter_mode:true -v headless:false integration-testing/
59100
60-
`docker-compose down`
101+
# Run of all the test suites (with chromium, headless), looks like chromium now only works headless. It crashs otherwise.
102+
robot -d target/chromium -v browser:chromium integration-testing/
103+
```

bin/docker-wait-on-containers.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
# Check until no more process found with filter.
4+
docker ps -a --filter label=compas
5+
6+
while [ `docker ps --filter health=starting --filter label=compas -q | wc -l` -gt 0 ]
7+
do
8+
echo "Still waiting for the containers with filter 'health=starting'."
9+
sleep 10
10+
done
11+
12+
echo "Done no containers with filter 'health=starting'."
13+
docker ps -a --filter label=compas
File renamed without changes.

compas/.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: 2021 Alliander N.V.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
COMPAS_HOSTNAME=localhost

compas/docker-compose.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# SPDX-FileCopyrightText: 2021 Alliander N.V.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
version: "3.9"
6+
7+
services:
8+
basex:
9+
labels:
10+
compas: true
11+
image: "basex/basexhttp:9.5.2"
12+
ports:
13+
- "1984:1984"
14+
volumes:
15+
- basex-data-volume:/srv/basex/data
16+
- basex-repo-volume:/srv/basex/repo
17+
- basex-webapp-volume:/srv/basex/webapp
18+
19+
keycloak:
20+
build:
21+
context: ./keycloak
22+
args:
23+
COMPAS_HOSTNAME: ${COMPAS_HOSTNAME}
24+
labels:
25+
compas: true
26+
ports:
27+
- "8089:8080"
28+
environment:
29+
- KEYCLOAK_FRONTEND_URL=http://${COMPAS_HOSTNAME}/auth/
30+
- KEYCLOAK_HOSTNAME=${COMPAS_HOSTNAME}
31+
- KEYCLOAK_HTTP_PORT=80
32+
- PROXY_ADDRESS_FORWARDING=true
33+
healthcheck:
34+
test: ["CMD", "curl", "-f", "http://localhost:8080/auth/"]
35+
interval: 30s
36+
timeout: 10s
37+
retries: 5
38+
39+
scl-data-service:
40+
labels:
41+
compas: true
42+
image: "lfenergy/compas-scl-data-service:0.8.2"
43+
environment:
44+
- BASEX_HOST=basex
45+
- BASEX_PORT=1984
46+
- JWT_VERIFY_KEY=http://keycloak:8080/auth/realms/compas/protocol/openid-connect/certs
47+
- JWT_VERIFY_ISSUER=http://${COMPAS_HOSTNAME}/auth/realms/compas
48+
- JWT_VERIFY_CLIENT_ID=scl-data-service
49+
- JWT_GROUPS_PATH=resource_access/scl-data-service/roles
50+
- USERINFO_NAME_CLAIMNAME=name
51+
- USERINFO_WHO_CLAIMNAME=name
52+
- USERINFO_SESSION_WARNING=20
53+
- USERINFO_SESSION_EXPIRES=30
54+
healthcheck:
55+
test: ["CMD", "curl", "-f", "http://localhost:8080/compas-scl-data-service/q/health/ready"]
56+
interval: 15s
57+
timeout: 10s
58+
retries: 5
59+
depends_on:
60+
- basex
61+
- keycloak
62+
63+
cim-mapping:
64+
labels:
65+
compas: true
66+
image: "lfenergy/compas-cim-mapping:0.7.4"
67+
environment:
68+
- JWT_VERIFY_KEY=http://keycloak:8080/auth/realms/compas/protocol/openid-connect/certs
69+
- JWT_VERIFY_ISSUER=http://${COMPAS_HOSTNAME}/auth/realms/compas
70+
- JWT_VERIFY_CLIENT_ID=cim-mapping
71+
- JWT_GROUPS_PATH=resource_access/cim-mapping/roles
72+
- USERINFO_WHO_CLAIMNAME=name
73+
healthcheck:
74+
test: ["CMD", "curl", "-f", "http://localhost:8080/compas-cim-mapping/q/health/ready"]
75+
interval: 15s
76+
timeout: 10s
77+
retries: 5
78+
depends_on:
79+
- keycloak
80+
81+
open-scd:
82+
labels:
83+
compas: true
84+
image: "lfenergy/compas-open-scd:v0.7.1-compas-1"
85+
healthcheck:
86+
test: ["CMD", "curl", "-f", "http://localhost/"]
87+
interval: 30s
88+
timeout: 10s
89+
retries: 5
90+
depends_on:
91+
- scl-data-service
92+
- cim-mapping
93+
94+
reverse-proxy:
95+
labels:
96+
compas: true
97+
build:
98+
context: ./reverse-proxy
99+
args:
100+
COMPAS_HOSTNAME: ${COMPAS_HOSTNAME}
101+
ports:
102+
- "80:80"
103+
healthcheck:
104+
test: ["CMD", "curl", "-f", "http://localhost/"]
105+
interval: 30s
106+
timeout: 10s
107+
retries: 5
108+
depends_on:
109+
- keycloak
110+
- scl-data-service
111+
- cim-mapping
112+
- open-scd
113+
114+
volumes:
115+
basex-data-volume:
116+
basex-repo-volume:
117+
basex-webapp-volume:

docker/keycloak/Dockerfile renamed to compas/keycloak/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
FROM jboss/keycloak:latest
66

7+
ARG COMPAS_HOSTNAME
8+
79
# Copy the demo realm configuration to /tmp/ inside the container, so it can be used afterwards
8-
COPY keycloak_compas_realm.json /tmp/keycloak_compas_realm.json
10+
COPY --chown=jboss:jboss keycloak_compas_realm.json /tmp/keycloak_compas_realm.json
11+
RUN sed -i "s/##COMPAS_HOSTNAME##/${COMPAS_HOSTNAME}/g" /tmp/keycloak_compas_realm.json
912

1013
# Creating an Admin account
1114
ENV KEYCLOAK_USER admin

0 commit comments

Comments
 (0)