Skip to content

Commit

Permalink
DS-566: Created test for image and fixed image
Browse files Browse the repository at this point in the history
  • Loading branch information
tedgin committed Mar 29, 2024
1 parent 196fced commit ebc3e6f
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
- name: build base image
run: "${{ github.repository }}/build"

- name: build test image
run: docker buildx build "${{ github.repository }}"/test-artifacts
- name: test base image
run: "${{ github.repository }}/test"

- name: log into Docker Hub
if: ${{ github.ref_name == 'main' }}
Expand Down
16 changes: 8 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ FROM ubuntu:22.04

### Update installed packages to latest version
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get --quiet update && \
apt-get --quiet --yes install apt-utils 2>&1 && \
apt-get --quiet --yes upgrade && \
RUN apt-get update && \
apt-get --yes install apt-utils 2>&1 && \
apt-get --yes upgrade && \
#
### Install dumb-init
apt-get --quiet --yes install dumb-init && \
apt-get --yes install dumb-init && \
apt-get clean && \
#
### Install iRODS server
Expand All @@ -19,14 +19,14 @@ RUN apt-get --quiet update && \
COPY apt.irods /etc/apt/preferences.d/irods
ADD --chmod=444 \
https://packages.irods.org/irods-signing-key.asc /etc/apt/trusted.gpg.d/irods-signing-key.asc
RUN apt-get --quiet --yes install ca-certificates gnupg lsb-release && \
RUN apt-get --yes install ca-certificates gnupg lsb-release && \
echo deb [arch=amd64] https://packages.irods.org/apt/ "$(lsb_release --codename --short)" main \
> /etc/apt/sources.list.d/renci-irods.list && \
apt-get --quiet update && \
apt-get --quiet --yes install irods-server && \
apt-get update && \
apt-get --yes install irods-server && \
#
### Install iRODS management script dependencies
apt-get --quiet --yes install jq && \
apt-get --yes install jq && \
apt-get clean && \
#
### Initialize server
Expand Down
8 changes: 2 additions & 6 deletions build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
#
# Usage:
# build [options]
# build
#
# This program builds the cyverse/irods image tagged with `new`.

Expand All @@ -10,8 +10,4 @@ set -o errexit -o nounset -o pipefail
BASE_DIR="$(dirname "$(realpath --canonicalize-existing "$0")")"
readonly BASE_DIR

main() {
docker build --tag cyverse/irods:new "$BASE_DIR"
}

main "$@"
docker buildx build --tag cyverse/irods:new "$BASE_DIR"
51 changes: 31 additions & 20 deletions run-irods.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

set -o errexit -o nounset -o pipefail

declare PERIPHERY_EXEC
declare PERIPHERY_EXEC PERIPHERY_AFTER_STOP_CALLED

declare TailPid

Expand All @@ -48,17 +48,10 @@ main() {
return 1
fi

if am_provider; then
printf 'Catalog Service Provider Instance\n'
start_server
init_clerver_session localhost
else
printf 'Catalog Service Consumer Instance\n'
init_clerver_session "$(wait_for_provider)"
start_server
fi
start_server

trap stop_server SIGTERM
trap 'call_periphery after_stop' EXIT

printf 'Ready\n'

Expand All @@ -75,24 +68,28 @@ configured() {
[[ -e /etc/irods/server_config.json ]] && [[ -e /var/lib/irods/.irods/irods_environment.json ]]
}

init_clerver_session() {
local provider="$1"

IRODS_HOST="$provider" iinit <<< "$IRODS_CLERVER_PASSWORD" > /dev/null
}

start_server() {
call_periphery before_start
printf 'Starting iRODS\n'
/var/lib/irods/irodsctl start

if am_provider; then
printf 'Catalog Service Provider Instance\n'
/var/lib/irods/irodsctl start
init_clerver_session "$(hostname)"
else
printf 'Catalog Service Consumer Instance\n'
init_clerver_session "$(wait_for_provider)"
/var/lib/irods/irodsctl start
fi

call_periphery after_start
}

stop_server() {
call_periphery before_stop
call_periphery before_stop || true
printf 'Stopping iRODS\n'
/var/lib/irods/irodsctl stop
call_periphery after_stop
/var/lib/irods/irodsctl stop || true
call_periphery after_stop || true

if [[ -n "${TailPid-}" ]]; then
if kill "$TailPid" 2> /dev/null; then
Expand All @@ -104,6 +101,14 @@ stop_server() {
call_periphery() {
local cmd="$1"

if [[ "$cmd" == after_stop ]]; then
if [[ -n "${PERIPHERY_AFTER_STOP_CALLED-}" ]]; then
return
else
readonly PERIPHERY_AFTER_STOP_CALLED=called
fi
fi

if [[ -n "${PERIPHERY_EXEC-}" ]]; then
eval "$PERIPHERY_EXEC" "$cmd"
fi
Expand All @@ -113,6 +118,12 @@ am_provider() {
[[ "$(query_server_config .plugin_configuration.database)" != null ]]
}

init_clerver_session() {
local provider="$1"

IRODS_HOST="$provider" iinit <<< "$IRODS_CLERVER_PASSWORD" > /dev/null
}

wait_for_provider() {
local zonePort
zonePort="$(query_server_config .zone_port)"
Expand Down
80 changes: 80 additions & 0 deletions test
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env bash
#
# Usage:
# test
#
# This program tests the cyverse/irods base image by creating an image based on
# it and verifying that iRODS is working on that image.

set -o errexit -o nounset

BASE_DIR="$(dirname "$(realpath --canonicalize-existing "$0")")"
readonly BASE_DIR

declare -rA PROG_MSGS=(
[before_start]='Resolving host name'
[after_start]='after_start received'
[before_stop]='before_stop received'
[after_stop]='Stopping PostgreSQL'
)

main() {
docker buildx build --tag test-image "$BASE_DIR"/test-artifacts
docker run --rm --name test-container test-image | test_container
printf 'PASSED\n'
}

test_container() {
local msgLine

verify_start_msg before_start
verify_start_msg after_start

while read -r msgLine; do
if [[ "$msgLine" == Ready ]]; then
break
fi
done

if [[ "$(docker exec test-container ./irodsctl status)" =~ 'No iRODS server running' ]]; then
printf 'iRODS failed to start\n' >&2
exit 1
fi

docker stop test-container > /dev/null

verify_stop_msg before_stop
verify_stop_msg after_stop
}

verify_start_msg() {
local state="$1"

local msgLine
while read -r msgLine; do
if [[ "$msgLine" == "${PROG_MSGS["$state"]}" ]]; then
break
fi

if [[ "$msgLine" == Ready ]]; then
printf '%s not triggered\n' "$state" >&2
exit 1
fi
done
}

verify_stop_msg() {
local state="$1"

local msgLine
while read -r msgLine; do
if [[ "$msgLine" == "${PROG_MSGS["$state"]}" ]]; then
return
fi
done

printf '%s not triggered\n' "$state" >&2
exit 1
}

main "$@"
14 changes: 9 additions & 5 deletions test-artifacts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ ARG DEBIAN_FRONTEND=noninteractive

RUN --mount=target=/tmp/unattended_installation.json,source=unattended_installation.json \
### Installed required packages
apt-get --quiet update && \
apt-get --quiet --yes upgrade && \
apt-get --quiet --yes install \
irods-database-plugin-postgres postgresql postgresql-contrib python-is-python3 && \
apt-get update && \
apt-get --yes upgrade && \
apt-get --yes install \
irods-database-plugin-postgres moreutils postgresql postgresql-contrib python-is-python3 && \
apt-get clean && \
### Initialize server
echo 'irods ALL=(postgres) NOPASSWD: ALL' > /etc/sudoers.d/irods && \
Expand All @@ -22,8 +22,12 @@ RUN --mount=target=/tmp/unattended_installation.json,source=unattended_installat
sudo --user=postgres psql --command="CREATE USER irods WITH PASSWORD 'testpassword'" && \
sudo --user=postgres psql --command='CREATE DATABASE "ICAT"' && \
sudo --user=postgres psql --command='GRANT ALL PRIVILEGES ON DATABASE "ICAT" TO irods' && \
jq '.service_account_environment.irods_host |= "'"$(hostname)"'"' \
/tmp/unattended_installation.json \
> /tmp/resolved_installation.json && \
python /var/lib/irods/scripts/setup_irods.py --verbose \
--json_configuration_file=/tmp/unattended_installation.json && \
--json_configuration_file=/tmp/resolved_installation.json && \
rm --force /tmp/resolved_installation.json && \
sudo --login --user=postgres \
/usr/lib/postgresql/14/bin/pg_ctl --pgdata=/var/lib/postgresql/14/main stop

Expand Down
19 changes: 19 additions & 0 deletions test-artifacts/control-dbms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ set -o errexit -o nounset -o pipefail
main() {
case "$1" in
before_start)
resolve_irods_host
start_dbms
;;
after_start)
printf 'after_start received\n'
;;
before_stop)
printf 'before_stop received\n'
;;
after_stop)
stop_dbms
;;
Expand All @@ -15,6 +22,18 @@ main() {
esac
}

resolve_irods_host() {
printf 'Resolving host name\n'

local host
host="$(hostname)"

jq '.irods_host |= "'"$host"'"' /var/lib/irods/.irods/irods_environment.json \
| sponge /var/lib/irods/.irods/irods_environment.json

indent /dev/stdout < /var/lib/irods/.irods/irods_environment.json
}

start_dbms() {
printf 'Starting PostgreSQL\n'

Expand Down
12 changes: 9 additions & 3 deletions test-artifacts/unattended_installation.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@
},
"server_config": {
"advanced_settings": {
"agent_factory_watcher_sleep_time_in_seconds": 5,
"default_number_of_transfer_threads": 4,
"default_temporary_password_lifetime_in_seconds": 120,
"delay_rule_executors": [],
"delay_server_sleep_time_in_seconds": 30,
"dns_cache": {
"cache_clearer_sleep_time_in_seconds": 600,
"eviction_age_in_seconds": 3600,
"shared_memory_size_in_bytes": 5000000
},
"host_name_cache": {
"cache_clearer_sleep_time_in_seconds": 600,
"eviction_age_in_seconds": 3600,
"shared_memory_size_in_bytes": 2500000
},
"maximum_size_for_single_buffer_in_megabytes": 32,
"maximum_size_of_delay_queue_in_bytes": 0,
"maximum_temporary_password_lifetime_in_seconds": 1000,
"migrate_delay_server_sleep_time_in_seconds": 5,
"number_of_concurrent_delay_rule_executors": 4,
"stacktrace_file_processor_sleep_time_in_seconds": 10,
"transfer_buffer_size_for_parallel_transfer_in_megabytes": 4,
"transfer_chunk_size_for_parallel_transfer_in_megabytes": 40
Expand Down Expand Up @@ -57,7 +62,8 @@
"network": "info",
"resource": "info",
"rule_engine": "info",
"server": "info"
"server": "info",
"sql": "info"
},
"match_hash_policy": "compatible",
"negotiation_key": "TEMPORARY_32byte_negotiation_key",
Expand Down Expand Up @@ -134,7 +140,7 @@
"irods_encryption_num_hash_rounds": 16,
"irods_encryption_salt_size": 8,
"irods_home": "/tempZone/home/rods",
"irods_host": "localhost",
"irods_host": "_UNKNOWN_",
"irods_match_hash_policy": "compatible",
"irods_maximum_size_for_single_buffer_in_megabytes": 32,
"irods_port": 1247,
Expand All @@ -146,6 +152,6 @@
"irods_user_name": "rods",
"irods_zone_name": "tempZone",
"schema_name": "service_account_environment",
"schema_version": "v3"
"schema_version": "v4"
}
}

0 comments on commit ebc3e6f

Please sign in to comment.