Skip to content

Commit ca2dd32

Browse files
author
Rob Tjalma
authored
Merge pull request #37 from com-pas/postgresql-docker-compose
Added PostgreSQL version of Docker Compose and Testing Github Action.
2 parents 5f2cb87 + 594844a commit ca2dd32

File tree

6 files changed

+272
-13
lines changed

6 files changed

+272
-13
lines changed

.github/workflows/run-integration-tests.yml renamed to .github/workflows/run-integration-tests-basex.yml

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

5-
name: Run integration tests
5+
name: Run integration tests (BaseX)
66

77
on:
88
push:
@@ -31,7 +31,7 @@ jobs:
3131
key: ${{ runner.os }}-buildx-${{ hashFiles('**/Dockerfile') }}
3232

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

README.md

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ 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:
13+
## Docker Compose (BaseX)
14+
There is a pre configured [Docker Compose](compas/docker-compose-basex.yml) file, which starts all the given CoMPAS services.
15+
To start all configured services using BaseX, run the following two commands:
1616

1717
```
1818
# Build (if needed) and start all the containers in the background.
19-
docker-compose up -d --build
19+
docker-compose -f compas/docker-compose-basex.yml up -d --build
2020
```
2121

22-
This first command builds 2 containers (keycloak and reverse proxy) and next command starts all CoMPAS services at the same time.
22+
This command will first build the custom images for Keycloak and the Reverse Proxy and then start all containers.
23+
To know if all containers are running execute the shell script "bin/docker-wait-on-containers.sh".
24+
This script will wait until all containers are running.
25+
2326
Now, the following services are available:
2427

2528
- open-scd, available at [http://localhost/](http://localhost/).
@@ -36,16 +39,42 @@ To stop and remove all the containers run the command:
3639

3740
```
3841
# Stop all containers and remove the volumes.
39-
docker-compose down -v
42+
docker-compose -f compas/docker-compose-basex.yml down -v
43+
```
44+
45+
The option '-v' also removes the volumes created, so all data is lost with this option.
46+
47+
## Docker Compose (PostgreSQL)
48+
There is a pre configured [Docker Compose](compas/docker-compose-postgresql.yml) file, which starts all the given CoMPAS services.
49+
To start all configured services using PostgreSQL, run the following two commands:
50+
51+
```
52+
# Build (if needed) and start all the containers in the background.
53+
docker-compose -f compas/docker-compose-postgresql.yml up -d --build
54+
```
55+
56+
This command will first build the custom images for Keycloak and the Reverse Proxy and then start all containers.
57+
To know if all containers are running execute the shell script "bin/docker-wait-on-containers.sh".
58+
This script will wait until all containers are running.
59+
60+
The URLs are the same as for the BaseX version, except of course the BaseX Container. This is now a PostgreSQL
61+
container. The PostgreSQL container is available at port 5432.
62+
63+
To stop and remove all the containers run the command:
64+
65+
```
66+
# Stop all containers and remove the volumes.
67+
docker-compose -f compas/docker-compose-postgresql.yml down -v
4068
```
4169

4270
The option '-v' also removes the volumes created, so all data is lost with this option.
4371

4472
### Known issue with Docker Compose
4573

46-
Using the current configuration with Keycloak and OpenResty (lua-resty-session) sometimes gives an error "**state from argument does not match state restored from session**".
74+
Using the current configuration with Keycloak and OpenResty (lua-resty-session) sometimes gives an error
75+
"**state from argument does not match state restored from session**".
4776
This mostly happens after using logout or the session is expired. The login page is shown, but after login this error is shown.
48-
Just open the url [http://localhost/](http://localhost/) again and OpenSCD is shown again also being logged in.
77+
Just open the url [http://localhost/](http://localhost/) again and OpenSCD is shown again, also being logged in.
4978

5079
## Keycloak Demo Configuration
5180
For demo purposes, a [demo Keycloak configuration](compas/keycloak/keycloak_compas_realm.json) is created which can be imported when
@@ -56,7 +85,8 @@ The following Keycloak attributes have been added:
5685
- **OpenSCD client**: A client has been made for interacting with OpenSCD.
5786
- **SCL Data Service client**: A client has been made for interacting with the SCL Data Service.
5887
- **CRUD roles for the SCL Data Service**: Create, Read, Update and Delete roles have been added to the SCL Data Service client.
59-
When interacting with the SCL Data Service, a JWT token needs to have certain roles before interaction is possible. These roles are assigned to certain users (see below).
88+
When interacting with the SCL Data Service, a JWT token needs to have certain roles before interaction is possible.
89+
These roles are assigned to certain users (see below).
6090
- **CoMPAS Group**: A CoMPAS demo group has been added.
6191
- **A Demo User**: A Demo user without specific roles.
6292
- Username: 'user'

bin/docker-wait-on-containers.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ while [ `docker ps --filter health=starting --filter label=compas -q | wc -l` -g
77
do
88
echo "Still waiting for the containers with filter 'health=starting'."
99
sleep 10
10+
docker ps -a --filter label=compas
1011
done
1112

1213
echo "Done no containers with filter 'health=starting'."

compas/docker-compose.yml renamed to compas/docker-compose-basex.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ services:
3939
scl-data-service:
4040
labels:
4141
compas: true
42-
image: "lfenergy/compas-scl-data-service:0.8.3"
42+
image: "lfenergy/compas-scl-data-service:0.9.0-basex"
4343
environment:
4444
- BASEX_HOST=basex
4545
- BASEX_PORT=1984
@@ -51,6 +51,12 @@ services:
5151
- USERINFO_WHO_CLAIMNAME=name
5252
- USERINFO_SESSION_WARNING=20
5353
- USERINFO_SESSION_EXPIRES=30
54+
deploy:
55+
restart_policy:
56+
condition: on-failure
57+
delay: 5s
58+
max_attempts: 3
59+
window: 30s
5460
healthcheck:
5561
test: ["CMD", "curl", "-f", "http://localhost:8080/compas-scl-data-service/q/health/ready"]
5662
interval: 15s
@@ -70,6 +76,12 @@ services:
7076
- JWT_VERIFY_CLIENT_ID=cim-mapping
7177
- JWT_GROUPS_PATH=resource_access/cim-mapping/roles
7278
- USERINFO_WHO_CLAIMNAME=name
79+
deploy:
80+
restart_policy:
81+
condition: on-failure
82+
delay: 5s
83+
max_attempts: 3
84+
window: 30s
7385
healthcheck:
7486
test: ["CMD", "curl", "-f", "http://localhost:8080/compas-cim-mapping/q/health/ready"]
7587
interval: 15s
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# SPDX-FileCopyrightText: 2021 Alliander N.V.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
version: "3.9"
6+
7+
services:
8+
postgresql:
9+
labels:
10+
compas: true
11+
image: "postgres:latest"
12+
ports:
13+
- "5432:5432"
14+
environment:
15+
- POSTGRES_PASSWORD=postgres
16+
- POSTGRES_DB=compas
17+
- PGDATA=/var/lib/postgresql/data/compas
18+
healthcheck:
19+
test: ["CMD-SHELL", "pg_isready -U postgres"]
20+
interval: 15s
21+
timeout: 10s
22+
retries: 5
23+
volumes:
24+
- postgresql-data-volume:/var/lib/postgresql/data
25+
26+
keycloak:
27+
build:
28+
context: ./keycloak
29+
args:
30+
COMPAS_HOSTNAME: ${COMPAS_HOSTNAME}
31+
labels:
32+
compas: true
33+
ports:
34+
- "8089:8080"
35+
environment:
36+
- KEYCLOAK_FRONTEND_URL=http://${COMPAS_HOSTNAME}/auth/
37+
- KEYCLOAK_HOSTNAME=${COMPAS_HOSTNAME}
38+
- KEYCLOAK_HTTP_PORT=80
39+
- PROXY_ADDRESS_FORWARDING=true
40+
healthcheck:
41+
test: ["CMD", "curl", "-f", "http://localhost:8080/auth/"]
42+
interval: 30s
43+
timeout: 10s
44+
retries: 5
45+
46+
scl-data-service:
47+
labels:
48+
compas: true
49+
image: "lfenergy/compas-scl-data-service:0.9.0-postgresql"
50+
environment:
51+
- POSTGRESQL_HOST=postgresql
52+
- POSTGRESQL_DB=compas
53+
- JWT_VERIFY_KEY=http://keycloak:8080/auth/realms/compas/protocol/openid-connect/certs
54+
- JWT_VERIFY_ISSUER=http://${COMPAS_HOSTNAME}/auth/realms/compas
55+
- JWT_VERIFY_CLIENT_ID=scl-data-service
56+
- JWT_GROUPS_PATH=resource_access/scl-data-service/roles
57+
- USERINFO_NAME_CLAIMNAME=name
58+
- USERINFO_WHO_CLAIMNAME=name
59+
- USERINFO_SESSION_WARNING=20
60+
- USERINFO_SESSION_EXPIRES=30
61+
deploy:
62+
restart_policy:
63+
condition: on-failure
64+
delay: 5s
65+
max_attempts: 3
66+
window: 30s
67+
healthcheck:
68+
test: ["CMD", "curl", "-f", "http://localhost:8080/compas-scl-data-service/q/health/ready"]
69+
interval: 15s
70+
timeout: 10s
71+
retries: 5
72+
depends_on:
73+
- postgresql
74+
- keycloak
75+
76+
cim-mapping:
77+
labels:
78+
compas: true
79+
image: "lfenergy/compas-cim-mapping:0.7.6"
80+
environment:
81+
- JWT_VERIFY_KEY=http://keycloak:8080/auth/realms/compas/protocol/openid-connect/certs
82+
- JWT_VERIFY_ISSUER=http://${COMPAS_HOSTNAME}/auth/realms/compas
83+
- JWT_VERIFY_CLIENT_ID=cim-mapping
84+
- JWT_GROUPS_PATH=resource_access/cim-mapping/roles
85+
- USERINFO_WHO_CLAIMNAME=name
86+
deploy:
87+
restart_policy:
88+
condition: on-failure
89+
delay: 5s
90+
max_attempts: 3
91+
window: 30s
92+
healthcheck:
93+
test: ["CMD", "curl", "-f", "http://localhost:8080/compas-cim-mapping/q/health/ready"]
94+
interval: 15s
95+
timeout: 10s
96+
retries: 5
97+
depends_on:
98+
- keycloak
99+
100+
open-scd:
101+
labels:
102+
compas: true
103+
image: "lfenergy/compas-open-scd:v0.7.1-compas-4"
104+
healthcheck:
105+
test: ["CMD", "curl", "-f", "http://localhost/"]
106+
interval: 30s
107+
timeout: 10s
108+
retries: 5
109+
depends_on:
110+
- scl-data-service
111+
- cim-mapping
112+
113+
reverse-proxy:
114+
labels:
115+
compas: true
116+
build:
117+
context: ./reverse-proxy
118+
args:
119+
COMPAS_HOSTNAME: ${COMPAS_HOSTNAME}
120+
ports:
121+
- "80:80"
122+
healthcheck:
123+
test: ["CMD", "curl", "-f", "http://localhost/"]
124+
interval: 30s
125+
timeout: 10s
126+
retries: 5
127+
depends_on:
128+
- keycloak
129+
- scl-data-service
130+
- cim-mapping
131+
- open-scd
132+
133+
volumes:
134+
postgresql-data-volume:

0 commit comments

Comments
 (0)