|
| 1 | +import { spawnSync } from 'child_process'; |
1 | 2 | import * as fs from 'fs';
|
2 | 3 | import * as path from 'path';
|
3 | 4 | import { Template } from '../../assertions';
|
4 | 5 | import * as iam from '../../aws-iam';
|
5 | 6 | import * as cxschema from '../../cloud-assembly-schema';
|
6 | 7 | import { App, Stack, DefaultStackSynthesizer } from '../../core';
|
7 | 8 | import * as cxapi from '../../cx-api';
|
8 |
| -import { TarballImageAsset } from '../lib'; |
| 9 | +import { TarballImageAsset, DOCKER_LOAD_OUTPUT_REGEX } from '../lib'; |
9 | 10 |
|
10 | 11 | /* eslint-disable quote-props */
|
11 | 12 |
|
@@ -42,7 +43,7 @@ describe('image asset', () => {
|
42 | 43 | executable: [
|
43 | 44 | 'sh',
|
44 | 45 | '-c',
|
45 |
| - `docker load -i asset.${asset.assetHash}.tar | tail -n 1 | sed "s/Loaded image: //g"`, |
| 46 | + `docker load -i asset.${asset.assetHash}.tar | tail -n 1 | sed "${DOCKER_LOAD_OUTPUT_REGEX}"`, |
46 | 47 | ],
|
47 | 48 | },
|
48 | 49 | );
|
@@ -160,6 +161,36 @@ describe('image asset', () => {
|
160 | 161 | expect(asset2.imageTag).toEqual('banana95c924c84f5d023be4edee540cb2cb401a49f115d01ed403b288f6cb412771df');
|
161 | 162 | });
|
162 | 163 | });
|
| 164 | + test('docker load output format handling', () => { |
| 165 | + // Test that our sed expression can handle both old and new Docker output formats |
| 166 | + const oldFormatOutput = 'Loaded image: sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a'; |
| 167 | + const newFormatOutput = 'Loaded image ID: sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a'; |
| 168 | + |
| 169 | + // Test old format (Loaded image: sha256:...) |
| 170 | + const oldFormatResult = spawnSync('sh', [ |
| 171 | + '-c', |
| 172 | + `echo "${oldFormatOutput}" | sed "${DOCKER_LOAD_OUTPUT_REGEX}"`, |
| 173 | + ]); |
| 174 | + expect(oldFormatResult.status).toBe(0); |
| 175 | + expect(oldFormatResult.stdout.toString().trim()).toBe('sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a'); |
| 176 | + |
| 177 | + // Test new format (Loaded image ID: sha256:...) |
| 178 | + const newFormatResult = spawnSync('sh', [ |
| 179 | + '-c', |
| 180 | + `echo "${newFormatOutput}" | sed "${DOCKER_LOAD_OUTPUT_REGEX}"`, |
| 181 | + ]); |
| 182 | + expect(newFormatResult.status).toBe(0); |
| 183 | + expect(newFormatResult.stdout.toString().trim()).toBe('sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a'); |
| 184 | + |
| 185 | + // Test that the old sed expression fails with the new format |
| 186 | + const oldSedWithNewFormat = spawnSync('sh', [ |
| 187 | + '-c', |
| 188 | + `echo "${newFormatOutput}" | sed "s/Loaded image: //g"`, |
| 189 | + ]); |
| 190 | + expect(oldSedWithNewFormat.status).toBe(0); |
| 191 | + expect(oldSedWithNewFormat.stdout.toString().trim()).not.toBe('sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a'); |
| 192 | + expect(oldSedWithNewFormat.stdout.toString().trim()).toBe('Loaded image ID: sha256:4a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a'); |
| 193 | + }); |
163 | 194 | });
|
164 | 195 |
|
165 | 196 | function isAssetManifest(x: cxapi.CloudArtifact): x is cxapi.AssetManifestArtifact {
|
|
0 commit comments