Skip to content

Commit

Permalink
Adding check for Docker image tag and updating README
Browse files Browse the repository at this point in the history
  • Loading branch information
tefirman committed Jan 25, 2025
1 parent 54c530c commit 15644b7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 32 deletions.
46 changes: 28 additions & 18 deletions helloDockerHostname/README.md
Original file line number Diff line number Diff line change
@@ -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
34 changes: 20 additions & 14 deletions helloDockerHostname/helloDockerHostname.wdl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 15644b7

Please sign in to comment.