From 15644b720f804c53d7204dc94c76eb4e3b0762da Mon Sep 17 00:00:00 2001 From: tefirman Date: Fri, 24 Jan 2025 16:59:33 -0800 Subject: [PATCH] Adding check for Docker image tag and updating README --- helloDockerHostname/README.md | 46 +++++++++++++-------- helloDockerHostname/helloDockerHostname.wdl | 34 ++++++++------- 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/helloDockerHostname/README.md b/helloDockerHostname/README.md index 3c5ca29..30a13f7 100644 --- a/helloDockerHostname/README.md +++ b/helloDockerHostname/README.md @@ -1,46 +1,56 @@ # HelloDockerHostname WDL Workflow ## Overview -A test workflow that demonstrates Docker container integration in WDL by returning the hostname of the compute node where the job is executed. This workflow extends the basic hostname test by running the command within a Docker container. +A test workflow that validates Docker container execution in WDL by running commands within a specified container and verifying the container environment. The workflow confirms both the container image and version, while also capturing the hostname of the execution node. ## Workflow Components ### Workflow: `HelloDockerHostname` -The main workflow executes a single task within a Docker container and returns its output. +The main workflow executes a task within a specified Docker container and validates the container environment. + +**Inputs:** +- `docker_image`: String specifying the Docker image (default: "ubuntu:20.04") **Outputs:** -- `stdout`: File containing the hostname of the execution node +- `stdout`: File containing container verification and hostname information ### Task: `Hostname` -Executes the `hostname` command within an Ubuntu Docker container. +Validates the Docker environment and executes commands within the container. **Runtime Requirements:** - CPU: 1 core - Memory: 1 GB -- Docker: `ubuntu:latest` +- Docker: Configurable via input (defaults to ubuntu:latest) -**Outputs:** -- `out`: File containing the hostname of the execution node +**Validation Checks:** +- Verifies Docker image name matches expected value +- Confirms image version/tag matches specified version ## Usage ```bash -# Execute with cromwell +# Execute with default Ubuntu latest java -jar cromwell.jar run helloDockerHostname.wdl -# Execute with miniwdl -miniwdl run helloDockerHostname.wdl +# Execute with specific Docker image +java -jar cromwell.jar run helloDockerHostname.wdl -i inputs.json + +# Using miniwdl with specific image +miniwdl run helloDockerHostname.wdl docker_image=ubuntu:20.04 +``` + +Example inputs.json: +```json +{ + "HelloDockerHostname.docker_image": "ubuntu:20.04" +} ``` ## Purpose -This workflow serves as a test case for: -- Docker container integration -- Container runtime environment validation -- Basic resource allocation testing -- Output handling validation from containerized tasks +- Docker container integration testing +- Container environment validation +- Image and version verification +- Resource allocation validation - Backend Docker support verification ## Version WDL 1.0 - -## Notes -- Comparing outputs between this and the non-Docker version can help verify proper container execution diff --git a/helloDockerHostname/helloDockerHostname.wdl b/helloDockerHostname/helloDockerHostname.wdl index 75fc123..8819321 100644 --- a/helloDockerHostname/helloDockerHostname.wdl +++ b/helloDockerHostname/helloDockerHostname.wdl @@ -6,7 +6,7 @@ version 1.0 workflow HelloDockerHostname { input { - String docker_image = "ubuntu:latest" # Default value but can be overridden + String docker_image = "ubuntu:20.04" # Default value but can be overridden } call Hostname { @@ -31,23 +31,29 @@ task Hostname { } command <<< - # Extract just the image name without tag for comparison - EXPECTED_BASE_IMAGE=$(echo "~{expected_image}" | cut -d':' -f1) - - # Get Docker image info + # Split expected image into name and tag + EXPECTED_IMAGE_NAME=$(echo "~{expected_image}" | cut -d':' -f1) + EXPECTED_TAG=$(echo "~{expected_image}" | cut -d':' -f2) + + # Get current image info CURRENT_IMAGE=$(grep "ID=" /etc/os-release | head -n1 | cut -d'=' -f2) - - # Assert it's the expected image - if [[ "$CURRENT_IMAGE" != "$EXPECTED_BASE_IMAGE" ]]; then - echo "Error: Expected Docker image $EXPECTED_BASE_IMAGE but got: $CURRENT_IMAGE" + CURRENT_VERSION=$(grep "VERSION_ID=" /etc/os-release | cut -d'"' -f2) + + # Compare image name + if [[ "$CURRENT_IMAGE" != "$EXPECTED_IMAGE_NAME" ]]; then + echo "Error: Expected Docker image $EXPECTED_IMAGE_NAME but got: $CURRENT_IMAGE" + exit 1 + fi + + # Compare version/tag + if [[ "$CURRENT_VERSION" != "$EXPECTED_TAG" ]]; then + echo "Error: Expected version $EXPECTED_TAG but got: $CURRENT_VERSION" exit 1 fi - - # If assertion passes, print container info - echo "Verified Docker Image: $CURRENT_IMAGE" - echo "Expected Image: $EXPECTED_BASE_IMAGE" + + echo "Verified Docker Image: $CURRENT_IMAGE:$CURRENT_VERSION" + echo "Expected Image: ~{expected_image}" echo "Hostname: $(hostname)" - echo "Container ID: $(grep -o -E '[[:alnum:]]{64}' /proc/1/cpuset || echo 'Not found')" >>> output {