-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #210 from kjsanger/feature/tests-in-docker
Add simplified Docker Compose support for tests
- Loading branch information
Showing
12 changed files
with
211 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
FROM ghcr.io/wtsi-npg/ub-18.04-baton-irods-4.2.11:latest | ||
|
||
ARG PYTHON_VERSION=3.12 | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
USER root | ||
|
||
RUN apt-get update && \ | ||
apt-get install -q -y --no-install-recommends \ | ||
apt-transport-https \ | ||
apt-utils \ | ||
build-essential \ | ||
ca-certificates \ | ||
curl \ | ||
gcc \ | ||
git \ | ||
make \ | ||
libbz2-dev \ | ||
libncurses-dev \ | ||
libreadline-dev \ | ||
libssl-dev \ | ||
zlib1g-dev | ||
|
||
# Install the iRODS icommands package because it's useful for interactions with \ | ||
# the server during development | ||
RUN echo "deb [arch=amd64] https://packages.irods.org/apt/ $(lsb_release -sc) main" |\ | ||
tee /etc/apt/sources.list.d/renci-irods.list && \ | ||
apt-get update && \ | ||
apt-get install -q -y --no-install-recommends \ | ||
irods-icommands="4.2.11-1~$(lsb_release -sc)" | ||
|
||
WORKDIR /app | ||
|
||
COPY . /app | ||
|
||
# It's more practical to build from an iRODS client image and install recent Python | ||
# than to build from a recent Python image and install iRODS clients. | ||
ENV PYENV_ROOT="/app/.pyenv" | ||
|
||
# Put PYENV first to ensure we use the pyenv-installed Python | ||
ENV PATH="${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" | ||
|
||
RUN ./docker/install_pyenv.sh | ||
|
||
RUN pyenv install "$PYTHON_VERSION" | ||
RUN pyenv global "$PYTHON_VERSION" | ||
|
||
RUN pip install --no-cache-dir -r requirements.txt && \ | ||
pip install --no-cache-dir -r test-requirements.txt && \ | ||
pip install --no-cache-dir . && \ | ||
git status && \ | ||
ls -al | ||
|
||
RUN chown -R appuser:appuser /app | ||
|
||
USER appuser | ||
|
||
ENTRYPOINT ["/app/docker/entrypoint.sh"] | ||
|
||
CMD ["/bin/bash"] |
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
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 |
---|---|---|
@@ -1,23 +1,31 @@ | ||
|
||
services: | ||
irods-server: | ||
platform: linux/amd64 | ||
container_name: irods-server | ||
image: "ghcr.io/wtsi-npg/ub-18.04-irods-${IRODS_VERSION:-4.2.11}:${DOCKER_TAG:-latest}" | ||
restart: always | ||
image: "ghcr.io/wtsi-npg/ub-16.04-irods-4.2.7:latest" | ||
ports: | ||
- "1247:1247" | ||
- "20000-20199:20000-20199" | ||
- "127.0.0.1:1247:1247" | ||
- "127.0.0.1:20000-20199:20000-20199" | ||
restart: always | ||
healthcheck: | ||
test: ["CMD", "nc", "-z", "-v", "localhost", "1247"] | ||
start_period: 30s | ||
interval: 5s | ||
timeout: 10s | ||
retries: 12 | ||
|
||
irods-clients: | ||
container_name: irods-clients | ||
image: "ghcr.io/wtsi-npg/ub-18.04-irods-clients-${IRODS_VERSION:-4.2.11}:${DOCKER_TAG:-latest}" | ||
app: | ||
platform: linux/amd64 | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.dev | ||
restart: always | ||
volumes: | ||
- "${PWD}:${PWD}" | ||
- "${PWD}/tests/.irods:${HOME}/.irods/" | ||
- "./tests/.irods:/home/appuser/.irods/" | ||
environment: | ||
CLIENT_USER: "${USER:? ERROR: The USER environment variable is unset}" | ||
CLIENT_USER_ID: "${UID:? ERROR: The UID environment variable is unset}" | ||
CLIENT_USER_HOME: "${HOME}" | ||
IRODS_ENVIRONMENT_FILE: "${HOME}/.irods/irods_environment.json" | ||
command: sleep infinity | ||
IRODS_ENVIRONMENT_FILE: "/home/appuser/.irods/irods_environment.json" | ||
IRODS_PASSWORD: "irods" | ||
depends_on: | ||
- irods-server | ||
irods-server: | ||
condition: service_healthy |
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 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
export PYENV_ROOT="/app/.pyenv" | ||
|
||
# Put PYENV first to ensure we use the pyenv-installed Python | ||
export PATH="${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:/bin:/usr/bin:/usr/local/bin" | ||
export PYTHONUNBUFFERED=1 | ||
export PYTHONPATH="" | ||
|
||
exec "$@" |
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,15 @@ | ||
#!/bin/bash | ||
|
||
set -ex | ||
|
||
PYENV_RELEASE_VERSION=${PYENV_RELEASE_VERSION:="2.4.1"} | ||
export PYENV_GIT_TAG="v${PYENV_RELEASE_VERSION}" | ||
|
||
PYENV_ROOT=${PYENV_ROOT:-"$HOME/.pyenv"} | ||
export PATH="$PYENV_ROOT/bin:$PATH" | ||
|
||
PYENV_SHA256="a1ad63c22842dce498b441551e2f83ede3e3b6ebb33f62013607bba424683191" | ||
curl -sSL -O https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | ||
sha256sum ./pyenv-installer | grep "$PYENV_SHA256" | ||
/bin/bash ./pyenv-installer | ||
rm ./pyenv-installer |
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
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright © 2020, 2021, 2022, 2023 Genome Research Ltd. All rights | ||
# Copyright © 2020, 2021, 2022, 2023, 2024 Genome Research Ltd. All rights | ||
# reserved. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
|
@@ -18,9 +18,12 @@ | |
# | ||
# @author Keith James <[email protected]> | ||
|
||
import json | ||
import os | ||
import shlex | ||
import subprocess | ||
from io import StringIO | ||
from pathlib import PurePath | ||
from pathlib import Path, PurePath | ||
from typing import List, Union | ||
|
||
from structlog import get_logger | ||
|
@@ -62,6 +65,49 @@ def imkdir(remote_path: Union[PurePath, str], make_parents=True): | |
_run(cmd) | ||
|
||
|
||
def iinit(): | ||
password = os.environ.get("IRODS_PASSWORD") | ||
if password is None or password == "": | ||
log.info( | ||
"Not authenticating with iRODS; no password specified by the " | ||
"IRODS_PASSWORD environment variable. Assuming the user is already " | ||
"authenticated." | ||
) | ||
return | ||
|
||
env_val = os.environ.get("IRODS_ENVIRONMENT_FILE") | ||
if env_val is None or env_val == "": | ||
log.info( | ||
"No iRODS environment file specified by the IRODS_ENVIRONMENT_FILE " | ||
"environment variable; using the default" | ||
) | ||
env_path = Path("~/.irods/irods_environment.json").expanduser().as_posix() | ||
else: | ||
env_path = Path(env_val).resolve().as_posix() | ||
|
||
log.info("Using iRODS environment file", env_path=env_path) | ||
|
||
with open(env_path) as f: | ||
env = json.load(f) | ||
if "irods_authentication_file" not in env: | ||
log.info( | ||
"No iRODS authentication file specified in the environment file; " | ||
"using the default" | ||
) | ||
auth_path = Path("~/.irods/.irodsA").expanduser().as_posix() | ||
else: | ||
auth_path = Path(env["irods_authentication_file"]).as_posix() | ||
|
||
if Path(auth_path).exists(): | ||
log.info("Updating the existing iRODS auth file", auth_path=auth_path) | ||
else: | ||
log.info("Creating a new iRODS auth file", auth_path=auth_path) | ||
|
||
password = shlex.quote(password) | ||
cmd = ["/bin/sh", "-c", f"echo {password} | iinit"] | ||
_run(cmd) | ||
|
||
|
||
def iget( | ||
remote_path: Union[PurePath, str], | ||
local_path: Union[PurePath, str], | ||
|
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
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,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright © 2024 Genome Research Ltd. All rights reserved. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
from partisan.icommands import iinit | ||
|
||
# Ensure that the iRODS environment is initialised before running any tests. Calling | ||
# this function will create or update a local iRODS auth file ready for use by the | ||
# iRODS clients used in the tests. | ||
iinit() |
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
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