pre remote host

This commit is contained in:
CaffeineFueled 2025-06-08 22:13:26 +02:00
parent 9569f90aba
commit 86d66717c1
6 changed files with 90 additions and 18 deletions

View file

@ -88,18 +88,48 @@ setup_data_directory() {
fi
}
# Check for .env file
check_env_file() {
if [ ! -f ".env" ]; then
print_warning ".env file not found"
print_status "Creating .env file from .env.example..."
if [ -f ".env.example" ]; then
cp .env.example .env
print_warning "Please edit .env file with your actual API keys before running the container"
print_status "You can edit .env now or the container will use example keys"
# Ask user if they want to edit now
read -p "Do you want to edit .env file now? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
${EDITOR:-nano} .env
fi
else
print_error ".env.example file not found. Cannot create .env file."
exit 1
fi
else
print_status ".env file found"
fi
}
# Run container
run_container() {
print_status "Starting container: ${CONTAINER_NAME}"
# Convert relative path to absolute path
#DATA_DIR_ABS=$(realpath "${DATA_DIR}")
DATA_DIR_ABS="/home/user/Documents/Dom.Decimal/30-Projects/30-Misc/30-00-ZeroOne/30-00-002-Work-FastAPI-REST-Endpoint/input"
DATA_DIR_ABS=$(realpath "${DATA_DIR}")
ENV_FILE_ABS=$(realpath ".env")
print_status "Mounting data directory: ${DATA_DIR_ABS}"
print_status "Mounting .env file: ${ENV_FILE_ABS}"
$CONTAINER_CMD run -d \
--name "${CONTAINER_NAME}" \
--publish "${HOST_PORT}:${CONTAINER_PORT}" \
--volume "${DATA_DIR_ABS}:/app/input:Z" \
--volume "${ENV_FILE_ABS}:/app/.env:ro,Z" \
--restart unless-stopped \
--security-opt no-new-privileges \
--cap-drop ALL \
@ -157,18 +187,19 @@ show_usage_info() {
print_status "API Documentation: http://localhost:${HOST_PORT}/docs"
print_status "Health Check: http://localhost:${HOST_PORT}/health"
echo
print_status "Authentication Tokens:"
echo " - Input Token: input_token_123"
echo " - Read Token: read_token_456"
print_status "API Key Configuration:"
echo " - Keys are loaded from .env file"
echo " - Separate keys for INPUT and READ operations"
echo " - Multiple keys supported per operation type"
echo
print_status "Example Usage:"
echo " # Send data:"
echo " # Send data (use any key from INPUT_API_KEYS):"
echo ' curl -X POST http://localhost:8000/api/run1/ \'
echo ' -H "Authorization: Bearer input_token_123" \'
echo ' -H "Authorization: Bearer <YOUR_INPUT_API_KEY>" \'
echo ' -d "host_a,is ok"'
echo
echo " # Read results:"
echo ' curl -H "Authorization: Bearer read_token_456" \'
echo " # Read results (use any key from READ_API_KEYS):"
echo ' curl -H "Authorization: Bearer <YOUR_READ_API_KEY>" \'
echo ' http://localhost:8000/results/run1/'
echo
print_status "Data Directory: ${DATA_DIR_ABS}"
@ -191,6 +222,7 @@ main() {
cleanup_existing_container
build_image
setup_data_directory
check_env_file
run_container
verify_container
show_usage_info