Skip to content

Commit 2909e02

Browse files
committed
Changed Implementation to Plugin as opposed to modifying the codebase
Build as a plugin Removed old compose folders to convert to plugin arch Deprecated tests removal ProgressBarTests are the only tests using XCTest -> Swift Testing Important fix to plugin config Fixed tests for Compose plugin
1 parent 6660fe6 commit 2909e02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1749
-1049
lines changed

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,21 @@ include Protobuf.Makefile
3939
.PHONY: all
4040
all: container
4141
all: init-block
42+
all: plugins
4243

4344
.PHONY: build
4445
build:
4546
@echo Building container binaries...
4647
@$(SWIFT) build -c $(BUILD_CONFIGURATION)
4748

49+
.PHONY: plugins
50+
plugins: plugin-compose
51+
52+
.PHONY: plugin-compose
53+
plugin-compose:
54+
@echo Building container-compose plugin...
55+
@cd Plugins/container-compose && $(SWIFT) build -c $(BUILD_CONFIGURATION)
56+
4857
.PHONY: container
4958
# Install binaries under project directory
5059
container: build
@@ -77,6 +86,7 @@ $(STAGING_DIR):
7786
@mkdir -p "$(join $(STAGING_DIR), libexec/container/plugins/container-runtime-linux/bin)"
7887
@mkdir -p "$(join $(STAGING_DIR), libexec/container/plugins/container-network-vmnet/bin)"
7988
@mkdir -p "$(join $(STAGING_DIR), libexec/container/plugins/container-core-images/bin)"
89+
@mkdir -p "$(join $(STAGING_DIR), libexec/container/plugins/container-compose/bin)"
8090

8191
@install "$(BUILD_BIN_DIR)/container" "$(join $(STAGING_DIR), bin/container)"
8292
@install "$(BUILD_BIN_DIR)/container-apiserver" "$(join $(STAGING_DIR), bin/container-apiserver)"
@@ -86,6 +96,10 @@ $(STAGING_DIR):
8696
@install config/container-network-vmnet-config.json "$(join $(STAGING_DIR), libexec/container/plugins/container-network-vmnet/config.json)"
8797
@install "$(BUILD_BIN_DIR)/container-core-images" "$(join $(STAGING_DIR), libexec/container/plugins/container-core-images/bin/container-core-images)"
8898
@install config/container-core-images-config.json "$(join $(STAGING_DIR), libexec/container/plugins/container-core-images/config.json)"
99+
@if [ -f "Plugins/container-compose/.build/$(BUILD_CONFIGURATION)/container-compose" ]; then \
100+
install "Plugins/container-compose/.build/$(BUILD_CONFIGURATION)/container-compose" "$(join $(STAGING_DIR), libexec/container/plugins/container-compose/bin/container-compose)"; \
101+
install "Plugins/container-compose/config.json" "$(join $(STAGING_DIR), libexec/container/plugins/container-compose/config.json)"; \
102+
fi
89103

90104
@echo Install uninstaller script
91105
@install scripts/uninstall-container.sh "$(join $(STAGING_DIR), bin/uninstall-container.sh)"
@@ -98,6 +112,9 @@ installer-pkg: $(STAGING_DIR)
98112
@codesign $(CODESIGN_OPTS) --prefix=com.apple.container. "$(join $(STAGING_DIR), libexec/container/plugins/container-core-images/bin/container-core-images)"
99113
@codesign $(CODESIGN_OPTS) --prefix=com.apple.container. --entitlements=signing/container-runtime-linux.entitlements "$(join $(STAGING_DIR), libexec/container/plugins/container-runtime-linux/bin/container-runtime-linux)"
100114
@codesign $(CODESIGN_OPTS) --prefix=com.apple.container. --entitlements=signing/container-network-vmnet.entitlements "$(join $(STAGING_DIR), libexec/container/plugins/container-network-vmnet/bin/container-network-vmnet)"
115+
@if [ -f "$(join $(STAGING_DIR), libexec/container/plugins/container-compose/bin/container-compose)" ]; then \
116+
codesign $(CODESIGN_OPTS) --prefix=com.apple.container. "$(join $(STAGING_DIR), libexec/container/plugins/container-compose/bin/container-compose)"; \
117+
fi
101118

102119
@echo Creating application installer
103120
@pkgbuild --root "$(STAGING_DIR)" --identifier com.apple.container-installer --install-location /usr/local --version ${RELEASE_VERSION} $(PKG_PATH)
@@ -192,3 +209,4 @@ clean:
192209
@rm -rf bin/ libexec/
193210
@rm -rf _site _serve
194211
@$(SWIFT) package clean
212+
@cd Plugins/container-compose && $(SWIFT) package clean 2>/dev/null || true

Package.resolved

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ let package = Package(
3939
.library(name: "ContainerPlugin", targets: ["ContainerPlugin"]),
4040
.library(name: "ContainerXPC", targets: ["ContainerXPC"]),
4141
.library(name: "SocketForwarder", targets: ["SocketForwarder"]),
42-
.library(name: "ContainerCompose", targets: ["ContainerCompose"]),
4342
],
4443
dependencies: [
4544
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
@@ -53,7 +52,6 @@ let package = Package(
5352
.package(url: "https://github.com/orlandos-nl/DNSClient.git", from: "2.4.1"),
5453
.package(url: "https://github.com/Bouke/DNS.git", from: "1.2.0"),
5554
.package(url: "https://github.com/apple/containerization.git", exact: Version(stringLiteral: scVersion)),
56-
.package(url: "https://github.com/jpsim/Yams.git", from: "5.0.0"),
5755
],
5856
targets: [
5957
.executableTarget(
@@ -71,7 +69,6 @@ let package = Package(
7169
"ContainerClient",
7270
"ContainerPlugin",
7371
"ContainerLog",
74-
"ContainerCompose",
7572
],
7673
path: "Sources/CLI"
7774
),
@@ -326,25 +323,5 @@ let package = Package(
326323
.define("BUILDER_SHIM_VERSION", to: "\"\(builderShimVersion)\""),
327324
]
328325
),
329-
.target(
330-
name: "ContainerCompose",
331-
dependencies: [
332-
.product(name: "Yams", package: "Yams"),
333-
.product(name: "Logging", package: "swift-log"),
334-
.product(name: "Containerization", package: "containerization"),
335-
.product(name: "ContainerizationOS", package: "containerization"),
336-
.product(name: "ArgumentParser", package: "swift-argument-parser"),
337-
"ContainerClient",
338-
"TerminalProgress",
339-
]
340-
),
341-
.testTarget(
342-
name: "ContainerComposeTests",
343-
dependencies: [
344-
"ContainerCompose",
345-
.product(name: "Containerization", package: "containerization"),
346-
.product(name: "Logging", package: "swift-log"),
347-
]
348-
),
349326
]
350327
)

Plugins/container-compose/BUILD.md

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# Building and Testing Container Compose Plugin
2+
3+
## Prerequisites
4+
5+
- macOS 15 or later
6+
- Swift 6.2 or later
7+
- Main container project dependencies
8+
9+
## Building
10+
11+
### From the main project root:
12+
13+
```bash
14+
# Build everything including the plugin
15+
make all
16+
17+
# Build only the compose plugin
18+
make plugin-compose
19+
20+
# Clean build
21+
make clean
22+
```
23+
24+
### From the plugin directory:
25+
26+
```bash
27+
cd Plugins/container-compose
28+
29+
# Build in debug mode
30+
swift build
31+
32+
# Build in release mode
33+
swift build -c release
34+
35+
# Run the plugin directly
36+
.build/debug/container-compose --help
37+
```
38+
39+
## Testing
40+
41+
### Run tests from plugin directory:
42+
43+
```bash
44+
cd Plugins/container-compose
45+
46+
# Run all tests
47+
swift test
48+
49+
# Run specific test
50+
swift test --filter ComposeParserTests
51+
52+
# Run with verbose output
53+
swift test --verbose
54+
```
55+
56+
### Manual testing:
57+
58+
1. Build the plugin:
59+
```bash
60+
swift build
61+
```
62+
63+
2. Test basic functionality:
64+
```bash
65+
# Validate a compose file
66+
.build/debug/container-compose validate -f test-compose.yml
67+
68+
# Show help
69+
.build/debug/container-compose --help
70+
.build/debug/container-compose up --help
71+
```
72+
73+
## Installation
74+
75+
### Via main project install:
76+
77+
```bash
78+
# From main project root
79+
make install
80+
```
81+
82+
This installs the plugin to: `/usr/local/libexec/container/plugins/container-compose/`
83+
84+
### Manual installation:
85+
86+
```bash
87+
# Build in release mode
88+
cd Plugins/container-compose
89+
swift build -c release
90+
91+
# Copy to plugin directory
92+
sudo mkdir -p /usr/local/libexec/container/plugins/container-compose/bin
93+
sudo cp .build/release/container-compose /usr/local/libexec/container/plugins/container-compose/bin/
94+
sudo cp config.json /usr/local/libexec/container/plugins/container-compose/
95+
```
96+
97+
## Integration Testing
98+
99+
After installation, test the plugin integration:
100+
101+
```bash
102+
# Should work through main container CLI
103+
container compose --help
104+
container compose up --help
105+
106+
# Create a test compose file
107+
cat > test-compose.yml << 'EOF'
108+
version: '3'
109+
services:
110+
web:
111+
image: nginx:alpine
112+
ports:
113+
- "8080:80"
114+
EOF
115+
116+
# Test compose commands
117+
container compose validate -f test-compose.yml
118+
container compose up -d -f test-compose.yml
119+
container compose ps -f test-compose.yml
120+
container compose down -f test-compose.yml
121+
```
122+
123+
## Troubleshooting
124+
125+
### Build Errors
126+
127+
1. **Missing dependencies**: Ensure the main container project is built first
128+
```bash
129+
cd ../..
130+
swift build
131+
```
132+
133+
2. **Swift version**: Check Swift version
134+
```bash
135+
swift --version
136+
```
137+
138+
3. **Clean build**: Try a clean build
139+
```bash
140+
swift package clean
141+
swift build
142+
```
143+
144+
### Runtime Errors
145+
146+
1. **Plugin not found**: Check installation path
147+
```bash
148+
ls -la /usr/local/libexec/container/plugins/container-compose/
149+
```
150+
151+
2. **Permission issues**: Ensure proper permissions
152+
```bash
153+
sudo chmod +x /usr/local/libexec/container/plugins/container-compose/bin/container-compose
154+
```
155+
156+
3. **Debug output**: Enable debug logging
157+
```bash
158+
container compose --debug up
159+
```
160+
161+
## Development Workflow
162+
163+
1. Make changes to the plugin code
164+
2. Build and test locally:
165+
```bash
166+
swift build && swift test
167+
```
168+
3. Test integration:
169+
```bash
170+
make -C ../.. plugin-compose
171+
sudo make -C ../.. install
172+
container compose --help
173+
```
174+
4. Submit changes via PR
175+
176+
## Notes
177+
178+
- The plugin uses a stub for ProgressBar to avoid dependencies on internal APIs
179+
- All compose functionality is self-contained in the plugin
180+
- The plugin can be developed and tested independently of the main project

0 commit comments

Comments
 (0)