Skip to content

Commit 1a165f4

Browse files
committed
add precondition checks for missing volumes
1 parent 7d07bdd commit 1a165f4

4 files changed

Lines changed: 71 additions & 2 deletions

File tree

src/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ENV TEMPORARY_CERT_NAME=solid-temporary
1111

1212
WORKDIR ${SOLID_HOME}
1313
COPY ./src/entrypoint.sh ./entrypoint.sh
14+
COPY ./src/checks.sh ./checks.sh
1415
COPY ./src/create-temporary-cert.sh ./create-temporary-cert.sh
1516
RUN chown --recursive ${PROCESS_USER}:${PROCESS_USER} ${SOLID_HOME}
1617

@@ -27,4 +28,4 @@ VOLUME $SOLID_HOME
2728

2829
ENTRYPOINT ["./entrypoint.sh"]
2930

30-
CMD ["start"]
31+
CMD ["start"]

src/checks.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
checks_failed=0
4+
5+
check_failed()
6+
{
7+
checks_failed=$((checks_failed + 1))
8+
}
9+
check_dir_exists()
10+
{
11+
dir=$1
12+
if [ -f "${dir}" ]; then
13+
echo "${dir} exists"
14+
else
15+
echo "${dir} missing"
16+
check_failed
17+
fi
18+
}
19+
20+
check_dir_exists "${SOLID_HOME}/data"
21+
check_dir_exists "${SOLID_HOME}/.db"
22+
check_dir_exists "${SOLID_HOME}/config"
23+
24+
if [ "$checks_failed" -gt 0 ]; then
25+
echo "Finished: ERROR"
26+
exit 1
27+
fi

src/entrypoint.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
set -e
44

5+
./checks.sh
6+
57
./create-temporary-cert.sh ${TEMPORARY_CERT_NAME}
68

7-
solid "$@"
9+
solid "$@"

test/test_precondition_checks.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# coding=utf-8
2+
import docker
3+
import pytest
4+
import time
5+
6+
testinfra_hosts = ['docker://test_container']
7+
8+
9+
@pytest.fixture(scope="module", autouse=True)
10+
def container(client, image):
11+
container = client.containers.run(
12+
image.id,
13+
name="test_container",
14+
volumes={
15+
'missing_data': {'bind': '/opt/solid/data'},
16+
'missing_db': {'bind': '/opt/solid/.db'},
17+
'missing_config': {'bind': '/opt/solid/config'}
18+
},
19+
environment=[
20+
"SOLID_SERVER_KEY=/missing/key",
21+
"SOLID_SERVER_CERT=/missing/cert"
22+
],
23+
detach=True,
24+
tty=True
25+
)
26+
# give the solid process some seconds to create the directory structure before making assertions
27+
time.sleep(2)
28+
yield container
29+
container.remove(force=True)
30+
31+
32+
def test_container_fails_with_errors(container):
33+
assert container.status == "created"
34+
logs = container.logs()
35+
assert "✗ /opt/solid/data missing" in logs
36+
assert "✗ /opt/solid/.db missing" in logs
37+
assert "✗ /opt/solid/config missing" in logs
38+
assert "Finished: ERROR" in logs
39+
assert not "Finished: SUCCESS" in logs

0 commit comments

Comments
 (0)