Use swift package edit instead of CONTAINERIZATION_PATH. (#318)

- Closes #294.
This commit is contained in:
J Logan
2025-07-09 14:06:28 -07:00
committed by GitHub
parent 66a6974c6d
commit 7272328cf3
4 changed files with 36 additions and 36 deletions
+26 -21
View File
@@ -6,6 +6,9 @@ To build the `container` project, you need:
- macOS 15 minimum, macOS 26 beta recommended
- Xcode 26 beta
> [!IMPORTANT]
> There is a bug in the `vmnet` framework on macOS 26 beta that causes network creation to fail if the `container` helper applications are located under your `Documents` or `Desktop` directories. If you use `make install`, you can simply run the `container` binary in `/usr/local`. If you prefer to use the binaries that `make all` creates in your project `bin` and `libexec` directories, locate your project elsewhere, such as `~/projects/container`, until this issue is resolved.
## Compile and test
Build `container` and the background services from source, and run basic and integration tests:
@@ -38,58 +41,60 @@ to prepare your build environment.
2. In your development shell, go to the `container` project directory.
```
```bash
cd container
```
3. If the `container` services are already running, stop them.
```
```bash
bin/container system stop
```
4. Configure the environment variable `CONTAINERIZATION_PATH` to refer to your Containerization project, and update your `Package.resolved` file.
4. Use the Swift package manager to configure use your local `containerization` package and update your `Package.resolved` file.
```
export CONTAINERIZATION_PATH=../containerization
swift package update containerization
```bash
/usr/bin/swift package edit --path ../containerization containerization
/usr/bin/swift package update containerization
```
5. Build the init filesystem for your local copy of the Containerization project.
```
(cd ${CONTAINERIZATION_PATH} && make clean all)
```
6. Build `container`.
> [!IMPORTANT]
> If you are using Xcode, you will need to temporarily modify `Package.swift` instead of using `swift package edit`, using a path dependency in place of the versioned `container` dependency:
>
> ```swift
> .package(.path: "../containerization"),
> ```
5. Build `container`.
```
make clean all
```
7. Start the `container` services.
6. Restart the `container` services.
```
bin/container system stop
bin/container system start
```
To revert to using the Containerization dependency from your `Package.swift`:
1. Unset your `CONTAINERIZATION_PATH` environment variable, and update `Package.resolved`.
1. Use the Swift package manager to restore the normal `containerization` dependency and update your `Package.resolved` file. If you are using Xcode, revert your `Package.swift` change instead of using `swift package unedit`.
```
unset CONTAINERIZATION_PATH
swift package update containerization
```bash
/usr/bin/swift package unedit containerization
/usr/bin/swift package update containerization
```
2. Rebuild `container`.
```
```bash
make clean all
```
3. Restart the `container` services.
```
bin/container system restart
```bash
bin/container system stop
bin/container system start
```
+1 -1
View File
@@ -1,5 +1,5 @@
{
"originHash" : "912a08d7a8cc6a403ab02a8d236337b39276fa0d4f675ceb6d69d5d624af8a49",
"originHash" : "c8e7b05f9aa730fadfb17c6a44fd842dbb9e9ee978878284164250f61abc90a5",
"pins" : [
{
"identity" : "async-http-client",
+2 -11
View File
@@ -20,18 +20,9 @@
import Foundation
import PackageDescription
let scDependency: Package.Dependency
let scVersion: String
if let path = ProcessInfo.processInfo.environment["CONTAINERIZATION_PATH"] {
scDependency = .package(path: path)
scVersion = "latest"
} else {
scVersion = "0.3.0"
scDependency = .package(url: "https://github.com/apple/containerization.git", exact: Version(stringLiteral: scVersion))
}
let releaseVersion = ProcessInfo.processInfo.environment["RELEASE_VERSION"] ?? "0.0.0"
let gitCommit = ProcessInfo.processInfo.environment["GIT_COMMIT"] ?? "unspecified"
let scVersion = "0.3.0"
let builderShimVersion = "0.3.0"
let package = Package(
@@ -58,7 +49,7 @@ let package = Package(
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.20.1"),
.package(url: "https://github.com/orlandos-nl/DNSClient.git", from: "2.4.1"),
.package(url: "https://github.com/Bouke/DNS.git", from: "1.2.0"),
scDependency,
.package(url: "https://github.com/apple/containerization.git", exact: Version(stringLiteral: scVersion)),
],
targets: [
.executableTarget(
+7 -3
View File
@@ -18,9 +18,13 @@ IMAGE_NAME="vminit:latest"
DESTDIR="${1:-$(git rev-parse --show-toplevel)/bin}"
mkdir -p "${DESTDIR}"
CONTAINERIZATION_VERSION="${CONTAINERIZATION_VERSION:-$(${SWIFT} package show-dependencies --format json | jq -r '.dependencies[] | select(.identity == "containerization") | .version')}"
if [ ! -z "${CONTAINERIZATION_PATH}" -o "${CONTAINERIZATION_VERSION}" == "unspecified" ] ; then
CONTAINERIZATION_PATH="${CONTAINERIZATION_PATH:-$(${SWIFT} package show-dependencies --format json | jq -r '.dependencies[] | select(.identity == "containerization") | .path')}"
CONTAINERIZATION_VERSION="$(${SWIFT} package show-dependencies --format json | jq -r '.dependencies[] | select(.identity == "containerization") | .version')"
if [ "${CONTAINERIZATION_VERSION}" == "unspecified" ] ; then
CONTAINERIZATION_PATH="$(${SWIFT} package show-dependencies --format json | jq -r '.dependencies[] | select(.identity == "containerization") | .path')"
if [ ! -d "${CONTAINERIZATION_PATH}" ] ; then
echo "editable containerization directory at ${CONTAINERIZATION_PATH} does not exist"
exit 1
fi
echo "Creating InitImage"
make -C ${CONTAINERIZATION_PATH} init
${CONTAINERIZATION_PATH}/bin/cctl images save -o /tmp/init.tar ${IMAGE_NAME}