|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -import {describe, expect, test} from '@jest/globals'; |
| 17 | +import {afterEach, beforeEach, describe, expect, it, jest, test} from '@jest/globals'; |
18 | 18 | import * as fs from 'fs'; |
19 | 19 | import * as path from 'path'; |
20 | 20 |
|
@@ -147,3 +147,52 @@ maybe('exportBuild', () => { |
147 | 147 | expect(exportRes?.summaries).toBeDefined(); |
148 | 148 | }); |
149 | 149 | }); |
| 150 | + |
| 151 | +maybe('exportBuild custom image', () => { |
| 152 | + const originalEnv = process.env; |
| 153 | + beforeEach(() => { |
| 154 | + jest.resetModules(); |
| 155 | + process.env = { |
| 156 | + ...originalEnv, |
| 157 | + DOCKER_BUILD_EXPORT_BUILD_IMAGE: 'docker.io/dockereng/export-build:0.2.2' |
| 158 | + }; |
| 159 | + }); |
| 160 | + afterEach(() => { |
| 161 | + process.env = originalEnv; |
| 162 | + }); |
| 163 | + |
| 164 | + it('with custom image', async () => { |
| 165 | + const buildx = new Buildx(); |
| 166 | + const build = new Build({buildx: buildx}); |
| 167 | + |
| 168 | + fs.mkdirSync(tmpDir, {recursive: true}); |
| 169 | + await expect( |
| 170 | + (async () => { |
| 171 | + // prettier-ignore |
| 172 | + const buildCmd = await buildx.getCommand([ |
| 173 | + '--builder', process.env.CTN_BUILDER_NAME ?? 'default', |
| 174 | + 'build', '-f', path.join(fixturesDir, 'hello.Dockerfile'), |
| 175 | + '--metadata-file', build.getMetadataFilePath(), |
| 176 | + fixturesDir |
| 177 | + ]); |
| 178 | + await Exec.exec(buildCmd.command, buildCmd.args); |
| 179 | + })() |
| 180 | + ).resolves.not.toThrow(); |
| 181 | + |
| 182 | + const metadata = build.resolveMetadata(); |
| 183 | + expect(metadata).toBeDefined(); |
| 184 | + const buildRef = build.resolveRef(metadata); |
| 185 | + expect(buildRef).toBeDefined(); |
| 186 | + |
| 187 | + const history = new History({buildx: buildx}); |
| 188 | + const exportRes = await history.export({ |
| 189 | + refs: [buildRef ?? ''] |
| 190 | + }); |
| 191 | + |
| 192 | + expect(exportRes).toBeDefined(); |
| 193 | + expect(exportRes?.dockerbuildFilename).toBeDefined(); |
| 194 | + expect(exportRes?.dockerbuildSize).toBeDefined(); |
| 195 | + expect(fs.existsSync(exportRes?.dockerbuildFilename)).toBe(true); |
| 196 | + expect(exportRes?.summaries).toBeDefined(); |
| 197 | + }); |
| 198 | +}); |
0 commit comments