Skip to content

Commit 7b4197c

Browse files
authored
Merge pull request #15 from aarranz/feature/read-only-configuration-file
Allow to use custom configuration files
2 parents b0601a8 + 4114299 commit 7b4197c

6 files changed

Lines changed: 244 additions & 10 deletions

File tree

1.2/docker-compose-config-file.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
version: "3"
2+
3+
services:
4+
5+
nginx:
6+
restart: always
7+
image: nginx:latest
8+
ports:
9+
- 80:80
10+
volumes:
11+
- ./nginx.conf:/etc/nginx/nginx.conf:ro
12+
- ./wirecloud-static:/var/www/static:ro
13+
depends_on:
14+
- wirecloud
15+
16+
17+
postgres:
18+
restart: always
19+
image: postgres:latest
20+
environment:
21+
- POSTGRES_PASSWORD=wirepass # Change this password!
22+
volumes:
23+
- ./postgres-data:/var/lib/postgresql/data
24+
25+
26+
elasticsearch:
27+
restart: always
28+
image: elasticsearch:2.4
29+
volumes:
30+
- ./elasticsearch-data:/usr/share/elasticsearch/data
31+
command: elasticsearch -Des.index.max_result_window=50000
32+
33+
34+
memcached:
35+
restart: always
36+
image: memcached:1
37+
command: memcached -m 2048m
38+
39+
40+
wirecloud:
41+
restart: always
42+
image: fiware/wirecloud:1.2
43+
depends_on:
44+
- postgres
45+
- elasticsearch
46+
- memcached
47+
environment:
48+
- DEBUG=False
49+
# - DEFAULT_THEME=wirecloud.defaulttheme
50+
- DB_HOST=postgres
51+
- DB_PASSWORD=wirepass # Change this password!
52+
- FORWARDED_ALLOW_IPS=*
53+
- ELASTICSEARCH2_URL=http://elasticsearch:9200/
54+
- MEMCACHED_LOCATION=memcached:11211
55+
# Uncomment the following environment variables to enable IDM integration
56+
#- FIWARE_IDM_SERVER=${FIWARE_IDM_SERVER}
57+
#- SOCIAL_AUTH_FIWARE_KEY=${SOCIAL_AUTH_FIWARE_KEY}
58+
#- SOCIAL_AUTH_FIWARE_SECRET=${SOCIAL_AUTH_FIWARE_SECRET}
59+
volumes:
60+
- ./wirecloud-data:/opt/wirecloud_instance/data
61+
- ./wirecloud-static:/var/www/static
62+
- ./settings.py:/opt/wirecloud_instance/wirecloud_instance/settings.py:ro

1.2/docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44

55
# allow the container to be started with `--user`
66
if [ "$(id -u)" = '0' ]; then
7-
chown -R wirecloud .
7+
chown -R wirecloud data
88
chown -R wirecloud /var/www/static
99
fi
1010

1.2/tests.py

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,30 @@
1212
import requests
1313
import sh
1414

15+
POLL_FREQUENCY = 0.5 # How long to sleep inbetween calls to the method
16+
17+
18+
class TimeoutException(Exception):
19+
"""
20+
Thrown when a command does not complete in enough time.
21+
"""
22+
pass
23+
24+
25+
def wait_until_running(timeout=120):
26+
end_time = time.time() + timeout
27+
while True:
28+
try:
29+
response = requests.get("http://localhost/api/version")
30+
if response.status_code != 502:
31+
return
32+
except requests.exceptions.ConnectionError:
33+
pass
34+
time.sleep(POLL_FREQUENCY)
35+
if time.time() > end_time:
36+
break
37+
raise TimeoutException()
38+
1539

1640
class WireCloudTests(object):
1741

@@ -48,11 +72,12 @@ class StandaloneTests(unittest.TestCase, WireCloudTests):
4872

4973
@classmethod
5074
def setUpClass(cls):
75+
print("\n################################################################################\n")
5176
print("#")
5277
print("# Initializing standalone test case")
5378
print("#\n")
5479
sh.docker_compose("-f", "docker-compose-standalone.yml", "up", d=True, remove_orphans=True, _fg=True)
55-
time.sleep(30)
80+
wait_until_running()
5681
print()
5782

5883
@classmethod
@@ -71,11 +96,12 @@ class SimpleTests(unittest.TestCase, WireCloudTests):
7196

7297
@classmethod
7398
def setUpClass(cls):
99+
print("\n################################################################################\n")
74100
print("#")
75101
print("# Initializing simple test case")
76102
print("#\n")
77103
sh.docker_compose("-f", "docker-compose-simple.yml", "up", d=True, remove_orphans=True, _fg=True)
78-
time.sleep(30)
104+
wait_until_running()
79105
print()
80106

81107
@classmethod
@@ -94,11 +120,39 @@ class ComposedTests(unittest.TestCase, WireCloudTests):
94120

95121
@classmethod
96122
def setUpClass(cls):
123+
print("\n################################################################################\n")
97124
print("#")
98125
print("# Initializing composed test case")
99126
print("#\n")
100127
sh.docker_compose.up(d=True, remove_orphans=True, _fg=True)
101-
time.sleep(30)
128+
wait_until_running()
129+
print()
130+
131+
@classmethod
132+
def tearDownClass(cls):
133+
print()
134+
print("#")
135+
print("# Removing containers and volumes")
136+
print("#\n")
137+
sh.docker_compose.down(remove_orphans=True, v=True, _fg=True)
138+
shutil.rmtree('wirecloud-data')
139+
shutil.rmtree('wirecloud-static')
140+
shutil.rmtree('elasticsearch-data')
141+
shutil.rmtree('postgres-data')
142+
print()
143+
144+
145+
class ReadOnlyConfigTests(unittest.TestCase, WireCloudTests):
146+
147+
@classmethod
148+
def setUpClass(cls):
149+
print("\n################################################################################\n")
150+
print("#")
151+
print("# Initializing read-only config test case")
152+
print("#\n")
153+
154+
sh.docker_compose("-f", "docker-compose-config-file.yml", "up", d=True, remove_orphans=True, _fg=True)
155+
wait_until_running()
102156
print()
103157

104158
@classmethod
@@ -119,6 +173,7 @@ class IDMTests(unittest.TestCase, WireCloudTests):
119173

120174
@classmethod
121175
def setUpClass(cls):
176+
print("\n################################################################################\n")
122177
print("#")
123178
print("# Initializing idm test case")
124179
print("#\n")
@@ -129,7 +184,7 @@ def setUpClass(cls):
129184
env["SOCIAL_AUTH_FIWARE_KEY"] = "wirecloud_test_client_id"
130185
env["SOCIAL_AUTH_FIWARE_SECRET"] = "notused"
131186
sh.docker_compose("-f", "docker-compose-idm.yml", "up", d=True, remove_orphans=True, _env=env, _fg=True)
132-
time.sleep(45)
187+
wait_until_running()
133188
print()
134189

135190
@classmethod

dev/docker-compose-config-file.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
version: "3"
2+
3+
services:
4+
5+
nginx:
6+
restart: always
7+
image: nginx:latest
8+
ports:
9+
- 80:80
10+
volumes:
11+
- ./nginx.conf:/etc/nginx/nginx.conf:ro
12+
- ./wirecloud-static:/var/www/static:ro
13+
depends_on:
14+
- wirecloud
15+
16+
17+
postgres:
18+
restart: always
19+
image: postgres:latest
20+
environment:
21+
- POSTGRES_PASSWORD=wirepass # Change this password!
22+
volumes:
23+
- ./postgres-data:/var/lib/postgresql/data
24+
25+
26+
elasticsearch:
27+
restart: always
28+
image: elasticsearch:2.4
29+
volumes:
30+
- ./elasticsearch-data:/usr/share/elasticsearch/data
31+
command: elasticsearch -Des.index.max_result_window=50000
32+
33+
34+
memcached:
35+
restart: always
36+
image: memcached:1
37+
command: memcached -m 2048m
38+
39+
40+
wirecloud:
41+
restart: always
42+
image: fiware/wirecloud:dev
43+
depends_on:
44+
- postgres
45+
- elasticsearch
46+
- memcached
47+
environment:
48+
- DEBUG=False
49+
# - DEFAULT_THEME=wirecloud.defaulttheme
50+
- DB_HOST=postgres
51+
- DB_PASSWORD=wirepass # Change this password!
52+
- FORWARDED_ALLOW_IPS=*
53+
- ELASTICSEARCH2_URL=http://elasticsearch:9200/
54+
- MEMCACHED_LOCATION=memcached:11211
55+
# Uncomment the following environment variables to enable IDM integration
56+
#- FIWARE_IDM_SERVER=${FIWARE_IDM_SERVER}
57+
#- SOCIAL_AUTH_FIWARE_KEY=${SOCIAL_AUTH_FIWARE_KEY}
58+
#- SOCIAL_AUTH_FIWARE_SECRET=${SOCIAL_AUTH_FIWARE_SECRET}
59+
volumes:
60+
- ./wirecloud-data:/opt/wirecloud_instance/data
61+
- ./wirecloud-static:/var/www/static
62+
- ./settings.py:/opt/wirecloud_instance/wirecloud_instance/settings.py:ro

dev/docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44

55
# allow the container to be started with `--user`
66
if [ "$(id -u)" = '0' ]; then
7-
chown -R wirecloud .
7+
chown -R wirecloud data
88
chown -R wirecloud /var/www/static
99
fi
1010

dev/tests.py

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,30 @@
1212
import requests
1313
import sh
1414

15+
POLL_FREQUENCY = 0.5 # How long to sleep inbetween calls to the method
16+
17+
18+
class TimeoutException(Exception):
19+
"""
20+
Thrown when a command does not complete in enough time.
21+
"""
22+
pass
23+
24+
25+
def wait_until_running(timeout=120):
26+
end_time = time.time() + timeout
27+
while True:
28+
try:
29+
response = requests.get("http://localhost/api/version")
30+
if response.status_code != 502:
31+
return
32+
except requests.exceptions.ConnectionError:
33+
pass
34+
time.sleep(POLL_FREQUENCY)
35+
if time.time() > end_time:
36+
break
37+
raise TimeoutException()
38+
1539

1640
class WireCloudTests(object):
1741

@@ -48,11 +72,12 @@ class StandaloneTests(unittest.TestCase, WireCloudTests):
4872

4973
@classmethod
5074
def setUpClass(cls):
75+
print("\n################################################################################\n")
5176
print("#")
5277
print("# Initializing standalone test case")
5378
print("#\n")
5479
sh.docker_compose("-f", "docker-compose-standalone.yml", "up", d=True, remove_orphans=True, _fg=True)
55-
time.sleep(40)
80+
wait_until_running()
5681
print()
5782

5883
@classmethod
@@ -71,11 +96,12 @@ class SimpleTests(unittest.TestCase, WireCloudTests):
7196

7297
@classmethod
7398
def setUpClass(cls):
99+
print("\n################################################################################\n")
74100
print("#")
75101
print("# Initializing simple test case")
76102
print("#\n")
77103
sh.docker_compose("-f", "docker-compose-simple.yml", "up", d=True, remove_orphans=True, _fg=True)
78-
time.sleep(40)
104+
wait_until_running()
79105
print()
80106

81107
@classmethod
@@ -94,11 +120,39 @@ class ComposedTests(unittest.TestCase, WireCloudTests):
94120

95121
@classmethod
96122
def setUpClass(cls):
123+
print("\n################################################################################\n")
97124
print("#")
98125
print("# Initializing composed test case")
99126
print("#\n")
100127
sh.docker_compose.up(d=True, remove_orphans=True, _fg=True)
101-
time.sleep(40)
128+
wait_until_running()
129+
print()
130+
131+
@classmethod
132+
def tearDownClass(cls):
133+
print()
134+
print("#")
135+
print("# Removing containers and volumes")
136+
print("#\n")
137+
sh.docker_compose.down(remove_orphans=True, v=True, _fg=True)
138+
shutil.rmtree('wirecloud-data')
139+
shutil.rmtree('wirecloud-static')
140+
shutil.rmtree('elasticsearch-data')
141+
shutil.rmtree('postgres-data')
142+
print()
143+
144+
145+
class ReadOnlyConfigTests(unittest.TestCase, WireCloudTests):
146+
147+
@classmethod
148+
def setUpClass(cls):
149+
print("\n################################################################################\n")
150+
print("#")
151+
print("# Initializing read-only config test case")
152+
print("#\n")
153+
154+
sh.docker_compose("-f", "docker-compose-config-file.yml", "up", d=True, remove_orphans=True, _fg=True)
155+
wait_until_running()
102156
print()
103157

104158
@classmethod
@@ -119,6 +173,7 @@ class IDMTests(unittest.TestCase, WireCloudTests):
119173

120174
@classmethod
121175
def setUpClass(cls):
176+
print("\n################################################################################\n")
122177
print("#")
123178
print("# Initializing idm test case")
124179
print("#\n")
@@ -129,7 +184,7 @@ def setUpClass(cls):
129184
env["SOCIAL_AUTH_FIWARE_KEY"] = "wirecloud_test_client_id"
130185
env["SOCIAL_AUTH_FIWARE_SECRET"] = "notused"
131186
sh.docker_compose("-f", "docker-compose-idm.yml", "up", d=True, remove_orphans=True, _env=env, _fg=True)
132-
time.sleep(45)
187+
wait_until_running()
133188
print()
134189

135190
@classmethod

0 commit comments

Comments
 (0)