it builds, but does it run?
All checks were successful
Build Docker Image on Commit / build-and-publish (push) Successful in 16m30s

This commit is contained in:
Merith-TK 2025-07-04 22:27:34 +01:00
parent d93ecd2627
commit bfc790355a
10 changed files with 801 additions and 23 deletions

134
scripts/README.md Normal file
View file

@ -0,0 +1,134 @@
# FreeTAKServer Docker Scripts
This directory contains the scripts used by the FreeTAKServer Docker container. These scripts have been extracted from the Dockerfile for better maintainability and easier development.
## Scripts Overview
### `install_freetak.sh`
- **Purpose**: Installs FreeTAKServer using Ansible playbooks
- **Usage**: Called during Docker build process
- **Environment Variables**:
- `INSTALL_TYPE`: Installation type (latest, stable, legacy)
- `FTS_VENV`: Path to Python virtual environment
- `STABLE_FTS_VERSION`: Stable version number
- `LEGACY_FTS_VERSION`: Legacy version number
- `CFG_RPATH`: Configuration path
### `start_freetak.sh`
- **Purpose**: Simple startup script for FreeTAKServer
- **Usage**: Basic container startup (deprecated, use entrypoint.sh)
- **Environment Variables**:
- `FTS_VENV`: Path to Python virtual environment
- `CFG_RPATH`: Configuration path
### `entrypoint.sh`
- **Purpose**: Main entrypoint script with signal handling and logging
- **Usage**: Default container entrypoint
- **Features**:
- Graceful shutdown handling
- Proper signal forwarding
- Timestamped logging
- Dynamic configuration path detection
- Environment-based configuration
### `healthcheck.sh`
- **Purpose**: Health check script for Docker container
- **Usage**: Called by Docker healthcheck
- **Functionality**: Checks if FreeTAKServer process is running
### `dev-helper.sh`
- **Purpose**: Development helper script for validation and testing
- **Usage**: `./scripts/dev-helper.sh [validate|test|info|help]`
- **Features**:
- Script validation
- Syntax checking
- Information display
- Development workflow support
## Development Workflow
1. **Validate Scripts**: Ensure all scripts exist and are executable
```bash
./scripts/dev-helper.sh validate
```
2. **Test Syntax**: Check all scripts for syntax errors
```bash
./scripts/dev-helper.sh test
```
3. **View Information**: Display script information
```bash
./scripts/dev-helper.sh info
```
## Script Maintenance
### Adding New Scripts
1. Create the script in the `scripts/` directory
2. Make it executable: `chmod +x scripts/your-script.sh`
3. Add it to the Dockerfile `COPY` instruction
4. Update the `dev-helper.sh` script to include validation
### Modifying Existing Scripts
1. Edit the script file directly
2. Test syntax: `./scripts/dev-helper.sh test`
3. Rebuild the Docker image to apply changes
### Best Practices
- Always include proper error handling (`set -e`)
- Use descriptive variable names
- Add comments for complex logic
- Follow consistent formatting
- Test scripts before committing
## Environment Variables
The scripts use these key environment variables:
- `FTS_VENV`: Python virtual environment path (default: `/opt/fts.venv`)
- `INSTALL_TYPE`: Installation type - `latest`, `stable`, or `legacy`
- `CFG_RPATH`: Configuration path (auto-detected based on install type)
- `STABLE_FTS_VERSION`: Stable version number
- `LEGACY_FTS_VERSION`: Legacy version number
## Troubleshooting
### Script Not Executable
```bash
chmod +x scripts/script-name.sh
```
### Syntax Errors
```bash
bash -n scripts/script-name.sh
```
### Testing Individual Scripts
```bash
# Test in container context
docker run --rm -it freetak-server /bin/bash
# Then run: /opt/script-name.sh
```
### Debugging
Add `set -x` at the beginning of scripts to enable debug output.
## Integration with Dockerfile
The scripts are copied into the container during build:
```dockerfile
# Copy the scripts
COPY scripts/install_freetak.sh /opt/install_freetak.sh
COPY scripts/start_freetak.sh /opt/start_freetak.sh
COPY scripts/healthcheck.sh /opt/healthcheck.sh
COPY scripts/entrypoint.sh /opt/entrypoint.sh
# Make the scripts executable
RUN chmod +x /opt/*.sh
```
## License
These scripts are part of the FreeTAKServer Docker container project and follow the same licensing as the original FreeTAKHub-Installation project (Eclipse Public License 2.0).

160
scripts/dev-helper.sh Executable file
View file

@ -0,0 +1,160 @@
#!/bin/bash
# Development helper script for FreeTAKServer Docker container
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to check if script exists and is executable
check_script() {
local script_path="$1"
local script_name=$(basename "$script_path")
if [[ ! -f "$script_path" ]]; then
print_error "Script $script_name not found at $script_path"
return 1
fi
if [[ ! -x "$script_path" ]]; then
print_warning "Script $script_name is not executable, fixing..."
chmod +x "$script_path"
fi
print_success "Script $script_name is ready"
return 0
}
# Function to validate scripts
validate_scripts() {
print_status "Validating scripts..."
local scripts=(
"$PROJECT_DIR/scripts/install_freetak.sh"
"$PROJECT_DIR/scripts/start_freetak.sh"
"$PROJECT_DIR/scripts/healthcheck.sh"
"$PROJECT_DIR/scripts/entrypoint.sh"
)
local all_valid=true
for script in "${scripts[@]}"; do
if ! check_script "$script"; then
all_valid=false
fi
done
if [[ "$all_valid" == true ]]; then
print_success "All scripts are valid and executable"
else
print_error "Some scripts have issues"
exit 1
fi
}
# Function to test script syntax
test_syntax() {
print_status "Testing script syntax..."
local scripts=(
"$PROJECT_DIR/scripts/install_freetak.sh"
"$PROJECT_DIR/scripts/start_freetak.sh"
"$PROJECT_DIR/scripts/healthcheck.sh"
"$PROJECT_DIR/scripts/entrypoint.sh"
)
for script in "${scripts[@]}"; do
local script_name=$(basename "$script")
if bash -n "$script"; then
print_success "Syntax check passed for $script_name"
else
print_error "Syntax check failed for $script_name"
exit 1
fi
done
}
# Function to show script information
show_info() {
print_status "FreeTAKServer Docker Scripts Information"
echo
echo "Scripts directory: $PROJECT_DIR/scripts/"
echo
echo "Available scripts:"
echo " install_freetak.sh - Installs FreeTAKServer using Ansible"
echo " start_freetak.sh - Simple startup script"
echo " entrypoint.sh - Main entrypoint with signal handling"
echo " healthcheck.sh - Health check script"
echo
echo "Usage in Dockerfile:"
echo " COPY scripts/ /opt/scripts/"
echo " RUN chmod +x /opt/scripts/*.sh"
echo
}
# Function to show usage
usage() {
echo "Usage: $0 [COMMAND]"
echo
echo "Commands:"
echo " validate Validate all scripts exist and are executable"
echo " test Test script syntax"
echo " info Show information about scripts"
echo " help Show this help message"
echo
echo "If no command is provided, 'validate' is run by default."
}
# Main script logic
main() {
case "${1:-validate}" in
validate)
validate_scripts
;;
test)
validate_scripts
test_syntax
;;
info)
show_info
;;
help|--help|-h)
usage
;;
*)
print_error "Unknown command: $1"
usage
exit 1
;;
esac
}
# Change to project directory
cd "$PROJECT_DIR"
# Run main function
main "$@"

68
scripts/entrypoint.sh Executable file
View file

@ -0,0 +1,68 @@
#!/bin/bash
set -e
# Function to log messages with timestamp
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
}
# Function to handle signals for graceful shutdown
cleanup() {
log "Received shutdown signal, stopping FreeTAKServer..."
if [ -n "$FTS_PID" ]; then
kill -TERM "$FTS_PID" 2>/dev/null || true
wait "$FTS_PID" 2>/dev/null || true
fi
log "FreeTAKServer stopped"
exit 0
}
# Set up signal handlers
trap cleanup SIGTERM SIGINT
# Source the virtual environment
log "Activating Python virtual environment..."
source ${FTS_VENV}/bin/activate
# Set up environment variables based on install type
case ${INSTALL_TYPE} in
legacy)
export CFG_RPATH=controllers/configuration
log "Using legacy configuration path: ${CFG_RPATH}"
;;
*)
export CFG_RPATH=core/configuration
log "Using standard configuration path: ${CFG_RPATH}"
;;
esac
# Change to the configuration directory
CONFIG_DIR="/opt/FreeTAKHub-Installation/${CFG_RPATH}"
if [ -d "$CONFIG_DIR" ]; then
log "Changing to configuration directory: $CONFIG_DIR"
cd "$CONFIG_DIR"
else
log "WARNING: Configuration directory not found at $CONFIG_DIR"
log "Attempting to start from FreeTAKHub-Installation root..."
cd /opt/FreeTAKHub-Installation
fi
# Start FreeTAKServer
log "Starting FreeTAKServer (Install Type: ${INSTALL_TYPE})..."
log "Python version: $(python3 --version)"
log "Working directory: $(pwd)"
# Start the service in the background to allow signal handling
python3 -m FreeTAKServer.controllers.services.FTS &
FTS_PID=$!
log "FreeTAKServer started with PID: $FTS_PID"
log "FreeTAKServer is running. Use Ctrl+C to stop."
# Wait for the background process
wait "$FTS_PID"
# Deactivate virtual environment
deactivate
log "FreeTAKServer has stopped"

4
scripts/healthcheck.sh Executable file
View file

@ -0,0 +1,4 @@
#!/bin/bash
# Simple healthcheck - check if the FTS process is running
pgrep -f "FreeTAKServer" > /dev/null
exit $?

49
scripts/install_freetak.sh Executable file
View file

@ -0,0 +1,49 @@
#!/bin/bash
set -e
# Source the virtual environment
source ${FTS_VENV}/bin/activate
# Set up environment variables
export CODENAME=jammy
export INSTALL_TYPE=${INSTALL_TYPE:-latest}
export FTS_VERSION=${STABLE_FTS_VERSION}
export PY3_VER=${PY3_VER}
export CFG_RPATH=${CFG_RPATH}
export FTS_VENV=${FTS_VENV}
# Determine FTS version based on install type
case ${INSTALL_TYPE} in
latest)
export FTS_VERSION=$(curl -s https://pypi.org/pypi/FreeTAKServer/json | python3 -c "import sys, json; print(json.load(sys.stdin)[\"info\"][\"version\"])" 2>/dev/null || echo "${STABLE_FTS_VERSION}")
;;
stable)
export FTS_VERSION=${STABLE_FTS_VERSION}
;;
legacy)
export FTS_VERSION=${LEGACY_FTS_VERSION}
export PY3_VER=3.8
export CFG_RPATH=controllers/configuration
;;
esac
# Set up Ansible variables
env_vars="python3_version=${PY3_VER} codename=${CODENAME} itype=${INSTALL_TYPE}"
env_vars="${env_vars} fts_version=${FTS_VERSION} cfg_rpath=${CFG_RPATH} fts_venv=${FTS_VENV}"
env_vars="${env_vars} webmap_force_install=true"
# Run Ansible playbook
cd /opt/FreeTAKHub-Installation
echo "Installing FreeTAKServer with the following settings:"
echo " Version: ${FTS_VERSION}"
echo " Python: ${PY3_VER}"
echo " Install Type: ${INSTALL_TYPE}"
echo " Virtual Environment: ${FTS_VENV}"
ansible-playbook -u root install_all.yml \
--connection=local \
--inventory localhost, \
--extra-vars "${env_vars}" \
-v
deactivate

14
scripts/start_freetak.sh Executable file
View file

@ -0,0 +1,14 @@
#!/bin/bash
set -e
# Source the virtual environment
source ${FTS_VENV}/bin/activate
# Change to the configuration directory
cd /opt/FreeTAKHub-Installation/${CFG_RPATH}
# Start FreeTAKServer
echo "Starting FreeTAKServer..."
python3 -m FreeTAKServer.controllers.services.FTS
deactivate