-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
stack_orchestrator/data/container-build/cerc-test-database-client/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM ubuntu:latest | ||
|
||
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && export DEBCONF_NOWARNINGS="yes" && \ | ||
apt-get install -y software-properties-common && \ | ||
apt-get install -y postgresql-client && \ | ||
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
|
||
EXPOSE 80 | ||
|
||
COPY run.sh /app/run.sh | ||
|
||
ENTRYPOINT ["/app/run.sh"] |
5 changes: 5 additions & 0 deletions
5
stack_orchestrator/data/container-build/cerc-test-database-client/build.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
# Build cerc/test-container | ||
source ${CERC_CONTAINER_BASE_DIR}/build-base.sh | ||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
docker build -t cerc/test-database-client:local -f ${SCRIPT_DIR}/Dockerfile ${build_command_args} $SCRIPT_DIR |
42 changes: 42 additions & 0 deletions
42
stack_orchestrator/data/container-build/cerc-test-database-client/run.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
if [ -n "$CERC_SCRIPT_DEBUG" ]; then | ||
set -x | ||
fi | ||
|
||
# TODO derive this from config | ||
database_url="postgresql://test-user:password@localhost:5432/test-db" | ||
psql_command="psql ${database_url}" | ||
|
||
does_test_data_exist () { | ||
query_result=$(${psql_command} -t -c "select count(*) from test_table_1 where key_column = 'test_key_1';" | head -1 | tr -d ' ') | ||
if [[ "${query_result}" == "1" ]]; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
create_test_data () { | ||
${psql_command} -c "create table test_table_1 (key_column text, value_column text, primary key(key_column));" | ||
${psql_command} -c "insert into test_table_1 values ('test_key_1', 'test_value_1');" | ||
} | ||
|
||
wait_forever() { | ||
# Loop to keep docker/k8s happy since this is the container entrypoint | ||
while :; do sleep 600; done | ||
} | ||
|
||
# Check if the test database content exists already | ||
if does_test_data_exist; then | ||
# If so, log saying so. Test harness will look for this log output | ||
echo "Database test client: test data already exists" | ||
else | ||
# Otherwise log saying the content was not present | ||
echo "Database test client: test data does not exist" | ||
echo "Database test client: creating test data" | ||
# then create it | ||
create_test_data | ||
fi | ||
|
||
wait_forever |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters