-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-lib.sh
More file actions
executable file
·103 lines (87 loc) · 3.08 KB
/
docker-lib.sh
File metadata and controls
executable file
·103 lines (87 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env bash
#
# docker-lib.sh - Common Functions Library for Docker Maintainer
# BACKWARD COMPATIBILITY FACADE - Sources all modules
#
# NOTE: This file is maintained for backward compatibility.
# The library has been split into 3 focused modules for better maintainability:
# docker-lib-core.sh - Core utilities (output, logging, formatting)
# docker-lib-safety.sh - Safety checks, config, audit logging
# docker-lib-resources.sh - Docker API, metadata, templates
#
# New scripts should source specific modules directly, but existing scripts
# can continue to source this facade file which loads all modules.
#
# Version: 2.0.0 (Library Split - Phase 2)
# Requires: bash 4.0+, docker, jq, coreutils
#
set -euo pipefail
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Source all modules in correct order
# 1. Core module (no dependencies)
source "$SCRIPT_DIR/docker-lib-core.sh"
# 2. Safety module (depends on core)
source "$SCRIPT_DIR/docker-lib-safety.sh"
# 3. Resources module (depends on core + safety)
source "$SCRIPT_DIR/docker-lib-resources.sh"
#######################################
# Display usage information about the library split
# Globals:
# None
# Arguments:
# None
# Returns:
# 0 always
# Outputs:
# Usage information to stdout
#######################################
usage() {
cat << EOF
Docker Maintainer - Common Functions Library (v2.0.0)
This library has been split into 3 focused modules for better maintainability:
docker-lib-core.sh (~839 lines)
- Core utilities: output, logging, formatting, validation
- Color definitions and constants
- No dependencies (standalone)
docker-lib-safety.sh (~1069 lines)
- Safety checks: volume/image/container protection
- Configuration management and validation
- Audit logging and pattern matching
- Depends on: docker-lib-core.sh
docker-lib-resources.sh (~607 lines)
- Docker API wrappers and resource operations
- Metadata extraction callbacks
- Template Method Pattern (scan_resources_generic)
- Depends on: docker-lib-core.sh, docker-lib-safety.sh
USAGE (Backward Compatible):
Existing scripts can continue to source docker-lib.sh:
source "\$SCRIPT_DIR/docker-lib.sh"
USAGE (Recommended for new scripts):
Source only the modules you need:
source "\$SCRIPT_DIR/docker-lib-core.sh"
source "\$SCRIPT_DIR/docker-lib-safety.sh"
source "\$SCRIPT_DIR/docker-lib-resources.sh"
MODULE DETAILS:
Total Functions: 67
- Core module: 31 functions
- Safety module: 19 functions
- Resources module: 16 functions
- Template method: 1 function (scan_resources_generic)
BENEFITS:
✓ Easier to navigate (smaller files)
✓ Clear module boundaries
✓ Reduced merge conflicts
✓ Better code organization
✓ Scripts can source only needed modules (future optimization)
For more information, see:
- README.md
- CLAUDE.md (project instructions)
- specs/refactor-code-quality-and-library-split.md
EOF
}
# If script is run directly, show usage
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
usage
exit 0
fi