|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -import { buildkitBuild, BuildkitBuildOptions, generateSecretArgsScript } from '../engines'; |
| 17 | +import { buildkitBuild, NativeBuildOptions, generateSecretArgsScript } from '../engines'; |
18 | 18 | import { shellPromise } from '../../shell'; |
19 | 19 | import { waitForJobAndGetLogs, getGitHubToken } from '../utils'; |
20 | 20 | import GlobalConfigService from '../../../services/globalConfig'; |
@@ -68,7 +68,7 @@ describe('buildkitBuild', () => { |
68 | 68 | build: { isStatic: false }, |
69 | 69 | } as any; |
70 | 70 |
|
71 | | - const mockOptions: BuildkitBuildOptions = { |
| 71 | + const mockOptions: NativeBuildOptions = { |
72 | 72 | ecrRepo: 'test-repo', |
73 | 73 | ecrDomain: '123456789.dkr.ecr.us-east-1.amazonaws.com', |
74 | 74 | envVars: { NODE_ENV: 'production' }, |
@@ -247,6 +247,35 @@ describe('buildkitBuild', () => { |
247 | 247 | expect(fullCommand).toContain('build-arg:NODE_ENV=production'); |
248 | 248 | }); |
249 | 249 |
|
| 250 | + it('keeps registry bootstrap installs default and adds AWS retry env vars', async () => { |
| 251 | + await buildkitBuild(mockDeploy, mockOptions); |
| 252 | + |
| 253 | + const kubectlCalls = (shellPromise as jest.Mock).mock.calls; |
| 254 | + const applyCall = kubectlCalls.find((call) => call[0].includes('kubectl apply')); |
| 255 | + const fullCommand = applyCall[0]; |
| 256 | + |
| 257 | + expect(fullCommand).toContain('apk add --no-cache aws-cli docker-cli'); |
| 258 | + expect(fullCommand).toContain('apk add --no-cache docker-cli'); |
| 259 | + expect(fullCommand).toContain('export AWS_MAX_ATTEMPTS=5'); |
| 260 | + expect(fullCommand).toContain('export AWS_RETRY_MODE=adaptive'); |
| 261 | + }); |
| 262 | + |
| 263 | + it('renders registry domain safely for non-ECR buildkit targets', async () => { |
| 264 | + const optionsWithCustomRegistry = { |
| 265 | + ...mockOptions, |
| 266 | + ecrDomain: 'registry.internal.svc.cluster.local', |
| 267 | + }; |
| 268 | + |
| 269 | + await buildkitBuild(mockDeploy, optionsWithCustomRegistry); |
| 270 | + |
| 271 | + const kubectlCalls = (shellPromise as jest.Mock).mock.calls; |
| 272 | + const applyCall = kubectlCalls.find((call) => call[0].includes('kubectl apply')); |
| 273 | + const fullCommand = applyCall[0]; |
| 274 | + |
| 275 | + expect(fullCommand).toContain('REGISTRY_DOMAIN=\\"registry.internal.svc.cluster.local\\"'); |
| 276 | + expect(fullCommand).toContain('apk add --no-cache docker-cli'); |
| 277 | + }); |
| 278 | + |
250 | 279 | it('coerces numeric env var values to strings for Kubernetes compatibility', async () => { |
251 | 280 | const optionsWithNumericEnv = { |
252 | 281 | ...mockOptions, |
@@ -320,7 +349,7 @@ describe('build resource precedence', () => { |
320 | 349 | build: { isStatic: false }, |
321 | 350 | } as any; |
322 | 351 |
|
323 | | - const baseOptions: BuildkitBuildOptions = { |
| 352 | + const baseOptions: NativeBuildOptions = { |
324 | 353 | ecrRepo: 'test-repo', |
325 | 354 | ecrDomain: '123456789.dkr.ecr.us-east-1.amazonaws.com', |
326 | 355 | envVars: { NODE_ENV: 'production' }, |
@@ -495,7 +524,7 @@ describe('build pod annotations', () => { |
495 | 524 | build: { isStatic: false }, |
496 | 525 | } as any; |
497 | 526 |
|
498 | | - const baseOptions: BuildkitBuildOptions = { |
| 527 | + const baseOptions: NativeBuildOptions = { |
499 | 528 | ecrRepo: 'test-repo', |
500 | 529 | ecrDomain: '123456789.dkr.ecr.us-east-1.amazonaws.com', |
501 | 530 | envVars: { NODE_ENV: 'production' }, |
@@ -655,3 +684,69 @@ describe('generateSecretArgsScript', () => { |
655 | 684 | expect(result).toContain('--opt build-arg:MY_SECRET='); |
656 | 685 | }); |
657 | 686 | }); |
| 687 | + |
| 688 | +describe('kaniko registry login bootstrap', () => { |
| 689 | + const mockDeploy = { |
| 690 | + deployable: { name: 'test-service' }, |
| 691 | + $fetchGraph: jest.fn(), |
| 692 | + build: { isStatic: false }, |
| 693 | + } as any; |
| 694 | + |
| 695 | + const baseOptions: NativeBuildOptions = { |
| 696 | + ecrRepo: 'test-repo', |
| 697 | + ecrDomain: '123456789.dkr.ecr.us-east-1.amazonaws.com', |
| 698 | + envVars: { NODE_ENV: 'production' }, |
| 699 | + dockerfilePath: 'Dockerfile', |
| 700 | + tag: 'v1.0.0', |
| 701 | + revision: 'abc123def456789', |
| 702 | + repo: 'owner/repo', |
| 703 | + branch: 'main', |
| 704 | + namespace: 'env-test-123', |
| 705 | + buildId: '456', |
| 706 | + deployUuid: 'test-service-abc123', |
| 707 | + jobTimeout: 1800, |
| 708 | + }; |
| 709 | + |
| 710 | + beforeEach(() => { |
| 711 | + jest.clearAllMocks(); |
| 712 | + (GlobalConfigService.getInstance as jest.Mock).mockReturnValue({ |
| 713 | + getAllConfigs: jest.fn().mockResolvedValue({}), |
| 714 | + }); |
| 715 | + (getGitHubToken as jest.Mock).mockResolvedValue('github-token-123'); |
| 716 | + (shellPromise as jest.Mock).mockResolvedValue(''); |
| 717 | + (waitForJobAndGetLogs as jest.Mock).mockResolvedValue({ |
| 718 | + logs: 'Build completed successfully', |
| 719 | + success: true, |
| 720 | + }); |
| 721 | + }); |
| 722 | + |
| 723 | + it('adds AWS retry env vars for ECR login', async () => { |
| 724 | + const { kanikoBuild } = require('../engines'); |
| 725 | + await kanikoBuild(mockDeploy, baseOptions); |
| 726 | + |
| 727 | + const kubectlCalls = (shellPromise as jest.Mock).mock.calls; |
| 728 | + const applyCall = kubectlCalls.find((call) => call[0].includes('kubectl apply')); |
| 729 | + const fullCommand = applyCall[0]; |
| 730 | + |
| 731 | + expect(fullCommand).toContain('image: "amazon/aws-cli:2.13.0"'); |
| 732 | + expect(fullCommand).toContain('export AWS_MAX_ATTEMPTS=5'); |
| 733 | + expect(fullCommand).toContain('export AWS_RETRY_MODE=adaptive'); |
| 734 | + expect(fullCommand).toContain('aws ecr get-login-password --region us-east-1'); |
| 735 | + }); |
| 736 | + |
| 737 | + it('keeps non-ECR login bootstrap generic', async () => { |
| 738 | + const { kanikoBuild } = require('../engines'); |
| 739 | + await kanikoBuild(mockDeploy, { |
| 740 | + ...baseOptions, |
| 741 | + ecrDomain: 'registry.internal.svc.cluster.local', |
| 742 | + }); |
| 743 | + |
| 744 | + const kubectlCalls = (shellPromise as jest.Mock).mock.calls; |
| 745 | + const applyCall = kubectlCalls.find((call) => call[0].includes('kubectl apply')); |
| 746 | + const fullCommand = applyCall[0]; |
| 747 | + |
| 748 | + expect(fullCommand).toContain('image: "alpine:3.18"'); |
| 749 | + expect(fullCommand).toContain('Using in-cluster registry: registry.internal.svc.cluster.local'); |
| 750 | + expect(fullCommand).not.toContain('AWS_MAX_ATTEMPTS=5'); |
| 751 | + }); |
| 752 | +}); |
0 commit comments