Skip to content

Commit c1b2bc9

Browse files
Merge branch 'main' into add-custom-routes
2 parents 4532d48 + 0177505 commit c1b2bc9

File tree

4 files changed

+98
-11
lines changed

4 files changed

+98
-11
lines changed

Protobuf.Makefile

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1+
# Copyright © 2025 Apple Inc. and the Containerization project authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
LOCAL_DIR := $(ROOT_DIR)/.local
2-
LOCALBIN := $(LOCAL_DIR)/bin
16+
LOCAL_BIN_DIR := $(LOCAL_DIR)/bin
317

4-
## Versions
5-
PROTOC_VERSION=26.1
18+
# Versions
19+
PROTOC_VERSION := 26.1
620

7-
# protoc binary installation
8-
PROTOC_ZIP = protoc-$(PROTOC_VERSION)-osx-universal_binary.zip
9-
PROTOC = $(LOCALBIN)/protoc@$(PROTOC_VERSION)/protoc
21+
# Protoc binary installation
22+
PROTOC_ZIP := protoc-$(PROTOC_VERSION)-osx-universal_binary.zip
23+
PROTOC := $(LOCAL_BIN_DIR)/protoc@$(PROTOC_VERSION)/protoc
1024
$(PROTOC):
1125
@echo Downloading protocol buffers...
1226
@mkdir -p $(LOCAL_DIR)
@@ -16,14 +30,13 @@ $(PROTOC):
1630
@unzip -o $(PROTOC_ZIP) 'include/*' -d $(dir $@)
1731
@rm -f $(PROTOC_ZIP)
1832

19-
protoc_gen_grpc_swift:
20-
swift build --product protoc-gen-grpc-swift
21-
33+
.PHONY: protoc-gen-swift
2234
protoc-gen-swift:
23-
swift build --product protoc-gen-swift
35+
@$(SWIFT) build --product protoc-gen-swift
36+
@$(SWIFT) build --product protoc-gen-grpc-swift
2437

2538
.PHONY: protos
26-
protos: $(PROTOC) protoc_gen_grpc_swift protoc-gen-swift
39+
protos: $(PROTOC) protoc-gen-swift
2740
@echo Generating protocol buffers source code...
2841
@$(PROTOC) Sources/Containerization/SandboxContext/SandboxContext.proto \
2942
--plugin=protoc-gen-grpc-swift=$(BUILD_BIN_DIR)/protoc-gen-grpc-swift \
@@ -35,3 +48,8 @@ protos: $(PROTOC) protoc_gen_grpc_swift protoc-gen-swift
3548
--swift_opt=Visibility=Public \
3649
-I.
3750
@"$(MAKE)" update-licenses
51+
52+
.PHONY: clean-proto-tools
53+
clean-proto-tools:
54+
@echo Cleaning proto tools...
55+
@rm -rf $(LOCAL_DIR)/bin/protoc*

Sources/Integration/ContainerTests.swift

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,73 @@ extension IntegrationSuite {
930930
}
931931
}
932932

933+
func testUnixSocketIntoGuest() async throws {
934+
let id = "test-unixsocket-into-guest"
935+
936+
let bs = try await bootstrap(id)
937+
938+
let hostSocketPath = try createHostUnixSocket()
939+
940+
let buffer = BufferWriter()
941+
let container = try LinuxContainer(id, rootfs: bs.rootfs, vmm: bs.vmm) { config in
942+
config.process.arguments = ["sleep", "100"]
943+
config.sockets = [
944+
UnixSocketConfiguration(
945+
source: URL(filePath: hostSocketPath),
946+
destination: URL(filePath: "/tmp/test.sock"),
947+
direction: .into
948+
)
949+
]
950+
config.bootlog = bs.bootlog
951+
}
952+
953+
do {
954+
try await container.create()
955+
try await container.start()
956+
957+
// Execute ls -l to check the socket exists and is indeed a socket
958+
let lsExec = try await container.exec("ls-socket") { config in
959+
config.arguments = ["ls", "-l", "/tmp/test.sock"]
960+
config.stdout = buffer
961+
}
962+
963+
try await lsExec.start()
964+
let status = try await lsExec.wait()
965+
try await lsExec.delete()
966+
967+
guard status.exitCode == 0 else {
968+
throw IntegrationError.assert(msg: "ls command failed with status \(status)")
969+
}
970+
971+
guard let output = String(data: buffer.data, encoding: .utf8) else {
972+
throw IntegrationError.assert(msg: "failed to convert ls output to UTF8")
973+
}
974+
975+
// Socket files in ls -l output start with 's'
976+
guard output.hasPrefix("s") else {
977+
throw IntegrationError.assert(
978+
msg: "expected socket file (starting with 's'), got: \(output)")
979+
}
980+
981+
try await container.kill(SIGKILL)
982+
try await container.wait()
983+
try await container.stop()
984+
} catch {
985+
try? await container.stop()
986+
throw error
987+
}
988+
}
989+
990+
private func createHostUnixSocket() throws -> String {
991+
let dir = FileManager.default.uniqueTemporaryDirectory(create: true)
992+
let socketPath = dir.appendingPathComponent("test.sock").path
993+
994+
let socket = try Socket(type: UnixType(path: socketPath))
995+
try socket.listen()
996+
997+
return socketPath
998+
}
999+
9331000
private func createMountDirectory() throws -> URL {
9341001
let dir = FileManager.default.uniqueTemporaryDirectory(create: true)
9351002
try "hello".write(to: dir.appendingPathComponent("hi.txt"), atomically: true, encoding: .utf8)

Sources/Integration/Suite.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ struct IntegrationSuite: AsyncParsableCommand {
293293
Test("container statistics", testContainerStatistics),
294294
Test("container cgroup limits", testCgroupLimits),
295295
Test("container no serial console", testNoSerialConsole),
296+
Test("unix socket into guest", testUnixSocketIntoGuest),
296297

297298
// Pods
298299
Test("pod single container", testPodSingleContainer),

licenserc.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ headerPath = "scripts/license-header.txt"
44

55
includes = [
66
"Makefile",
7+
"*.Makefile",
78
"*.swift",
89
"*.h",
910
"*.cpp",

0 commit comments

Comments
 (0)