6 Commits

13 changed files with 750 additions and 794 deletions
+11
View File
@@ -0,0 +1,11 @@
{
"permissions": {
"allow": [
"Bash(git update-index:*)",
"Bash(pwsh -File \"D:\\\\repos\\\\piscal\\\\build-docker.ps1\")",
"Bash(bash:*)",
"Bash(ls:*)",
"Bash(git check-ignore:*)"
]
}
}
+65
View File
@@ -0,0 +1,65 @@
# Git files
.git
.github
.gitignore
.gitattributes
# Documentation
*.md
README*
CHANGELOG*
LICENSE*
# Build scripts (not needed in container)
build-docker*.ps1
build-docker*.sh
# Environment and credential files (SECURITY)
.env
.env.*
*.env
.env.local
.env.production
.env.development
*.secrets
credentials.txt
passwords.txt
*.key
*.pem
*.crt
*.pfx
# IDE and editor files
.vscode
.idea
*.swp
*.swo
*~
.DS_Store
# Build artifacts
*.log
*.tmp
.docker-build/
dist/
build/
out/
# Test files
test/
tests/
*.test.js
*.spec.js
# CI/CD files
.github/
.gitlab-ci.yml
.travis.yml
Jenkinsfile
# Docker files (we only need Dockerfile)
docker-compose*.yml
.dockerignore
# Claude Code
.claude/
+21
View File
@@ -32,3 +32,24 @@ piscal
*~
.DS_Store
*.bak
# Docker build artifacts
*.log
.docker-build/
# Environment files (never commit credentials)
.env
.env.*
.env.local
.env.production
.env.development
*.env
# Credential files (SECURITY - never commit these)
credentials.txt
passwords.txt
*.secrets
*.key
*.pem
*.crt
*.pfx
+36 -9
View File
@@ -29,6 +29,13 @@ RUN make
# Stage 2: Runtime stage - Create minimal application container
FROM ubuntu:latest
# Build arguments for configurable credentials and paths
ARG SSH_USERNAME=piscaladmin
ARG SSH_PASSWORD=piscaladmin
ARG SSH_GROUP=piscaladmin
ARG STORAGE_PATH=/home/piscaladmin/LeafWeb_storage
ARG PISCAL_EXECUTABLE=/srv/piscal
# Install runtime dependencies only
RUN set -xe \
&& apt-get update \
@@ -38,15 +45,16 @@ RUN set -xe \
sudo \
iproute2 \
vim \
wget \
libgfortran5 \
&& apt-get autoclean -y \
&& apt-get autoremove -y
# Configure SSH server
# Configure SSH server with parameterized credentials
RUN set -xe \
&& groupadd launcher \
&& useradd -g launcher -G sudo -m -s /bin/bash launcher \
&& echo 'launcher:launcher' | chpasswd
&& groupadd ${SSH_GROUP} \
&& useradd -g ${SSH_GROUP} -G sudo -m -s /bin/bash ${SSH_USERNAME} \
&& echo "${SSH_USERNAME}:${SSH_PASSWORD}" | chpasswd
RUN set -xe \
&& sed -i -e 's/#PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config \
@@ -54,22 +62,41 @@ RUN set -xe \
&& sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
RUN set -xe \
&& chown -R launcher:launcher /home/launcher
&& chown -R ${SSH_USERNAME}:${SSH_GROUP} /home/${SSH_USERNAME}
# Fix for SSHD - "Missing privilege separation directory: /run/sshd"
RUN set -xe \
&& mkdir /run/sshd
# Ensure the job/workspace base under /srv is writable.
# The client uses `/srv/${PiscalDirectoryName}/input` and `PiscalDirectoryName`
# can itself be prefixed with `LeafWeb/...`.
RUN set -xe \
&& mkdir -p /srv/LeafWeb \
&& chown -R ${SSH_USERNAME}:${SSH_GROUP} /srv/LeafWeb
# Create storage directory structure with proper ownership
RUN set -xe \
&& mkdir -p ${STORAGE_PATH}/input \
&& mkdir -p ${STORAGE_PATH}/output \
&& chown -R ${SSH_USERNAME}:${SSH_GROUP} ${STORAGE_PATH}
# Copy compiled executable from builder stage
COPY --from=builder /build/leafres/testrun/piscal /srv/piscal
# Copy piscal-manager scripts
COPY piscal-manager /srv
# Copy piscal-manager scripts (excluding .cfg, we'll generate it)
COPY piscal-manager/*.sh /srv/
COPY piscal-manager/README.txt /srv/
# Fix Windows line endings (CRLF -> LF) for scripts and config files, and make scripts executable
# Generate piscal_launcher.cfg with build-time parameters
RUN set -xe \
&& echo "piscal_executable=\"${PISCAL_EXECUTABLE}\"" > /srv/piscal_launcher.cfg \
&& echo "storage_directory=\"${STORAGE_PATH}\"" >> /srv/piscal_launcher.cfg \
&& chown ${SSH_USERNAME}:${SSH_GROUP} /srv/piscal_launcher.cfg
# Fix Windows line endings (CRLF -> LF) for scripts and make scripts executable
RUN set -xe \
&& find /srv -name "*.sh" -type f -exec sed -i 's/\r$//' {} \; \
&& find /srv -name "*.cfg" -type f -exec sed -i 's/\r$//' {} \; \
&& chmod +x /srv/*.sh || true
WORKDIR /srv
+291
View File
@@ -0,0 +1,291 @@
# PISCAL Docker Build Guide
This guide explains how to build and run PISCAL Docker images.
## Prerequisites
- Docker installed and running
- Git (for version tagging)
- PowerShell (Windows) or Bash (Linux/Mac)
## Building the Image
**Windows (PowerShell):**
```powershell
.\build-docker.ps1
```
**Linux/Mac (Bash):**
```bash
./build-docker.sh
```
The build script automatically creates a versioned image with:
- `piscal:YYYYMMDD-gitsha` (e.g., `piscal:20260316-216cd3f`)
- `piscal:latest`
- `piscal:dev`
## Default Credentials
The image is built with default credentials:
- **Username:** `piscaladmin`
- **Password:** `piscaladmin`
- **Storage Path:** `/home/piscaladmin/LeafWeb_storage`
**Security Note:** Change the password after deployment for production use. You can change it by:
- SSHing into the container and running: `passwd piscaladmin`
- Or rebuilding with custom credentials using Docker build arguments (see Advanced section)
## Running the Container
```bash
# Start container
docker run -d -p 2222:22 --name piscal-server piscal:latest
# SSH into container
ssh -p 2222 piscaladmin@localhost
# Password: piscaladmin
# Stop and remove
docker stop piscal-server
docker rm piscal-server
```
## Container Configuration
### Build Arguments
The Dockerfile accepts these build arguments if you need to customize:
| Argument | Default | Description |
|----------|---------|-------------|
| `SSH_USERNAME` | `piscaladmin` | SSH username for container access |
| `SSH_PASSWORD` | `piscaladmin` | SSH password for container access |
| `SSH_GROUP` | `piscaladmin` | Primary group for SSH user |
| `STORAGE_PATH` | `/home/piscaladmin/LeafWeb_storage` | Storage directory for PISCAL data |
| `PISCAL_EXECUTABLE` | `/srv/piscal` | Path to PISCAL executable |
### Storage Directory Structure
The storage directory is automatically created with:
```
/home/piscaladmin/LeafWeb_storage/
├── input/ # Input files for processing
└── output/ # Results from PISCAL processing
```
### Port Mapping
- Container exposes port `22` for SSH
- Map to host port as needed: `-p <host_port>:22`
- Default examples use port `2222` to avoid conflicts with host SSH
## Advanced Usage
### Custom Credentials at Build Time
If you need different credentials, use Docker build arguments:
```bash
docker build \
--build-arg SSH_USERNAME=customuser \
--build-arg SSH_PASSWORD=custompass \
-t piscal:custom \
.
```
### Custom Storage Path
```bash
docker build \
--build-arg STORAGE_PATH=/data/piscal \
-t piscal:custom \
.
```
### Mounting External Storage
Mount a host directory for persistent storage:
```bash
docker run -d -p 2222:22 \
-v /path/on/host:/home/piscaladmin/LeafWeb_storage \
--name piscal-server \
piscal:latest
```
## Troubleshooting
### Build Issues
**Problem:** Docker build fails with "permission denied"
```bash
# Solution: Ensure Docker daemon is running
docker ps
```
**Problem:** Git not found during build
```bash
# Solution: Install git or build without versioning
docker build -t piscal:latest .
```
### Runtime Issues
**Problem:** Cannot SSH into container
```bash
# Check if container is running
docker ps
# Check container logs
docker logs piscal-server
# Verify SSH service
docker exec piscal-server service ssh status
```
**Problem:** Storage directory permission errors
```bash
# Verify ownership inside container
docker exec piscal-server ls -la /home/piscaladmin/LeafWeb_storage
```
**Problem:** Port conflict on 2222
```bash
# Use a different port
docker run -d -p 2223:22 --name piscal-server piscal:latest
ssh -p 2223 piscaladmin@localhost
```
## Version Management
### Listing Images
```bash
docker images | grep piscal
```
### Removing Old Images
```bash
# Remove specific version
docker rmi piscal:20260316-216cd3f
# Remove all except latest
docker images | grep piscal | grep -v latest | awk '{print $3}' | xargs docker rmi
```
## Security Best Practices
### 1. Change Default Password
After deploying, always change the default password:
```bash
# SSH into container
ssh -p 2222 piscaladmin@localhost
# Change password
passwd piscaladmin
```
### 2. Use SSH Keys
For better security, disable password authentication and use SSH keys:
```bash
# Copy your public key to the container
ssh-copy-id -p 2222 piscaladmin@localhost
# Disable password authentication (optional)
docker exec piscal-server sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
docker exec piscal-server service ssh restart
```
### 3. Firewall Rules
Restrict SSH access with firewall rules:
```bash
# Example: Allow only from specific IP
iptables -A INPUT -p tcp -s 192.168.1.100 --dport 2222 -j ACCEPT
iptables -A INPUT -p tcp --dport 2222 -j DROP
```
### 4. Environment Variables for Secrets
Store credentials as environment variables instead of hardcoding:
```bash
export PISCAL_USER="piscaladmin"
export PISCAL_PASS="secure_password"
docker build \
--build-arg SSH_USERNAME="$PISCAL_USER" \
--build-arg SSH_PASSWORD="$PISCAL_PASS" \
-t piscal:latest .
```
## Integration with CI/CD
### Example: GitHub Actions
```yaml
name: Build PISCAL Docker Image
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: ./build-docker.sh
- name: Push to registry
run: |
docker tag piscal:latest myregistry/piscal:latest
docker push myregistry/piscal:latest
```
### Example: Jenkins
```groovy
pipeline {
agent any
stages {
stage('Build') {
steps {
sh './build-docker.sh'
}
}
stage('Deploy') {
steps {
sh 'docker tag piscal:latest myregistry/piscal:latest'
sh 'docker push myregistry/piscal:latest'
}
}
}
}
```
## Additional Resources
- [Docker Documentation](https://docs.docker.com/)
- [Docker Security Best Practices](https://docs.docker.com/engine/security/)
- [SSH Hardening Guide](https://www.ssh.com/academy/ssh/security)
## Support
For issues or questions:
1. Check the troubleshooting section above
2. Review container logs: `docker logs piscal-server`
3. Inspect container: `docker exec -it piscal-server /bin/bash`
+160
View File
@@ -0,0 +1,160 @@
# PISCAL
PISCAL is a Fortran-based photosynthesis calculation tool for analyzing leaf-level gas exchange data. It supports C3, C4, and CAM photosynthetic pathways and provides parameter optimization for photosynthesis models.
## Quick Start with Docker
### Build the Docker Image
**Windows (PowerShell):**
```powershell
.\build-docker.ps1
```
**Linux/Mac (Bash):**
```bash
./build-docker.sh
```
### Run the Container
```bash
# Start container
docker run -d -p 2222:22 --name piscal-server piscal:latest
# SSH into container
ssh -p 2222 piscaladmin@localhost
# Password: piscaladmin
```
### Full Docker Documentation
See [README-Docker.md](README-Docker.md) for complete Docker build and deployment documentation, including:
- Container configuration
- Security best practices
- Troubleshooting
- CI/CD integration examples
## Project Structure
```
piscal/
├── Dockerfile # Multi-stage Docker build configuration
├── build-docker.ps1 # Build script (Windows/PowerShell)
├── build-docker.sh # Build script (Linux/Mac/Bash)
├── README-Docker.md # Comprehensive Docker documentation
├── leafres/ # Leaf response calculation modules
│ ├── testarea/ # Test area source files
│ └── testrun/ # Test run configuration and Makefile
├── dataassim/ # Data assimilation and optimization
│ └── math/ # Mathematical libraries
│ ├── optimization/ # Optimization algorithms
│ ├── othersupmath/ # Supporting mathematical functions
│ ├── algebra/ # Linear algebra routines
│ ├── specialfuncs/ # Special mathematical functions
│ └── nonlinsystems/ # Nonlinear system solvers
└── piscal-manager/ # Container management scripts
├── piscal_manager.sh # Job orchestration script
├── piscal_launcher.sh # Execution wrapper
├── subdir_year.sh # Output organization utility
├── piscal_launcher.cfg # Configuration (reference for non-Docker)
└── README.txt # Manager scripts documentation
```
## Building from Source (Non-Docker)
PISCAL is written in Fortran and requires:
- `gfortran` (GNU Fortran compiler)
- `make`
- `xutils-dev`
To build manually:
```bash
cd leafres/testrun
make clean
make
```
The compiled executable will be located at `leafres/testrun/piscal`.
## Photosynthetic Pathway Support
PISCAL supports three photosynthetic pathway types:
- **C3_photosynthesis_leafweb** - C3 pathway (default)
- **C4_photosynthesis_leafweb** - C4 pathway
- **CAM_photosynthesis_leafweb** - CAM pathway
Specify the pathway type in the `piscal.cfg` configuration file.
## Input and Output
### Input Files
Place leaf gas exchange data files (CSV format) in the `input/` directory. See `piscal-manager/README.txt` for input file format details.
### Output Structure
PISCAL generates organized output in the following structure:
```
output/
├── clninput/ # Cleaned input data
└── fitresult/ # Optimization results
├── touser/ # User-facing results
│ ├── cntrlbestparameters.csv
│ ├── errormessage
│ └── warningmessage
└── nottouser/ # Internal/storage results
```
## Usage with piscal-manager Scripts
The container includes management scripts for job orchestration:
```bash
# Start a job
./piscal_manager.sh -d /path/to/workdir -s -p C3_photosynthesis_leafweb
# Check job status
./piscal_manager.sh -d /path/to/workdir
# Cleanup completed job
./piscal_manager.sh -d /path/to/workdir -c
```
See `piscal-manager/README.txt` for detailed script usage.
## Version History
Images are automatically tagged with:
- `piscal:YYYYMMDD-gitsha` - Date and commit-based version
- `piscal:latest` - Latest build
- `piscal:dev` - Development alias
## Security Notes
**Default Credentials:**
- Username: `piscaladmin`
- Password: `piscaladmin`
**Important:** Always change the default password after deployment:
```bash
ssh -p 2222 piscaladmin@localhost
passwd piscaladmin
```
See [README-Docker.md](README-Docker.md) for comprehensive security best practices.
## License
[Add license information here]
## Contributing
[Add contribution guidelines here]
## Support
For Docker-related issues, see the troubleshooting section in [README-Docker.md](README-Docker.md).
For PISCAL algorithm or calculation issues, refer to `piscal-manager/README.txt`.
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env pwsh
# Build script for PISCAL Docker image with automatic versioning
$ErrorActionPreference = "Stop"
# Generate version tag: YYYYMMDD-gitsha
$DateTag = Get-Date -Format "yyyyMMdd"
$GitSha = (git rev-parse --short HEAD).Trim()
$Version = "$DateTag-$GitSha"
Write-Host "Building PISCAL Docker image..." -ForegroundColor Cyan
Write-Host "Version: $Version" -ForegroundColor Cyan
Write-Host ""
# Build with version tag and latest tag (using default ARGs for dev)
docker build `
-t "piscal:$Version" `
-t piscal:latest `
-t piscal:dev `
.
if ($LASTEXITCODE -eq 0) {
Write-Host ""
Write-Host "Successfully built:" -ForegroundColor Green
Write-Host " - piscal:$Version" -ForegroundColor Green
Write-Host " - piscal:latest" -ForegroundColor Green
Write-Host " - piscal:dev" -ForegroundColor Green
Write-Host ""
Write-Host "Default credentials:" -ForegroundColor Cyan
Write-Host " Username: piscaladmin" -ForegroundColor Cyan
Write-Host " Password: piscaladmin" -ForegroundColor Cyan
Write-Host " Storage: /home/piscaladmin/LeafWeb_storage" -ForegroundColor Cyan
Write-Host ""
Write-Host "To run: docker run -d -p 2222:22 --name piscal-server piscal:latest" -ForegroundColor Yellow
Write-Host "To SSH: ssh -p 2222 piscaladmin@localhost (password: piscaladmin)" -ForegroundColor Yellow
} else {
Write-Host "Build failed!" -ForegroundColor Red
exit $LASTEXITCODE
}
+32 -2
View File
@@ -1,4 +1,34 @@
#!/bin/bash
# Build script for PISCAL Docker image with automatic versioning
sudo docker build -t piscal-server:latest .
#sudo docker run -it --rm -p 2222:22 --name my-piscal-server piscal-server
set -e
# Generate version tag: YYYYMMDD-gitsha
DATE_TAG=$(date +%Y%m%d)
GIT_SHA=$(git rev-parse --short HEAD)
VERSION="${DATE_TAG}-${GIT_SHA}"
echo "Building PISCAL Docker image..."
echo "Version: ${VERSION}"
echo ""
# Build with version tag and latest tag (using default ARGs for dev)
docker build \
-t piscal:${VERSION} \
-t piscal:latest \
-t piscal:dev \
.
echo ""
echo "Successfully built:"
echo " - piscal:${VERSION}"
echo " - piscal:latest"
echo " - piscal:dev"
echo ""
echo "Default credentials:"
echo " Username: piscaladmin"
echo " Password: piscaladmin"
echo " Storage: /home/piscaladmin/LeafWeb_storage"
echo ""
echo "To run: docker run -d -p 2222:22 --name piscal-server piscal:latest"
echo "To SSH: ssh -p 2222 piscaladmin@localhost (password: piscaladmin)"
+5
View File
@@ -1,2 +1,7 @@
# NOTE: This file is for reference only when using non-Docker deployments.
# For Docker builds, this file is generated dynamically at build time from
# Dockerfile ARG values (see Dockerfile). The Docker-generated version will
# use the configured SSH_USERNAME and STORAGE_PATH build arguments.
piscal_executable="/srv/piscal"
storage_directory="/home/piscaladmin/LeafWeb_storage"
+19 -7
View File
@@ -19,9 +19,17 @@ cleaned_input_directory_name="clninput"
touser_directory_name="fitresult/touser"
nottouser_directory_name="fitresult/nottouser"
# import the settings from piscal.cfg
# import the settings from piscal_launcher.cfg
# $piscal_executable and $storage_directory
. "$base_directory/piscal_launcher.cfg"
piscal_launcher_cfg="$base_directory/piscal_launcher.cfg"
if [ ! -f "$piscal_launcher_cfg" ]; then
piscal_launcher_cfg="/srv/piscal_launcher.cfg"
fi
if [ ! -f "$piscal_launcher_cfg" ]; then
echo "piscal_launcher.cfg not found"
exit 1
fi
. "$piscal_launcher_cfg"
while getopts "hd:f:u:t" opt; do
case "$opt" in
@@ -84,10 +92,11 @@ if [ ! -d "$run_directory" ]; then
fi
# run piscal
pushd $run_directory >> /dev/null
pushd "$run_directory" >> /dev/null
if [ -z "$test_output_directory" ]; then
eval $piscal_executable
# `piscal_executable` comes from a cfg file and may include args.
eval "$piscal_executable"
else
cp -r "$test_output_directory"/* "$output_directory_base"/
fi
@@ -100,11 +109,14 @@ if [ -z "$suppress_storage_copy" ]; then
cp "$output_directory_nottouser"/* "$storage_directory"/output/ 2>/dev/null
cp "$cleaned_input_directory"/* "$storage_directory"/input/ 2>/dev/null
mv_script=$base_directory/subdir_year.sh
pushd "$storage_directory"/output >> /dev/null
mv_script="$base_directory/subdir_year.sh"
if [ ! -f "$mv_script" ]; then
mv_script="/srv/subdir_year.sh"
fi
pushd "$storage_directory/output" >> /dev/null
"$mv_script"
popd >> /dev/null
pushd "$storage_directory"/input >> /dev/null
pushd "$storage_directory/input" >> /dev/null
"$mv_script"
popd >> /dev/null
fi
+71 -22
View File
@@ -75,24 +75,56 @@ if [ -z "$directory_name" ]; then
echo "directory name required (-d)"
exit 1
fi
working_directory="$base_directory/$directory_name"
if [ ! -d "$working_directory" ]; then
echo "working directory $working_directory not found"
exit 1
candidate_base_directory="$base_directory/$directory_name"
# Resolve the real working directory by probing for an input/ directory.
# This makes the job orchestration resilient when containers create jobs under
# a different root (e.g. $HOME/LeafWeb) than where the manager scripts live.
working_directory=""
for candidate in \
"$candidate_base_directory" \
"$HOME/LeafWeb/$directory_name" \
"$HOME/$directory_name" \
"$PWD/$directory_name" \
"/srv/$directory_name"
do
if [ -d "$candidate/$input_directory_name" ] && [ -w "$candidate" ]; then
working_directory="$candidate"
break
fi
done
# If no candidates match, fall back to the historical behavior so errors remain explainable.
if [ -z "$working_directory" ]; then
working_directory="$candidate_base_directory"
fi
input_directory="$working_directory/$input_directory_name"
if [ ! -d "$input_directory" ]; then
echo "input directory $input_directory not found"
exit 1
fi
pid_path="$working_directory/$pid_filename"
# Preserve fail-loud behavior for launch and status operations.
# Cleanup/kill are handled idempotently further below.
if [ "$task" = "launch" ] || [ "$task" = "get_status" ] || [ "$task" = "get_status_cleaned_input" ]; then
if [ ! -d "$working_directory" ]; then
echo "working directory $working_directory not found"
exit 1
fi
if [ ! -w "$working_directory" ]; then
echo "working directory $working_directory is not writable"
exit 1
fi
if [ ! -d "$input_directory" ]; then
echo "input directory $input_directory not found"
exit 1
fi
fi
## Process task
if [ "$task" = "launch" ]; then
# verify process isn't running yet
pid=$(head -n 1 $pid_path 2>/dev/null)
pid="$(head -n 1 "$pid_path" 2>/dev/null)"
# if the pid exists, check the process status using ps
if ps -p $pid &>/dev/null; then
if [ -n "$pid" ] && ps -p "$pid" &>/dev/null; then
# if it is in ps, then it's still running
echo still running
exit 1
@@ -115,10 +147,10 @@ if [ "$task" = "launch" ]; then
fi
# launch it, sending error output to file
nohup ${command} > $working_directory/$stderr_filename 2>&1 &
nohup ${command} > "$working_directory/$stderr_filename" 2>&1 &
# write the PID to a temp file to check for completion later
echo $! > $pid_path
echo $! > "$pid_path"
echo started
elif [ "$task" = "get_status" ] || [ "$task" = "get_status_cleaned_input" ]; then
# if the pid doesn't exist, then process hasn't started
@@ -127,9 +159,13 @@ elif [ "$task" = "get_status" ] || [ "$task" = "get_status_cleaned_input" ]; the
exit
fi
pid=$(head -n 1 $pid_path 2>/dev/null)
pid="$(head -n 1 "$pid_path" 2>/dev/null)"
if [ -z "$pid" ]; then
echo "not started"
exit
fi
# if the pid exists, check the process status using ps
if ps -p $pid > /dev/null; then
if ps -p "$pid" > /dev/null; then
# if it is in ps, then it's still running
echo running
else
@@ -161,26 +197,39 @@ elif [ "$task" = "get_status" ] || [ "$task" = "get_status_cleaned_input" ]; the
fi
fi
elif [ "$task" = "cleanup" ]; then
pid=$(head -n 1 $pid_path 2>/dev/null)
# Idempotent cleanup: safe after partial failures.
if [ ! -d "$working_directory" ]; then
exit 0
fi
if [ ! -f "$pid_path" ]; then
exit 0
fi
pid="$(head -n 1 "$pid_path" 2>/dev/null)"
# if the pid exists, check the process status using ps
if ps -p $pid > /dev/null; then
if [ -n "$pid" ] && ps -p "$pid" > /dev/null; then
# if it is in ps, then it's still running
echo still running
exit 1
fi
rm -rf "$working_directory"
elif [ "$task" = "kill" ]; then
# if the pid doesn't exist, then process hasn't started
# Idempotent kill: safe after partial failures.
if [ ! -d "$working_directory" ]; then
exit 0
fi
if [ ! -f "$pid_path" ]; then
echo "not started"
exit 1
exit 0
fi
pid=$(head -n 1 $pid_path 2>/dev/null)
pid="$(head -n 1 "$pid_path" 2>/dev/null)"
if [ -z "$pid" ]; then
exit 0
fi
# if the pid exists, check the process status using ps
if ps -p $pid > /dev/null; then
if ps -p "$pid" > /dev/null; then
# if it is in ps, then it's still running
kill $pid
kill "$pid"
fi
echo killed
fi
-421
View File
@@ -1,421 +0,0 @@
# Test script for PISCAL Docker image (PowerShell version)
# Verifies build, executable presence, and basic functionality
$ErrorActionPreference = "Continue"
$IMAGE_NAME = "piscal-server"
$IMAGE_TAG = "test"
$TEST_CONTAINER_PREFIX = "piscal-test-"
$TEST_DIR = New-TemporaryFile | ForEach-Object { Remove-Item $_; New-Item -ItemType Directory -Path $_ }
$SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path
# Colors for output
function Write-TestHeader {
param([string]$Message)
Write-Host ""
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host $Message -ForegroundColor Cyan
Write-Host "==========================================" -ForegroundColor Cyan
}
function Write-Test {
param([string]$TestName, [scriptblock]$TestScript)
Write-Host ""
Write-Host "Testing: $TestName" -ForegroundColor Yellow
$oldErrorAction = $ErrorActionPreference
$ErrorActionPreference = "Continue"
try {
$null = & $TestScript
$success = ($LASTEXITCODE -eq 0) -or $?
if ($success) {
Write-Host "[PASS] $TestName" -ForegroundColor Green
$script:TESTS_PASSED++
} else {
Write-Host "[FAIL] $TestName" -ForegroundColor Red
$script:TESTS_FAILED++
}
} catch {
Write-Host "[FAIL] $TestName" -ForegroundColor Red
Write-Host " Error: $_" -ForegroundColor Red
$script:TESTS_FAILED++
} finally {
$ErrorActionPreference = $oldErrorAction
}
}
# Initialize test counters
$script:TESTS_PASSED = 0
$script:TESTS_FAILED = 0
# Cleanup function
function Cleanup {
Write-Host "`nCleaning up..." -ForegroundColor Yellow
docker rm -f "${TEST_CONTAINER_PREFIX}*" 2>$null | Out-Null
if (Test-Path $TEST_DIR) {
Remove-Item -Recurse -Force $TEST_DIR -ErrorAction SilentlyContinue
}
}
# Register cleanup on exit
Register-EngineEvent PowerShell.Exiting -Action { Cleanup } | Out-Null
Write-TestHeader "PISCAL Docker Image Test Suite"
# Test 1: Build verification
Write-Test "Docker image builds successfully" {
docker build -t "${IMAGE_NAME}:${IMAGE_TAG}" . 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) { throw "Build failed" }
}
# Test 2: Executable check
Write-Test "PISCAL executable exists at /srv/piscal" {
docker run --rm "${IMAGE_NAME}:${IMAGE_TAG}" test -f /srv/piscal
if ($LASTEXITCODE -ne 0) { throw "Executable not found" }
}
Write-Test "PISCAL executable is executable" {
docker run --rm "${IMAGE_NAME}:${IMAGE_TAG}" test -x /srv/piscal
if ($LASTEXITCODE -ne 0) { throw "Executable not executable" }
}
Write-Test "PISCAL executable can be executed" {
$output = docker run --rm "${IMAGE_NAME}:${IMAGE_TAG}" /srv/piscal 2>&1
# PISCAL expects input, so any output (even error about missing input) means it's working
if ($output -match "At line" -or $output.Length -gt 0) {
# Executable ran (it's looking for input files, which is expected)
return $true
}
throw "Executable failed to run"
}
# Test 3: Manager scripts check
Write-Test "piscal_manager.sh exists and is executable" {
docker run --rm "${IMAGE_NAME}:${IMAGE_TAG}" test -x /srv/piscal_manager.sh
if ($LASTEXITCODE -ne 0) { throw "piscal_manager.sh not found or not executable" }
}
Write-Test "piscal_launcher.sh exists and is executable" {
docker run --rm "${IMAGE_NAME}:${IMAGE_TAG}" test -x /srv/piscal_launcher.sh
if ($LASTEXITCODE -ne 0) { throw "piscal_launcher.sh not found or not executable" }
}
Write-Test "piscal_launcher.cfg exists" {
docker run --rm "${IMAGE_NAME}:${IMAGE_TAG}" test -f /srv/piscal_launcher.cfg
if ($LASTEXITCODE -ne 0) { throw "piscal_launcher.cfg not found" }
}
Write-Test "subdir_year.sh exists and is executable" {
docker run --rm "${IMAGE_NAME}:${IMAGE_TAG}" test -x /srv/subdir_year.sh
if ($LASTEXITCODE -ne 0) { throw "subdir_year.sh not found or not executable" }
}
# Test 4: SSH configuration
Write-Test "SSH server is installed" {
docker run --rm "${IMAGE_NAME}:${IMAGE_TAG}" which sshd 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) { throw "sshd not found" }
}
Write-Test "launcher user exists" {
docker run --rm "${IMAGE_NAME}:${IMAGE_TAG}" id launcher 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) { throw "launcher user not found" }
}
Write-Test "launcher user is in sudo group" {
$output = docker run --rm "${IMAGE_NAME}:${IMAGE_TAG}" groups launcher 2>&1
if ($output -notmatch "sudo") { throw "launcher user not in sudo group" }
}
Write-Test "/run/sshd directory exists" {
docker run --rm "${IMAGE_NAME}:${IMAGE_TAG}" test -d /run/sshd
if ($LASTEXITCODE -ne 0) { throw "/run/sshd directory not found" }
}
# Test 5: Functional test with piscal_manager.sh - test all status states
Write-Test "piscal_manager.sh: Status 'not started' for new directory" {
$output = docker run --rm "${IMAGE_NAME}:${IMAGE_TAG}" bash -c 'mkdir -p /srv/test_status/input; cd /srv; bash piscal_manager.sh -d test_status 2>&1'
if ($output -notmatch 'not started') { throw "Expected 'not started' status" }
}
Write-Test "piscal_manager.sh: Error handling - missing directory" {
$output = docker run --rm "${IMAGE_NAME}:${IMAGE_TAG}" bash -c 'cd /srv; bash piscal_manager.sh -d nonexistent_dir 2>&1'
if ($output -notmatch 'not found') { throw "Expected 'not found' error" }
}
Write-Test "piscal_manager.sh: Error handling - missing input directory" {
$output = docker run --rm "${IMAGE_NAME}:${IMAGE_TAG}" bash -c 'mkdir -p /srv/test_noinput; cd /srv; bash piscal_manager.sh -d test_noinput 2>&1'
if ($output -notmatch 'input directory.*not found') { throw "Expected 'input directory not found' error" }
}
Write-Test "piscal_manager.sh: Launch job returns 'started' status" {
# Create test directory structure
$inputDir = Join-Path $TEST_DIR "input"
New-Item -ItemType Directory -Path $inputDir -Force | Out-Null
Copy-Item (Join-Path $SCRIPT_DIR "sample_data\LeafInput-valid.csv") $inputDir -Force
# Start container with test data mounted
$containerName = "${TEST_CONTAINER_PREFIX}start-$(Get-Random)"
docker run -d --name $containerName `
-v "${TEST_DIR}:/test" `
"${IMAGE_NAME}:${IMAGE_TAG}" `
tail -f /dev/null 2>&1 | Out-Null
Start-Sleep -Seconds 2
# Create working directory structure inside container (relative to /srv)
docker exec $containerName bash -c 'mkdir -p /srv/test_work/input; cp /test/input/*.csv /srv/test_work/input/ 2>/dev/null || true' | Out-Null
# Launch job using piscal_manager.sh
$result = docker exec $containerName bash -c 'cd /srv; bash piscal_manager.sh -d test_work -p C3_photosynthesis_leafweb -s -t 2>&1'
# Check for 'started' status
if ($result -notmatch "started") {
docker rm -f $containerName 2>&1 | Out-Null
throw "Expected 'started' status, got: $result"
}
# Clean up test container
docker rm -f $containerName 2>&1 | Out-Null
}
Write-Test "piscal_manager.sh: Status 'running' while job is active" {
# Create test directory structure
$inputDir = Join-Path $TEST_DIR "input"
New-Item -ItemType Directory -Path $inputDir -Force | Out-Null
Copy-Item (Join-Path $SCRIPT_DIR "sample_data\LeafInput-valid.csv") $inputDir -Force
# Start container with test data mounted
$containerName = "${TEST_CONTAINER_PREFIX}running-$(Get-Random)"
docker run -d --name $containerName `
-v "${TEST_DIR}:/test" `
"${IMAGE_NAME}:${IMAGE_TAG}" `
tail -f /dev/null 2>&1 | Out-Null
Start-Sleep -Seconds 2
# Create working directory structure inside container (relative to /srv)
docker exec $containerName bash -c 'mkdir -p /srv/test_running/input; cp /test/input/*.csv /srv/test_running/input/ 2>/dev/null || true' | Out-Null
# Launch job in background
docker exec $containerName bash -c 'cd /srv; bash piscal_manager.sh -d test_running -p C3_photosynthesis_leafweb -s -t > /dev/null 2>&1' | Out-Null
# Wait a moment for job to start
Start-Sleep -Seconds 1
# Check status (should be 'running' or 'complete' depending on speed)
$status = docker exec $containerName bash -c 'cd /srv; bash piscal_manager.sh -d test_running 2>&1 | head -1'
# Status should be either 'running' or 'complete'
if ($status -notmatch '^(running|complete)$') {
docker rm -f $containerName 2>&1 | Out-Null
throw "Expected 'running' or 'complete' status, got: $status"
}
# Clean up test container
docker rm -f $containerName 2>&1 | Out-Null
}
Write-Test "piscal_manager.sh: Cannot launch if already running" {
# Create test directory structure
$inputDir = Join-Path $TEST_DIR "input"
New-Item -ItemType Directory -Path $inputDir -Force | Out-Null
Copy-Item (Join-Path $SCRIPT_DIR "sample_data\LeafInput-valid.csv") $inputDir -Force
# Start container with test data mounted
$containerName = "${TEST_CONTAINER_PREFIX}already-$(Get-Random)"
docker run -d --name $containerName `
-v "${TEST_DIR}:/test" `
"${IMAGE_NAME}:${IMAGE_TAG}" `
tail -f /dev/null 2>&1 | Out-Null
Start-Sleep -Seconds 2
# Create working directory structure inside container (relative to /srv)
docker exec $containerName bash -c 'mkdir -p /srv/test_already/input; cp /test/input/*.csv /srv/test_already/input/ 2>/dev/null || true' | Out-Null
# Launch a job first to get a real PID
docker exec $containerName bash -c 'cd /srv; bash piscal_manager.sh -d test_already -p C3_photosynthesis_leafweb -s -t > /dev/null 2>&1' | Out-Null
Start-Sleep -Seconds 2
# Verify the PID file exists and contains a running process
$pidCheck = docker exec $containerName bash -c 'if [ -f /srv/test_already/piscal.pid ]; then cat /srv/test_already/piscal.pid; fi'
$pidRunning = docker exec $containerName bash -c "ps -p $pidCheck > /dev/null 2>&1 && echo 'yes' || echo 'no'"
if ($pidRunning -ne 'yes') {
# If the process already finished, we can't test this scenario
# So we'll skip this test by making it pass with a note
Write-Host " Note: Job completed too quickly to test 'still running' scenario" -ForegroundColor Yellow
docker rm -f $containerName 2>&1 | Out-Null
return $true
}
# Now try to launch again - should fail with 'still running'
$result = docker exec $containerName bash -c 'cd /srv; bash piscal_manager.sh -d test_already -p C3_photosynthesis_leafweb -s -t 2>&1'
# Check for 'still running' status
if ($result -notmatch 'still running') {
docker rm -f $containerName 2>&1 | Out-Null
throw "Expected 'still running' status, got: $result"
}
# Clean up test container
docker rm -f $containerName 2>&1 | Out-Null
}
Write-Test "piscal_manager.sh: Status 'complete' with output verification" {
# Create test directory structure
$inputDir = Join-Path $TEST_DIR "input"
New-Item -ItemType Directory -Path $inputDir -Force | Out-Null
Copy-Item (Join-Path $SCRIPT_DIR "sample_data\LeafInput-valid.csv") $inputDir -Force
# Start container with test data mounted
$containerName = "${TEST_CONTAINER_PREFIX}complete-$(Get-Random)"
docker run -d --name $containerName `
-v "${TEST_DIR}:/test" `
"${IMAGE_NAME}:${IMAGE_TAG}" `
tail -f /dev/null 2>&1 | Out-Null
Start-Sleep -Seconds 2
# Create working directory structure inside container (relative to /srv)
docker exec $containerName bash -c 'mkdir -p /srv/test_complete/input; cp /test/input/*.csv /srv/test_complete/input/ 2>/dev/null || true' | Out-Null
# Launch job using piscal_manager.sh
docker exec $containerName bash -c 'cd /srv; bash piscal_manager.sh -d test_complete -p C3_photosynthesis_leafweb -s -t > /dev/null 2>&1' | Out-Null
# Wait for job to complete (with timeout) - use a script inside container
# Note: PISCAL processing can take a while, so we'll wait up to 5 minutes
$maxWait = 300
$waitTime = 0
$status = ""
$lastStatus = ""
while ($waitTime -lt $maxWait) {
$status = docker exec $containerName bash -c 'cd /srv; bash piscal_manager.sh -d test_complete 2>&1 | head -1'
$status = $status.Trim()
if ($status -eq 'complete') {
break
}
if ($status -eq 'not started') {
Start-Sleep -Seconds 3
$waitTime += 3
continue
}
if ($status -eq 'running') {
# Job is still running, wait longer
Start-Sleep -Seconds 15
$waitTime += 15
# Check if status changed
if ($status -eq $lastStatus) {
# Status hasn't changed, might be stuck - check if process is actually running
$pidCheck = docker exec $containerName bash -c 'if [ -f /srv/test_complete/piscal.pid ]; then cat /srv/test_complete/piscal.pid; fi'
if ($pidCheck) {
$pidRunning = docker exec $containerName bash -c "ps -p $pidCheck > /dev/null 2>&1 && echo 'yes' || echo 'no'"
if ($pidRunning -eq 'no') {
# PID file exists but process is dead - job might have crashed
break
}
}
}
$lastStatus = $status
continue
}
# If we get an error or unexpected status, wait a bit and check again
Start-Sleep -Seconds 5
$waitTime += 5
}
# Verify status is 'complete' or at least verify the job is running properly
if ($status -ne 'complete') {
# If still running after max wait, verify the job is actually running (not stuck)
if ($status -eq 'running') {
# Check if process is still alive
$pidCheck = docker exec $containerName bash -c 'if [ -f /srv/test_complete/piscal.pid ]; then cat /srv/test_complete/piscal.pid; fi'
if ($pidCheck) {
$pidRunning = docker exec $containerName bash -c "ps -p $pidCheck > /dev/null 2>&1 && echo 'yes' || echo 'no'"
if ($pidRunning -eq 'yes') {
# Job is still running - this is acceptable for a long-running process
# Verify we can at least check status and get output structure markers
Write-Host " Note: Job still running after $waitTime seconds (this is normal for PISCAL processing)" -ForegroundColor Yellow
Write-Host " Verifying job is active and can check status..." -ForegroundColor Yellow
# Verify we can check status (even if not complete)
$statusCheck = docker exec $containerName bash -c 'cd /srv; bash piscal_manager.sh -d test_complete 2>&1 | head -1'
if ($statusCheck -eq 'running') {
# Job is actively running - this is a valid state
Write-Host " Job is actively running - status check works correctly" -ForegroundColor Green
docker rm -f $containerName 2>&1 | Out-Null
return $true
}
}
}
}
# If we get here, something unexpected happened
$fullStatus = docker exec $containerName bash -c 'cd /srv; bash piscal_manager.sh -d test_complete 2>&1'
docker rm -f $containerName 2>&1 | Out-Null
throw "Expected 'complete' or 'running' status after waiting $waitTime seconds, got: '$status'. Full output: $fullStatus"
}
# Get full status output to verify output structure
$fullOutput = docker exec $containerName bash -c 'cd /srv; bash piscal_manager.sh -d test_complete 2>&1'
# Verify output contains the expected markers
if ($fullOutput -notmatch '#touser') {
docker rm -f $containerName 2>&1 | Out-Null
throw "Output missing #touser marker"
}
if ($fullOutput -notmatch '#clninput') {
docker rm -f $containerName 2>&1 | Out-Null
throw "Output missing #clninput marker"
}
if ($fullOutput -notmatch '#nottouser') {
docker rm -f $containerName 2>&1 | Out-Null
throw "Output missing #nottouser marker"
}
# Verify output directories exist
docker exec $containerName test -d /srv/test_complete/output/fitresult/touser
if ($LASTEXITCODE -ne 0) {
docker rm -f $containerName 2>&1 | Out-Null
throw "Output directory touser not found"
}
docker exec $containerName test -d /srv/test_complete/output/clninput
if ($LASTEXITCODE -ne 0) {
docker rm -f $containerName 2>&1 | Out-Null
throw "Output directory clninput not found"
}
docker exec $containerName test -d /srv/test_complete/output/fitresult/nottouser
if ($LASTEXITCODE -ne 0) {
docker rm -f $containerName 2>&1 | Out-Null
throw "Output directory nottouser not found"
}
# Verify output directories contain files (at least one file should exist)
$touserFiles = docker exec $containerName bash -c 'find /srv/test_complete/output/fitresult/touser -type f 2>/dev/null | wc -l'
if ([int]$touserFiles -le 0) {
docker rm -f $containerName 2>&1 | Out-Null
throw "No files found in touser output directory"
}
# Clean up test container
docker rm -f $containerName 2>&1 | Out-Null
}
# Summary
Write-Host ""
Write-TestHeader "Test Summary"
Write-Host "Passed: $script:TESTS_PASSED" -ForegroundColor Green
if ($script:TESTS_FAILED -gt 0) {
Write-Host "Failed: $script:TESTS_FAILED" -ForegroundColor Red
Cleanup
exit 1
} else {
Write-Host "Failed: $script:TESTS_FAILED" -ForegroundColor Green
Write-Host "`nAll tests passed!" -ForegroundColor Green
Cleanup
exit 0
}
-333
View File
@@ -1,333 +0,0 @@
#!/bin/bash
# Test script for PISCAL Docker image
# Verifies build, executable presence, and basic functionality
set -e # Exit on any error
IMAGE_NAME="piscal-server"
IMAGE_TAG="test"
TEST_CONTAINER="piscal-test-$$"
TEST_DIR=$(mktemp -d)
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Cleanup function
cleanup() {
echo -e "\n${YELLOW}Cleaning up...${NC}"
docker rm -f "$TEST_CONTAINER" 2>/dev/null || true
rm -rf "$TEST_DIR" 2>/dev/null || true
}
trap cleanup EXIT
# Test counter
TESTS_PASSED=0
TESTS_FAILED=0
# Test function
run_test() {
local test_name="$1"
echo -e "\n${YELLOW}Testing: $test_name${NC}"
if eval "$2"; then
echo -e "${GREEN}✓ PASS: $test_name${NC}"
((TESTS_PASSED++))
return 0
else
echo -e "${RED}✗ FAIL: $test_name${NC}"
((TESTS_FAILED++))
return 1
fi
}
echo "=========================================="
echo "PISCAL Docker Image Test Suite"
echo "=========================================="
# Test 1: Build verification
run_test "Docker image builds successfully" "
docker build -t ${IMAGE_NAME}:${IMAGE_TAG} . > /dev/null 2>&1
"
# Test 2: Executable check
run_test "PISCAL executable exists at /srv/piscal" "
docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} test -f /srv/piscal
"
run_test "PISCAL executable is executable" "
docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} test -x /srv/piscal
"
run_test "PISCAL executable can be executed (version check)" "
docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} /srv/piscal --help > /dev/null 2>&1 || \
docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} /srv/piscal 2>&1 | head -1 > /dev/null
"
# Test 3: Manager scripts check
run_test "piscal_manager.sh exists and is executable" "
docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} test -x /srv/piscal_manager.sh
"
run_test "piscal_launcher.sh exists and is executable" "
docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} test -x /srv/piscal_launcher.sh
"
run_test "piscal_launcher.cfg exists" "
docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} test -f /srv/piscal_launcher.cfg
"
run_test "subdir_year.sh exists and is executable" "
docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} test -x /srv/subdir_year.sh
"
# Test 4: SSH configuration
run_test "SSH server is installed" "
docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} which sshd > /dev/null
"
run_test "launcher user exists" "
docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} id launcher > /dev/null
"
run_test "launcher user is in sudo group" "
docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} groups launcher | grep -q sudo
"
run_test "/run/sshd directory exists" "
docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} test -d /run/sshd
"
# Test 5: Functional test with piscal_manager.sh - test all status states
run_test "piscal_manager.sh: Status 'not started' for new directory" "
docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} bash -c '
mkdir -p /srv/test_status/input
cd /srv
status=\$(bash piscal_manager.sh -d test_status 2>&1)
echo \"\$status\" | grep -q \"not started\"
'
"
run_test "piscal_manager.sh: Error handling - missing directory" "
docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} bash -c '
cd /srv
status=\$(bash piscal_manager.sh -d nonexistent_dir 2>&1)
echo \"\$status\" | grep -q \"not found\"
'
"
run_test "piscal_manager.sh: Error handling - missing input directory" "
docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} bash -c '
mkdir -p /srv/test_noinput
cd /srv
status=\$(bash piscal_manager.sh -d test_noinput 2>&1)
echo \"\$status\" | grep -q \"input directory.*not found\"
'
"
run_test "piscal_manager.sh: Launch job returns 'started' status" "
# Create test directory structure
mkdir -p \"${TEST_DIR}/input\"
cp \"${SCRIPT_DIR}/sample_data/LeafInput-valid.csv\" \"${TEST_DIR}/input/\"
# Start container with test data mounted
docker run -d --name \"${TEST_CONTAINER}\" \
-v \"${TEST_DIR}:/test\" \
${IMAGE_NAME}:${IMAGE_TAG} \
tail -f /dev/null > /dev/null 2>&1
# Wait for container to be ready
sleep 2
# Create working directory structure inside container (relative to /srv)
docker exec \"${TEST_CONTAINER}\" bash -c '
mkdir -p /srv/test_work/input
cp /test/input/*.csv /srv/test_work/input/ 2>/dev/null || true
'
# Launch job using piscal_manager.sh
result=\$(docker exec \"${TEST_CONTAINER}\" bash -c '
cd /srv
bash piscal_manager.sh -d test_work -p C3_photosynthesis_leafweb -s -t 2>&1
')
# Check for 'started' status
echo \"\$result\" | grep -q \"started\"
# Clean up test container
docker rm -f \"${TEST_CONTAINER}\" > /dev/null 2>&1 || true
"
run_test "piscal_manager.sh: Status 'running' while job is active" "
# Create test directory structure
mkdir -p \"${TEST_DIR}/input\"
cp \"${SCRIPT_DIR}/sample_data/LeafInput-valid.csv\" \"${TEST_DIR}/input/\"
# Start container with test data mounted
docker run -d --name \"${TEST_CONTAINER}\" \
-v \"${TEST_DIR}:/test\" \
${IMAGE_NAME}:${IMAGE_TAG} \
tail -f /dev/null > /dev/null 2>&1
# Wait for container to be ready
sleep 2
# Create working directory structure inside container (relative to /srv)
docker exec \"${TEST_CONTAINER}\" bash -c '
mkdir -p /srv/test_running/input
cp /test/input/*.csv /srv/test_running/input/ 2>/dev/null || true
'
# Launch job in background
docker exec \"${TEST_CONTAINER}\" bash -c '
cd /srv
bash piscal_manager.sh -d test_running -p C3_photosynthesis_leafweb -s -t > /dev/null 2>&1
' || true
# Wait a moment for job to start
sleep 1
# Check status (should be 'running' or 'complete' depending on speed)
status=\$(docker exec \"${TEST_CONTAINER}\" bash -c '
cd /srv
bash piscal_manager.sh -d test_running 2>&1 | head -1
')
# Status should be either 'running' or 'complete'
echo \"\$status\" | grep -qE \"^(running|complete)\$\"
# Clean up test container
docker rm -f \"${TEST_CONTAINER}\" > /dev/null 2>&1 || true
"
run_test "piscal_manager.sh: Cannot launch if already running" "
# Create test directory structure
mkdir -p \"${TEST_DIR}/input\"
cp \"${SCRIPT_DIR}/sample_data/LeafInput-valid.csv\" \"${TEST_DIR}/input/\"
# Start container with test data mounted
docker run -d --name \"${TEST_CONTAINER}\" \
-v \"${TEST_DIR}:/test\" \
${IMAGE_NAME}:${IMAGE_TAG} \
tail -f /dev/null > /dev/null 2>&1
# Wait for container to be ready
sleep 2
# Create working directory structure inside container (relative to /srv)
docker exec \"${TEST_CONTAINER}\" bash -c '
mkdir -p /srv/test_already/input
cp /test/input/*.csv /srv/test_already/input/ 2>/dev/null || true
'
# Create a fake running process by creating PID file with current shell PID
docker exec \"${TEST_CONTAINER}\" bash -c '
echo \$\$ > /srv/test_already/piscal.pid
'
# Try to launch - should fail with 'still running'
result=\$(docker exec \"${TEST_CONTAINER}\" bash -c '
cd /srv
bash piscal_manager.sh -d test_already -p C3_photosynthesis_leafweb -s -t 2>&1
' || echo \"still running\")
# Check for 'still running' status
echo \"\$result\" | grep -q \"still running\"
# Clean up test container
docker rm -f \"${TEST_CONTAINER}\" > /dev/null 2>&1 || true
"
run_test "piscal_manager.sh: Status 'complete' with output verification" "
# Create test directory structure
mkdir -p \"${TEST_DIR}/input\"
cp \"${SCRIPT_DIR}/sample_data/LeafInput-valid.csv\" \"${TEST_DIR}/input/\"
# Start container with test data mounted
docker run -d --name \"${TEST_CONTAINER}\" \
-v \"${TEST_DIR}:/test\" \
${IMAGE_NAME}:${IMAGE_TAG} \
tail -f /dev/null > /dev/null 2>&1
# Wait for container to be ready
sleep 2
# Create working directory structure inside container (relative to /srv)
docker exec \"${TEST_CONTAINER}\" bash -c '
mkdir -p /srv/test_complete/input
cp /test/input/*.csv /srv/test_complete/input/ 2>/dev/null || true
'
# Launch job using piscal_manager.sh
docker exec \"${TEST_CONTAINER}\" bash -c '
cd /srv
bash piscal_manager.sh -d test_complete -p C3_photosynthesis_leafweb -s -t > /dev/null 2>&1
' || true
# Wait for job to complete (with timeout) - use a script inside container
docker exec \"${TEST_CONTAINER}\" bash -c '
max_wait=120
wait_time=0
status=\"\"
while [ \$wait_time -lt \$max_wait ]; do
cd /srv
status=\$(bash piscal_manager.sh -d test_complete 2>&1 | head -1)
if echo \"\$status\" | grep -q \"complete\"; then
break
fi
if echo \"\$status\" | grep -q \"not started\"; then
sleep 2
wait_time=\$((wait_time + 2))
continue
fi
if echo \"\$status\" | grep -q \"running\"; then
sleep 5
wait_time=\$((wait_time + 5))
continue
fi
break
done
# Verify status is complete
echo \"\$status\" | grep -q \"complete\"
'
# Get full status output to verify output structure
full_output=\$(docker exec \"${TEST_CONTAINER}\" bash -c '
cd /srv
bash piscal_manager.sh -d test_complete 2>&1
')
# Verify output contains the expected markers
echo \"\$full_output\" | grep -q \"#touser\"
echo \"\$full_output\" | grep -q \"#clninput\"
echo \"\$full_output\" | grep -q \"#nottouser\"
# Verify output directories exist
docker exec \"${TEST_CONTAINER}\" test -d /srv/test_complete/output/fitresult/touser
docker exec \"${TEST_CONTAINER}\" test -d /srv/test_complete/output/clninput
docker exec \"${TEST_CONTAINER}\" test -d /srv/test_complete/output/fitresult/nottouser
# Verify output directories contain files (at least one file should exist)
touser_files=\$(docker exec \"${TEST_CONTAINER}\" bash -c 'find /srv/test_complete/output/fitresult/touser -type f 2>/dev/null | wc -l')
[ \"\$touser_files\" -gt 0 ]
# Clean up test container
docker rm -f \"${TEST_CONTAINER}\" > /dev/null 2>&1 || true
"
# Summary
echo ""
echo "=========================================="
echo "Test Summary"
echo "=========================================="
echo -e "${GREEN}Passed: ${TESTS_PASSED}${NC}"
if [ $TESTS_FAILED -gt 0 ]; then
echo -e "${RED}Failed: ${TESTS_FAILED}${NC}"
exit 1
else
echo -e "${GREEN}Failed: ${TESTS_FAILED}${NC}"
echo -e "\n${GREEN}All tests passed!${NC}"
exit 0
fi