Skip to content

Commit 7c063df

Browse files
Remove most uses of env variables for image registries (#100)
When we were testing the repo, we added authentication to most of the registry tests so that we could access private images. Now that the images are public, this PR removes the use of REGISTRY_TOKEN and REGISTRY_USERNAME in tests that no longer require authenticating. Note: REGISTRY_TOKEN, REGISTRY_USERNAME, and REGISTRY_HOST are still required in the CI to push images and for a few registry tests. So the env variables are not completely removed. The variables are only used in the test tool cctl and in our swift tests. Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
1 parent 5d2d7a1 commit 7c063df

File tree

3 files changed

+20
-41
lines changed

3 files changed

+20
-41
lines changed

Sources/Integration/Suite.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,6 @@ struct IntegrationSuite: AsyncParsableCommand {
5858
try! LocalContentStore(path: appRoot.appending(path: "content"))
5959
}()
6060

61-
private static var authentication: Authentication? {
62-
let env = ProcessInfo.processInfo.environment
63-
guard let password = env["REGISTRY_TOKEN"],
64-
let username = env["REGISTRY_USERNAME"]
65-
else {
66-
return nil
67-
}
68-
return BasicAuthentication(username: username, password: password)
69-
}
70-
7161
private static let _imageStore: ImageStore = {
7262
try! ImageStore(
7363
path: appRoot,
@@ -168,7 +158,7 @@ struct IntegrationSuite: AsyncParsableCommand {
168158
return try await store.get(reference: reference)
169159
} catch let error as ContainerizationError {
170160
if error.code == .notFound {
171-
return try await store.pull(reference: reference, auth: Self.authentication)
161+
return try await store.pull(reference: reference)
172162
}
173163
throw error
174164
}

Tests/ContainerizationOCITests/RegistryClientTests.swift

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,16 @@ struct OCIClientTests: ~Copyable {
9393
try await client.ping()
9494
}
9595

96-
@Test(.enabled(if: hasRegistryCredentials))
97-
func resolve() async throws {
98-
let client = RegistryClient(host: "ghcr.io", authentication: Self.authentication)
96+
@Test func resolve() async throws {
97+
let client = RegistryClient(host: "ghcr.io")
9998
let descriptor = try await client.resolve(name: "apple/containerization/dockermanifestimage", tag: "0.0.2")
10099
#expect(descriptor.mediaType == MediaTypes.dockerManifest)
101100
#expect(descriptor.size != 0)
102101
#expect(!descriptor.digest.isEmpty)
103102
}
104103

105-
@Test(.enabled(if: hasRegistryCredentials))
106-
func resolveSha() async throws {
107-
let client = RegistryClient(host: "ghcr.io", authentication: Self.authentication)
104+
@Test func resolveSha() async throws {
105+
let client = RegistryClient(host: "ghcr.io")
108106
let descriptor = try await client.resolve(
109107
name: "apple/containerization/dockermanifestimage", tag: "sha256:c8d344d228b7d9a702a95227438ec0d71f953a9a483e28ffabc5704f70d2b61e")
110108
let namedDescriptor = try await client.resolve(name: "apple/containerization/dockermanifestimage", tag: "0.0.2")
@@ -114,27 +112,24 @@ struct OCIClientTests: ~Copyable {
114112
#expect(!descriptor.digest.isEmpty)
115113
}
116114

117-
@Test(.enabled(if: hasRegistryCredentials))
118-
func fetchManifest() async throws {
119-
let client = RegistryClient(host: "ghcr.io", authentication: Self.authentication)
115+
@Test func fetchManifest() async throws {
116+
let client = RegistryClient(host: "ghcr.io")
120117
let descriptor = try await client.resolve(name: "apple/containerization/dockermanifestimage", tag: "0.0.2")
121118
let manifest: Manifest = try await client.fetch(name: "apple/containerization/dockermanifestimage", descriptor: descriptor)
122119
#expect(manifest.schemaVersion == 2)
123120
#expect(manifest.layers.count == 1)
124121
}
125122

126-
@Test(.enabled(if: hasRegistryCredentials))
127-
func fetchManifestAsData() async throws {
128-
let client = RegistryClient(host: "ghcr.io", authentication: Self.authentication)
123+
@Test func fetchManifestAsData() async throws {
124+
let client = RegistryClient(host: "ghcr.io")
129125
let descriptor = try await client.resolve(name: "apple/containerization/dockermanifestimage", tag: "0.0.2")
130126
let manifestData = try await client.fetchData(name: "apple/containerization/dockermanifestimage", descriptor: descriptor)
131127
let checksum = SHA256.hash(data: manifestData)
132128
#expect(descriptor.digest == checksum.digest)
133129
}
134130

135-
@Test(.enabled(if: hasRegistryCredentials))
136-
func fetchConfig() async throws {
137-
let client = RegistryClient(host: "ghcr.io", authentication: Self.authentication)
131+
@Test func fetchConfig() async throws {
132+
let client = RegistryClient(host: "ghcr.io")
138133
let descriptor = try await client.resolve(name: "apple/containerization/dockermanifestimage", tag: "0.0.2")
139134
let manifest: Manifest = try await client.fetch(name: "apple/containerization/dockermanifestimage", descriptor: descriptor)
140135
let image: Image = try await client.fetch(name: "apple/containerization/dockermanifestimage", descriptor: manifest.config)
@@ -143,9 +138,8 @@ struct OCIClientTests: ~Copyable {
143138
#expect(image.rootfs.diffIDs.count == 1)
144139
}
145140

146-
@Test(.enabled(if: hasRegistryCredentials))
147-
func fetchBlob() async throws {
148-
let client = RegistryClient(host: "ghcr.io", authentication: Self.authentication)
141+
@Test func fetchBlob() async throws {
142+
let client = RegistryClient(host: "ghcr.io")
149143
let descriptor = try await client.resolve(name: "apple/containerization/dockermanifestimage", tag: "0.0.2")
150144
let manifest: Manifest = try await client.fetch(name: "apple/containerization/dockermanifestimage", descriptor: descriptor)
151145
var called = false
@@ -274,12 +268,10 @@ struct OCIClientTests: ~Copyable {
274268
)
275269
}
276270

277-
@Test(.enabled(if: hasRegistryCredentials))
278-
func resolveWithRetry() async throws {
271+
@Test func resolveWithRetry() async throws {
279272
let counter = Mutex(0)
280273
let client = RegistryClient(
281274
host: "ghcr.io",
282-
authentication: Self.authentication,
283275
retryOptions: RetryOptions(
284276
maxRetries: 3,
285277
retryInterval: 500_000_000,

Tests/ContainerizationTests/ImageTests/ImageStoreImagePullTests.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import Testing
2525
@testable import Containerization
2626

2727
@Suite
28-
final class ImageStoreImagePullTests: ContainsAuth {
28+
final class ImageStoreImagePullTests {
2929
let store: ImageStore
3030
let dir: URL
3131
let contentStore: ContentStore
@@ -43,9 +43,8 @@ final class ImageStoreImagePullTests: ContainsAuth {
4343
try! FileManager.default.removeItem(at: self.dir)
4444
}
4545

46-
@Test(.enabled(if: hasRegistryCredentials))
47-
func testPullImageWithoutIndex() async throws {
48-
let img = try await self.store.pull(reference: "ghcr.io/apple/containerization/dockermanifestimage:0.0.2", auth: Self.authentication)
46+
@Test func testPullImageWithoutIndex() async throws {
47+
let img = try await self.store.pull(reference: "ghcr.io/apple/containerization/dockermanifestimage:0.0.2")
4948

5049
let rootDescriptor = img.descriptor
5150
let index: ContainerizationOCI.Index = try await contentStore.get(digest: rootDescriptor.digest)!
@@ -64,14 +63,13 @@ final class ImageStoreImagePullTests: ContainsAuth {
6463
}
6564

6665
@Test(
67-
.enabled(if: hasRegistryCredentials),
6866
arguments: [
6967
(Platform(arch: "arm64", os: "linux", variant: "v8"), imagePullArm64Layers),
7068
(Platform(arch: "amd64", os: "linux"), imagePullAmd64Layers),
7169
(nil, imagePullTestAllLayers),
7270
])
7371
func testPullSinglePlatform(platform: Platform?, expectLayers: [String]) async throws {
74-
let img = try await self.store.pull(reference: "ghcr.io/linuxcontainers/alpine:3.20", platform: platform, auth: Self.authentication)
72+
let img = try await self.store.pull(reference: "ghcr.io/linuxcontainers/alpine:3.20", platform: platform)
7573
let rootDescriptor = img.descriptor
7674
let index: ContainerizationOCI.Index = try await contentStore.get(digest: rootDescriptor.digest)!
7775
var foundMatch = false
@@ -98,11 +96,10 @@ final class ImageStoreImagePullTests: ContainsAuth {
9896
#expect(filesOnDisk == expectLayers)
9997
}
10098

101-
@Test(.enabled(if: hasRegistryCredentials))
102-
func testPullWithSha() async throws {
99+
@Test func testPullWithSha() async throws {
103100
let sha = "sha256:0a6a86d44d7f93c4f2b8dea7f0eee64e72cb98635398779f3610949632508d57"
104101
let r = "ghcr.io/linuxcontainers/alpine:3.20@\(sha)"
105-
let img = try await self.store.pull(reference: r, platform: .current, auth: Self.authentication)
102+
let img = try await self.store.pull(reference: r, platform: .current)
106103
#expect(img.descriptor.digest == sha)
107104
}
108105
}

0 commit comments

Comments
 (0)