mirror of
https://github.com/game-ci/unity-builder.git
synced 2026-06-07 06:30:17 -07:00
Compare commits
4 Commits
feature/cl
...
fix/secure
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f80e4f66d4 | ||
|
|
b2327008ed | ||
|
|
b3bd405399 | ||
|
|
8a41533779 |
124
action.yml
124
action.yml
@@ -105,6 +105,12 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ''
|
||||||
description: '[Orchestrator] Github private token to pull from github'
|
description: '[Orchestrator] Github private token to pull from github'
|
||||||
|
gitAuthMode:
|
||||||
|
required: false
|
||||||
|
default: 'header'
|
||||||
|
description:
|
||||||
|
'[Orchestrator] How git authentication is configured. "header" (default) uses http.extraHeader so the token
|
||||||
|
never appears in clone URLs or git config. "url" embeds the token in clone URLs (legacy behavior).'
|
||||||
githubOwner:
|
githubOwner:
|
||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ''
|
||||||
@@ -182,8 +188,8 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ''
|
||||||
description:
|
description:
|
||||||
'[Orchestrator] Run a custom job instead of the standard build automation for orchestrator (in yaml format with
|
'[Orchestrator] Run a custom job instead of the standard build automation for orchestrator (in yaml format with the
|
||||||
the keys image, secrets (name, value object array), command line string)'
|
keys image, secrets (name, value object array), command line string)'
|
||||||
awsStackName:
|
awsStackName:
|
||||||
default: 'game-ci'
|
default: 'game-ci'
|
||||||
required: false
|
required: false
|
||||||
@@ -279,120 +285,6 @@ inputs:
|
|||||||
description:
|
description:
|
||||||
'[Orchestrator] Specifies the repo for the unity builder. Useful if you forked the repo for testing, features, or
|
'[Orchestrator] Specifies the repo for the unity builder. Useful if you forked the repo for testing, features, or
|
||||||
fixes.'
|
fixes.'
|
||||||
gcpProject:
|
|
||||||
required: false
|
|
||||||
default: ''
|
|
||||||
description:
|
|
||||||
'[Orchestrator] [Experimental] Google Cloud project ID for Cloud Run Jobs provider. Falls back to
|
|
||||||
GOOGLE_CLOUD_PROJECT env var.'
|
|
||||||
gcpRegion:
|
|
||||||
required: false
|
|
||||||
default: ''
|
|
||||||
description:
|
|
||||||
'[Orchestrator] [Experimental] Google Cloud region for Cloud Run Jobs (e.g. us-central1). Defaults to the region
|
|
||||||
input if empty.'
|
|
||||||
gcpStorageType:
|
|
||||||
required: false
|
|
||||||
default: 'gcs-fuse'
|
|
||||||
description:
|
|
||||||
'[Orchestrator] [Experimental] Storage type for Cloud Run Jobs. Options: gcs-fuse (mount GCS bucket as filesystem,
|
|
||||||
unlimited size, best for large sequential I/O), gcs-copy (copy artifacts in/out via gsutil, simpler, no FUSE
|
|
||||||
overhead), nfs (Filestore NFS mount, true POSIX, good random I/O, up to 100 TiB), in-memory (tmpfs, fastest but
|
|
||||||
volatile, up to 32 GiB).'
|
|
||||||
gcpBucket:
|
|
||||||
required: false
|
|
||||||
default: ''
|
|
||||||
description:
|
|
||||||
'[Orchestrator] [Experimental] GCS bucket name for build artifact storage. Used by gcs-fuse and gcs-copy storage
|
|
||||||
types.'
|
|
||||||
gcpFilestoreIp:
|
|
||||||
required: false
|
|
||||||
default: ''
|
|
||||||
description:
|
|
||||||
'[Orchestrator] [Experimental] Filestore instance IP address for NFS storage type. Required when gcpStorageType is
|
|
||||||
nfs.'
|
|
||||||
gcpFilestoreShare:
|
|
||||||
required: false
|
|
||||||
default: '/share1'
|
|
||||||
description:
|
|
||||||
'[Orchestrator] [Experimental] Filestore share name for NFS storage type. Defaults to /share1 (the Filestore
|
|
||||||
default).'
|
|
||||||
gcpMachineType:
|
|
||||||
required: false
|
|
||||||
default: 'e2-standard-4'
|
|
||||||
description: '[Orchestrator] [Experimental] Machine type for Cloud Run Jobs (e.g. e2-standard-4, e2-highmem-8).'
|
|
||||||
gcpDiskSizeGb:
|
|
||||||
required: false
|
|
||||||
default: '100'
|
|
||||||
description:
|
|
||||||
'[Orchestrator] [Experimental] Disk size in GB for Cloud Run Jobs in-memory volumes. Only applies to in-memory
|
|
||||||
storage type (max 32).'
|
|
||||||
gcpServiceAccount:
|
|
||||||
required: false
|
|
||||||
default: ''
|
|
||||||
description: '[Orchestrator] [Experimental] Google Cloud service account email for Cloud Run Jobs execution.'
|
|
||||||
gcpVpcConnector:
|
|
||||||
required: false
|
|
||||||
default: ''
|
|
||||||
description: '[Orchestrator] [Experimental] VPC connector name for Cloud Run Jobs private networking.'
|
|
||||||
azureResourceGroup:
|
|
||||||
required: false
|
|
||||||
default: ''
|
|
||||||
description:
|
|
||||||
'[Orchestrator] [Experimental] Azure resource group for Container Instances provider. Falls back to
|
|
||||||
AZURE_RESOURCE_GROUP env var.'
|
|
||||||
azureLocation:
|
|
||||||
required: false
|
|
||||||
default: ''
|
|
||||||
description:
|
|
||||||
'[Orchestrator] [Experimental] Azure region for Container Instances (e.g. eastus, westeurope). Defaults to the
|
|
||||||
region input if empty.'
|
|
||||||
azureStorageType:
|
|
||||||
required: false
|
|
||||||
default: 'azure-files'
|
|
||||||
description:
|
|
||||||
'[Orchestrator] [Experimental] Storage type for Azure Container Instances. Options: azure-files (SMB file share
|
|
||||||
mount, up to 100 TiB, premium throughput), blob-copy (copy artifacts in/out via az storage blob, no mount
|
|
||||||
overhead), azure-files-nfs (NFS 4.1 file share mount, true POSIX, no SMB lock overhead), in-memory (emptyDir
|
|
||||||
tmpfs, fastest but volatile, size limited by container memory).'
|
|
||||||
azureStorageAccount:
|
|
||||||
required: false
|
|
||||||
default: ''
|
|
||||||
description:
|
|
||||||
'[Orchestrator] [Experimental] Azure Storage Account name. Used by azure-files, azure-files-nfs, and blob-copy
|
|
||||||
storage types.'
|
|
||||||
azureFileShareName:
|
|
||||||
required: false
|
|
||||||
default: 'unity-builds'
|
|
||||||
description:
|
|
||||||
'[Orchestrator] [Experimental] Azure File Share name within the storage account. Used by azure-files and
|
|
||||||
azure-files-nfs storage types. Supports up to 100 TiB per share.'
|
|
||||||
azureBlobContainer:
|
|
||||||
required: false
|
|
||||||
default: 'unity-builds'
|
|
||||||
description: '[Orchestrator] [Experimental] Azure Blob container name for blob-copy storage type.'
|
|
||||||
azureSubscriptionId:
|
|
||||||
required: false
|
|
||||||
default: ''
|
|
||||||
description: '[Orchestrator] [Experimental] Azure subscription ID. Falls back to AZURE_SUBSCRIPTION_ID env var.'
|
|
||||||
azureCpu:
|
|
||||||
required: false
|
|
||||||
default: '4'
|
|
||||||
description: '[Orchestrator] [Experimental] CPU cores for Azure Container Instances (1-16).'
|
|
||||||
azureMemoryGb:
|
|
||||||
required: false
|
|
||||||
default: '16'
|
|
||||||
description: '[Orchestrator] [Experimental] Memory in GB for Azure Container Instances (1-16).'
|
|
||||||
azureDiskSizeGb:
|
|
||||||
required: false
|
|
||||||
default: '100'
|
|
||||||
description:
|
|
||||||
'[Orchestrator] [Experimental] File share quota in GB for Azure Container Instances. Premium shares support up to
|
|
||||||
102400 GB (100 TiB).'
|
|
||||||
azureSubnetId:
|
|
||||||
required: false
|
|
||||||
default: ''
|
|
||||||
description: '[Orchestrator] [Experimental] Azure subnet resource ID for VNet-integrated Container Instances.'
|
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
volume:
|
volume:
|
||||||
|
|||||||
956
dist/index.js
generated
vendored
956
dist/index.js
generated
vendored
File diff suppressed because it is too large
Load Diff
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@@ -54,6 +54,7 @@ class BuildParameters {
|
|||||||
public sshAgent!: string;
|
public sshAgent!: string;
|
||||||
public sshPublicKeysDirectoryPath!: string;
|
public sshPublicKeysDirectoryPath!: string;
|
||||||
public providerStrategy!: string;
|
public providerStrategy!: string;
|
||||||
|
public gitAuthMode!: string;
|
||||||
public gitPrivateToken!: string;
|
public gitPrivateToken!: string;
|
||||||
public awsStackName!: string;
|
public awsStackName!: string;
|
||||||
public awsEndpoint?: string;
|
public awsEndpoint?: string;
|
||||||
@@ -107,31 +108,6 @@ class BuildParameters {
|
|||||||
public unityHubVersionOnMac!: string;
|
public unityHubVersionOnMac!: string;
|
||||||
public dockerWorkspacePath!: string;
|
public dockerWorkspacePath!: string;
|
||||||
|
|
||||||
// GCP Cloud Run (Experimental)
|
|
||||||
public gcpProject!: string;
|
|
||||||
public gcpRegion!: string;
|
|
||||||
public gcpStorageType!: string;
|
|
||||||
public gcpBucket!: string;
|
|
||||||
public gcpFilestoreIp!: string;
|
|
||||||
public gcpFilestoreShare!: string;
|
|
||||||
public gcpMachineType!: string;
|
|
||||||
public gcpDiskSizeGb!: string;
|
|
||||||
public gcpServiceAccount!: string;
|
|
||||||
public gcpVpcConnector!: string;
|
|
||||||
|
|
||||||
// Azure Container Instances (Experimental)
|
|
||||||
public azureResourceGroup!: string;
|
|
||||||
public azureLocation!: string;
|
|
||||||
public azureStorageType!: string;
|
|
||||||
public azureStorageAccount!: string;
|
|
||||||
public azureBlobContainer!: string;
|
|
||||||
public azureFileShareName!: string;
|
|
||||||
public azureSubscriptionId!: string;
|
|
||||||
public azureCpu!: string;
|
|
||||||
public azureMemoryGb!: string;
|
|
||||||
public azureDiskSizeGb!: string;
|
|
||||||
public azureSubnetId!: string;
|
|
||||||
|
|
||||||
public static shouldUseRetainedWorkspaceMode(buildParameters: BuildParameters) {
|
public static shouldUseRetainedWorkspaceMode(buildParameters: BuildParameters) {
|
||||||
return buildParameters.maxRetainedWorkspaces > 0 && Orchestrator.lockedWorkspace !== ``;
|
return buildParameters.maxRetainedWorkspaces > 0 && Orchestrator.lockedWorkspace !== ``;
|
||||||
}
|
}
|
||||||
@@ -219,6 +195,7 @@ class BuildParameters {
|
|||||||
containerRegistryRepository: Input.containerRegistryRepository,
|
containerRegistryRepository: Input.containerRegistryRepository,
|
||||||
containerRegistryImageVersion: Input.containerRegistryImageVersion,
|
containerRegistryImageVersion: Input.containerRegistryImageVersion,
|
||||||
providerStrategy: OrchestratorOptions.providerStrategy,
|
providerStrategy: OrchestratorOptions.providerStrategy,
|
||||||
|
gitAuthMode: OrchestratorOptions.gitAuthMode,
|
||||||
buildPlatform: OrchestratorOptions.buildPlatform,
|
buildPlatform: OrchestratorOptions.buildPlatform,
|
||||||
kubeConfig: OrchestratorOptions.kubeConfig,
|
kubeConfig: OrchestratorOptions.kubeConfig,
|
||||||
containerMemory: OrchestratorOptions.containerMemory,
|
containerMemory: OrchestratorOptions.containerMemory,
|
||||||
@@ -253,27 +230,6 @@ class BuildParameters {
|
|||||||
inputPullCommand: OrchestratorOptions.inputPullCommand,
|
inputPullCommand: OrchestratorOptions.inputPullCommand,
|
||||||
pullInputList: OrchestratorOptions.pullInputList,
|
pullInputList: OrchestratorOptions.pullInputList,
|
||||||
kubeStorageClass: OrchestratorOptions.kubeStorageClass,
|
kubeStorageClass: OrchestratorOptions.kubeStorageClass,
|
||||||
gcpProject: Input.gcpProject,
|
|
||||||
gcpRegion: Input.gcpRegion,
|
|
||||||
gcpStorageType: Input.gcpStorageType,
|
|
||||||
gcpBucket: Input.gcpBucket,
|
|
||||||
gcpFilestoreIp: Input.gcpFilestoreIp,
|
|
||||||
gcpFilestoreShare: Input.gcpFilestoreShare,
|
|
||||||
gcpMachineType: Input.gcpMachineType,
|
|
||||||
gcpDiskSizeGb: Input.gcpDiskSizeGb,
|
|
||||||
gcpServiceAccount: Input.gcpServiceAccount,
|
|
||||||
gcpVpcConnector: Input.gcpVpcConnector,
|
|
||||||
azureResourceGroup: Input.azureResourceGroup,
|
|
||||||
azureLocation: Input.azureLocation,
|
|
||||||
azureStorageType: Input.azureStorageType,
|
|
||||||
azureStorageAccount: Input.azureStorageAccount,
|
|
||||||
azureBlobContainer: Input.azureBlobContainer,
|
|
||||||
azureFileShareName: Input.azureFileShareName,
|
|
||||||
azureSubscriptionId: Input.azureSubscriptionId,
|
|
||||||
azureCpu: Input.azureCpu,
|
|
||||||
azureMemoryGb: Input.azureMemoryGb,
|
|
||||||
azureDiskSizeGb: Input.azureDiskSizeGb,
|
|
||||||
azureSubnetId: Input.azureSubnetId,
|
|
||||||
cacheKey: OrchestratorOptions.cacheKey,
|
cacheKey: OrchestratorOptions.cacheKey,
|
||||||
maxRetainedWorkspaces: Number.parseInt(OrchestratorOptions.maxRetainedWorkspaces),
|
maxRetainedWorkspaces: Number.parseInt(OrchestratorOptions.maxRetainedWorkspaces),
|
||||||
useLargePackages: OrchestratorOptions.useLargePackages,
|
useLargePackages: OrchestratorOptions.useLargePackages,
|
||||||
|
|||||||
@@ -282,92 +282,6 @@ class Input {
|
|||||||
return Input.getInput('skipActivation')?.toLowerCase() ?? 'false';
|
return Input.getInput('skipActivation')?.toLowerCase() ?? 'false';
|
||||||
}
|
}
|
||||||
|
|
||||||
// GCP Cloud Run (Experimental)
|
|
||||||
static get gcpProject(): string {
|
|
||||||
return Input.getInput('gcpProject') ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get gcpRegion(): string {
|
|
||||||
return Input.getInput('gcpRegion') ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get gcpStorageType(): string {
|
|
||||||
return Input.getInput('gcpStorageType') ?? 'gcs-fuse';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get gcpBucket(): string {
|
|
||||||
return Input.getInput('gcpBucket') ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get gcpFilestoreIp(): string {
|
|
||||||
return Input.getInput('gcpFilestoreIp') ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get gcpFilestoreShare(): string {
|
|
||||||
return Input.getInput('gcpFilestoreShare') ?? '/share1';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get gcpMachineType(): string {
|
|
||||||
return Input.getInput('gcpMachineType') ?? 'e2-standard-4';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get gcpDiskSizeGb(): string {
|
|
||||||
return Input.getInput('gcpDiskSizeGb') ?? '100';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get gcpServiceAccount(): string {
|
|
||||||
return Input.getInput('gcpServiceAccount') ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get gcpVpcConnector(): string {
|
|
||||||
return Input.getInput('gcpVpcConnector') ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Azure Container Instances (Experimental)
|
|
||||||
static get azureResourceGroup(): string {
|
|
||||||
return Input.getInput('azureResourceGroup') ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get azureLocation(): string {
|
|
||||||
return Input.getInput('azureLocation') ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get azureStorageType(): string {
|
|
||||||
return Input.getInput('azureStorageType') ?? 'azure-files';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get azureStorageAccount(): string {
|
|
||||||
return Input.getInput('azureStorageAccount') ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get azureBlobContainer(): string {
|
|
||||||
return Input.getInput('azureBlobContainer') ?? 'unity-builds';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get azureFileShareName(): string {
|
|
||||||
return Input.getInput('azureFileShareName') ?? 'unity-builds';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get azureSubscriptionId(): string {
|
|
||||||
return Input.getInput('azureSubscriptionId') ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get azureCpu(): string {
|
|
||||||
return Input.getInput('azureCpu') ?? '4';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get azureMemoryGb(): string {
|
|
||||||
return Input.getInput('azureMemoryGb') ?? '16';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get azureDiskSizeGb(): string {
|
|
||||||
return Input.getInput('azureDiskSizeGb') ?? '100';
|
|
||||||
}
|
|
||||||
|
|
||||||
static get azureSubnetId(): string {
|
|
||||||
return Input.getInput('azureSubnetId') ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ToEnvVarFormat(input: string) {
|
public static ToEnvVarFormat(input: string) {
|
||||||
if (input.toUpperCase() === input) {
|
if (input.toUpperCase() === input) {
|
||||||
return input;
|
return input;
|
||||||
|
|||||||
140
src/model/orchestrator/options/orchestrator-folders-auth.test.ts
Normal file
140
src/model/orchestrator/options/orchestrator-folders-auth.test.ts
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
import { OrchestratorFolders } from './orchestrator-folders';
|
||||||
|
|
||||||
|
jest.mock('../orchestrator', () => ({
|
||||||
|
__esModule: true,
|
||||||
|
default: {
|
||||||
|
buildParameters: {
|
||||||
|
orchestratorRepoName: 'game-ci/unity-builder',
|
||||||
|
githubRepo: 'myorg/myrepo',
|
||||||
|
gitPrivateToken: 'ghp_test123',
|
||||||
|
gitAuthMode: 'header',
|
||||||
|
buildGuid: 'test-guid',
|
||||||
|
projectPath: '',
|
||||||
|
buildPath: 'Builds',
|
||||||
|
cacheKey: 'test-cache',
|
||||||
|
},
|
||||||
|
lockedWorkspace: '',
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
jest.mock('./orchestrator-options', () => ({
|
||||||
|
__esModule: true,
|
||||||
|
default: {
|
||||||
|
useSharedBuilder: false,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
jest.mock('../services/core/orchestrator-system', () => ({
|
||||||
|
OrchestratorSystem: {
|
||||||
|
Run: jest.fn().mockResolvedValue(''),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
const mockOrchestrator = require('../orchestrator').default;
|
||||||
|
|
||||||
|
describe('OrchestratorFolders git auth', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('useHeaderAuth', () => {
|
||||||
|
it('should return true when gitAuthMode is header', () => {
|
||||||
|
mockOrchestrator.buildParameters.gitAuthMode = 'header';
|
||||||
|
expect(OrchestratorFolders.useHeaderAuth).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true when gitAuthMode is undefined (default)', () => {
|
||||||
|
mockOrchestrator.buildParameters.gitAuthMode = undefined;
|
||||||
|
expect(OrchestratorFolders.useHeaderAuth).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false when gitAuthMode is url', () => {
|
||||||
|
mockOrchestrator.buildParameters.gitAuthMode = 'url';
|
||||||
|
expect(OrchestratorFolders.useHeaderAuth).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('unityBuilderRepoUrl', () => {
|
||||||
|
it('should not include token in URL when using header auth', () => {
|
||||||
|
mockOrchestrator.buildParameters.gitAuthMode = 'header';
|
||||||
|
const url = OrchestratorFolders.unityBuilderRepoUrl;
|
||||||
|
expect(url).toBe('https://github.com/game-ci/unity-builder.git');
|
||||||
|
expect(url).not.toContain('ghp_test123');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should include token in URL when using url auth (legacy)', () => {
|
||||||
|
mockOrchestrator.buildParameters.gitAuthMode = 'url';
|
||||||
|
const url = OrchestratorFolders.unityBuilderRepoUrl;
|
||||||
|
expect(url).toBe('https://ghp_test123@github.com/game-ci/unity-builder.git');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('targetBuildRepoUrl', () => {
|
||||||
|
it('should not include token in URL when using header auth', () => {
|
||||||
|
mockOrchestrator.buildParameters.gitAuthMode = 'header';
|
||||||
|
const url = OrchestratorFolders.targetBuildRepoUrl;
|
||||||
|
expect(url).toBe('https://github.com/myorg/myrepo.git');
|
||||||
|
expect(url).not.toContain('ghp_test123');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should include token in URL when using url auth (legacy)', () => {
|
||||||
|
mockOrchestrator.buildParameters.gitAuthMode = 'url';
|
||||||
|
const url = OrchestratorFolders.targetBuildRepoUrl;
|
||||||
|
expect(url).toBe('https://ghp_test123@github.com/myorg/myrepo.git');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('gitAuthConfigScript', () => {
|
||||||
|
it('should emit http.extraHeader commands in header mode', () => {
|
||||||
|
mockOrchestrator.buildParameters.gitAuthMode = 'header';
|
||||||
|
const script = OrchestratorFolders.gitAuthConfigScript;
|
||||||
|
expect(script).toContain('http.extraHeader');
|
||||||
|
expect(script).toContain('GIT_PRIVATE_TOKEN');
|
||||||
|
expect(script).toContain('Authorization: Basic');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should emit no-op comment in url mode', () => {
|
||||||
|
mockOrchestrator.buildParameters.gitAuthMode = 'url';
|
||||||
|
const script = OrchestratorFolders.gitAuthConfigScript;
|
||||||
|
expect(script).toContain('legacy');
|
||||||
|
expect(script).not.toContain('http.extraHeader');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('configureGitAuth', () => {
|
||||||
|
it('should run git config with http.extraHeader in header mode', async () => {
|
||||||
|
mockOrchestrator.buildParameters.gitAuthMode = 'header';
|
||||||
|
mockOrchestrator.buildParameters.gitPrivateToken = 'ghp_test123';
|
||||||
|
const { OrchestratorSystem } = require('../services/core/orchestrator-system');
|
||||||
|
|
||||||
|
await OrchestratorFolders.configureGitAuth();
|
||||||
|
|
||||||
|
// Verify the base64 encoding and extraHeader config are correct
|
||||||
|
const expectedEncoded = Buffer.from('x-access-token:ghp_test123').toString('base64');
|
||||||
|
expect(OrchestratorSystem.Run).toHaveBeenCalledWith(expect.stringContaining(expectedEncoded));
|
||||||
|
expect(OrchestratorSystem.Run).toHaveBeenCalledWith(expect.stringContaining('.extraHeader'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not run git config in url mode', async () => {
|
||||||
|
mockOrchestrator.buildParameters.gitAuthMode = 'url';
|
||||||
|
const { OrchestratorSystem } = require('../services/core/orchestrator-system');
|
||||||
|
|
||||||
|
await OrchestratorFolders.configureGitAuth();
|
||||||
|
|
||||||
|
expect(OrchestratorSystem.Run).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not run git config when no token is available', async () => {
|
||||||
|
mockOrchestrator.buildParameters.gitAuthMode = 'header';
|
||||||
|
mockOrchestrator.buildParameters.gitPrivateToken = '';
|
||||||
|
const originalEnv = process.env.GIT_PRIVATE_TOKEN;
|
||||||
|
delete process.env.GIT_PRIVATE_TOKEN;
|
||||||
|
const { OrchestratorSystem } = require('../services/core/orchestrator-system');
|
||||||
|
|
||||||
|
await OrchestratorFolders.configureGitAuth();
|
||||||
|
|
||||||
|
expect(OrchestratorSystem.Run).not.toHaveBeenCalled();
|
||||||
|
if (originalEnv !== undefined) process.env.GIT_PRIVATE_TOKEN = originalEnv;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -72,14 +72,67 @@ export class OrchestratorFolders {
|
|||||||
return path.join(OrchestratorFolders.cacheFolderForCacheKeyFull, `Library`);
|
return path.join(OrchestratorFolders.cacheFolderForCacheKeyFull, `Library`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to use http.extraHeader for git authentication (secure, default)
|
||||||
|
* instead of embedding the token in clone URLs (legacy).
|
||||||
|
*/
|
||||||
|
public static get useHeaderAuth(): boolean {
|
||||||
|
return Orchestrator.buildParameters.gitAuthMode !== 'url';
|
||||||
|
}
|
||||||
|
|
||||||
public static get unityBuilderRepoUrl(): string {
|
public static get unityBuilderRepoUrl(): string {
|
||||||
|
if (OrchestratorFolders.useHeaderAuth) {
|
||||||
|
return `https://github.com/${Orchestrator.buildParameters.orchestratorRepoName}.git`;
|
||||||
|
}
|
||||||
|
|
||||||
return `https://${Orchestrator.buildParameters.gitPrivateToken}@github.com/${Orchestrator.buildParameters.orchestratorRepoName}.git`;
|
return `https://${Orchestrator.buildParameters.gitPrivateToken}@github.com/${Orchestrator.buildParameters.orchestratorRepoName}.git`;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static get targetBuildRepoUrl(): string {
|
public static get targetBuildRepoUrl(): string {
|
||||||
|
if (OrchestratorFolders.useHeaderAuth) {
|
||||||
|
return `https://github.com/${Orchestrator.buildParameters.githubRepo}.git`;
|
||||||
|
}
|
||||||
|
|
||||||
return `https://${Orchestrator.buildParameters.gitPrivateToken}@github.com/${Orchestrator.buildParameters.githubRepo}.git`;
|
return `https://${Orchestrator.buildParameters.gitPrivateToken}@github.com/${Orchestrator.buildParameters.githubRepo}.git`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shell commands to configure git authentication via http.extraHeader.
|
||||||
|
* Uses GIT_PRIVATE_TOKEN env var so the token never appears in clone URLs or git config output.
|
||||||
|
* This is the same mechanism used by actions/checkout.
|
||||||
|
*
|
||||||
|
* Only emits commands when gitAuthMode is 'header' (default). In 'url' mode,
|
||||||
|
* returns a no-op comment since the token is already in the URL.
|
||||||
|
*/
|
||||||
|
public static get gitAuthConfigScript(): string {
|
||||||
|
if (!OrchestratorFolders.useHeaderAuth) {
|
||||||
|
return `# git auth: using token-in-URL mode (legacy)`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `# git auth: configuring http.extraHeader (secure mode)
|
||||||
|
if [ -n "$GIT_PRIVATE_TOKEN" ]; then
|
||||||
|
git config --global http.https://github.com/.extraHeader "Authorization: Basic $(printf '%s' "x-access-token:$GIT_PRIVATE_TOKEN" | base64 -w 0)"
|
||||||
|
fi`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure git authentication via http.extraHeader in the current Node process.
|
||||||
|
* For use in the remote-client where shell scripts aren't used.
|
||||||
|
* Only configures when gitAuthMode is 'header' (default).
|
||||||
|
*/
|
||||||
|
public static async configureGitAuth(): Promise<void> {
|
||||||
|
if (!OrchestratorFolders.useHeaderAuth) return;
|
||||||
|
|
||||||
|
const token = Orchestrator.buildParameters.gitPrivateToken || process.env.GIT_PRIVATE_TOKEN || '';
|
||||||
|
if (!token) return;
|
||||||
|
|
||||||
|
const encoded = Buffer.from(`x-access-token:${token}`).toString('base64');
|
||||||
|
const { OrchestratorSystem } = await import('../services/core/orchestrator-system');
|
||||||
|
await OrchestratorSystem.Run(
|
||||||
|
`git config --global http.https://github.com/.extraHeader "Authorization: Basic ${encoded}"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static get buildVolumeFolder() {
|
public static get buildVolumeFolder() {
|
||||||
return 'data';
|
return 'data';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,6 +138,10 @@ class OrchestratorOptions {
|
|||||||
return provider || 'local';
|
return provider || 'local';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static get gitAuthMode(): string {
|
||||||
|
return OrchestratorOptions.getInput('gitAuthMode') || 'header';
|
||||||
|
}
|
||||||
|
|
||||||
static get containerCpu(): string {
|
static get containerCpu(): string {
|
||||||
return OrchestratorOptions.getInput('containerCpu') || `1024`;
|
return OrchestratorOptions.getInput('containerCpu') || `1024`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ import OrchestratorEnvironmentVariable from './options/orchestrator-environment-
|
|||||||
import TestOrchestrator from './providers/test';
|
import TestOrchestrator from './providers/test';
|
||||||
import LocalOrchestrator from './providers/local';
|
import LocalOrchestrator from './providers/local';
|
||||||
import LocalDockerOrchestrator from './providers/docker';
|
import LocalDockerOrchestrator from './providers/docker';
|
||||||
import GcpCloudRunProvider from './providers/gcp-cloud-run';
|
|
||||||
import AzureAciProvider from './providers/azure-aci';
|
|
||||||
import loadProvider from './providers/provider-loader';
|
import loadProvider from './providers/provider-loader';
|
||||||
import GitHub from '../github';
|
import GitHub from '../github';
|
||||||
import SharedWorkspaceLocking from './services/core/shared-workspace-locking';
|
import SharedWorkspaceLocking from './services/core/shared-workspace-locking';
|
||||||
@@ -160,14 +158,6 @@ class Orchestrator {
|
|||||||
case 'local':
|
case 'local':
|
||||||
Orchestrator.Provider = new LocalOrchestrator();
|
Orchestrator.Provider = new LocalOrchestrator();
|
||||||
break;
|
break;
|
||||||
case 'gcp-cloud-run':
|
|
||||||
OrchestratorLogger.log('⚠ EXPERIMENTAL: GCP Cloud Run Jobs provider');
|
|
||||||
Orchestrator.Provider = new GcpCloudRunProvider(Orchestrator.buildParameters);
|
|
||||||
break;
|
|
||||||
case 'azure-aci':
|
|
||||||
OrchestratorLogger.log('⚠ EXPERIMENTAL: Azure Container Instances provider');
|
|
||||||
Orchestrator.Provider = new AzureAciProvider(Orchestrator.buildParameters);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
// Try to load provider using the dynamic loader for unknown providers
|
// Try to load provider using the dynamic loader for unknown providers
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,536 +0,0 @@
|
|||||||
/**
|
|
||||||
* Azure Container Instances (ACI) Provider (Experimental)
|
|
||||||
*
|
|
||||||
* Executes Unity builds as Azure Container Instances with configurable storage backends.
|
|
||||||
*
|
|
||||||
* Storage types:
|
|
||||||
* - azure-files: SMB file share mount via Azure Files. Up to 100 TiB per share,
|
|
||||||
* premium throughput. Default.
|
|
||||||
* Requires: azureStorageAccount, azureFileShareName
|
|
||||||
* - blob-copy: Copy artifacts in/out of Azure Blob Storage before/after the build.
|
|
||||||
* No mount overhead, simpler.
|
|
||||||
* Requires: azureStorageAccount, azureBlobContainer
|
|
||||||
* - azure-files-nfs: NFS 4.1 file share mount. True POSIX semantics, no SMB lock overhead,
|
|
||||||
* better for Unity Library caching (many small random reads).
|
|
||||||
* Requires: azureStorageAccount, azureFileShareName, Premium FileStorage,
|
|
||||||
* VNet integration (azureSubnetId)
|
|
||||||
* - in-memory: emptyDir volume (tmpfs). Fastest I/O but volatile, size limited by
|
|
||||||
* container memory allocation.
|
|
||||||
*
|
|
||||||
* Prerequisites:
|
|
||||||
* - Azure CLI authenticated (az login or service principal)
|
|
||||||
* - A resource group for build resources
|
|
||||||
* - Contributor role on the resource group
|
|
||||||
*
|
|
||||||
* @experimental This provider is experimental. APIs and behavior may change.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { ProviderInterface } from '../provider-interface';
|
|
||||||
import BuildParameters from '../../../build-parameters';
|
|
||||||
import OrchestratorLogger from '../../services/core/orchestrator-logger';
|
|
||||||
import OrchestratorEnvironmentVariable from '../../options/orchestrator-environment-variable';
|
|
||||||
import OrchestratorSecret from '../../options/orchestrator-secret';
|
|
||||||
import { ProviderResource } from '../provider-resource';
|
|
||||||
import { ProviderWorkflow } from '../provider-workflow';
|
|
||||||
import { OrchestratorSystem } from '../../services/core/orchestrator-system';
|
|
||||||
import { Input } from '../../..';
|
|
||||||
import ResourceTracking from '../../services/core/resource-tracking';
|
|
||||||
|
|
||||||
type AzureStorageType = 'azure-files' | 'blob-copy' | 'azure-files-nfs' | 'in-memory';
|
|
||||||
|
|
||||||
class AzureAciProvider implements ProviderInterface {
|
|
||||||
private readonly resourceGroup: string;
|
|
||||||
private readonly location: string;
|
|
||||||
private readonly storageType: AzureStorageType;
|
|
||||||
private readonly storageAccount: string;
|
|
||||||
private readonly blobContainer: string;
|
|
||||||
private readonly fileShareName: string;
|
|
||||||
private readonly subscriptionId: string;
|
|
||||||
private readonly cpu: number;
|
|
||||||
private readonly memoryGb: number;
|
|
||||||
private readonly diskSizeGb: number;
|
|
||||||
private readonly subnetId: string;
|
|
||||||
private buildParameters: BuildParameters;
|
|
||||||
|
|
||||||
constructor(buildParameters: BuildParameters) {
|
|
||||||
this.buildParameters = buildParameters;
|
|
||||||
this.resourceGroup = buildParameters.azureResourceGroup || process.env.AZURE_RESOURCE_GROUP || '';
|
|
||||||
this.location = buildParameters.azureLocation || Input.region || 'eastus';
|
|
||||||
this.storageType = (buildParameters.azureStorageType || 'azure-files') as AzureStorageType;
|
|
||||||
this.storageAccount = buildParameters.azureStorageAccount || process.env.AZURE_STORAGE_ACCOUNT || '';
|
|
||||||
this.blobContainer = buildParameters.azureBlobContainer || 'unity-builds';
|
|
||||||
this.fileShareName = buildParameters.azureFileShareName || 'unity-builds';
|
|
||||||
this.subscriptionId = buildParameters.azureSubscriptionId || process.env.AZURE_SUBSCRIPTION_ID || '';
|
|
||||||
this.cpu = Number.parseInt(buildParameters.azureCpu || '4', 10);
|
|
||||||
this.memoryGb = Number.parseInt(buildParameters.azureMemoryGb || '16', 10);
|
|
||||||
this.diskSizeGb = Number.parseInt(buildParameters.azureDiskSizeGb || '100', 10);
|
|
||||||
this.subnetId = buildParameters.azureSubnetId || '';
|
|
||||||
|
|
||||||
OrchestratorLogger.log('[Azure ACI] Provider initialized (EXPERIMENTAL)');
|
|
||||||
OrchestratorLogger.log(`[Azure ACI] Resource Group: ${this.resourceGroup || '(not set)'}`);
|
|
||||||
OrchestratorLogger.log(`[Azure ACI] Location: ${this.location}`);
|
|
||||||
OrchestratorLogger.log(`[Azure ACI] Storage: ${this.storageType}`);
|
|
||||||
OrchestratorLogger.log(`[Azure ACI] Resources: ${this.cpu} CPU, ${this.memoryGb}GB RAM`);
|
|
||||||
|
|
||||||
this.validateStorageConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
private validateStorageConfig(): void {
|
|
||||||
switch (this.storageType) {
|
|
||||||
case 'azure-files':
|
|
||||||
if (!this.storageAccount) {
|
|
||||||
OrchestratorLogger.logWarning(
|
|
||||||
'[Azure ACI] Storage type "azure-files" requires azureStorageAccount to be set.',
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
OrchestratorLogger.log(`[Azure ACI] File Share: ${this.storageAccount}/${this.fileShareName} (SMB)`);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'azure-files-nfs':
|
|
||||||
if (!this.storageAccount) {
|
|
||||||
OrchestratorLogger.logWarning(
|
|
||||||
'[Azure ACI] Storage type "azure-files-nfs" requires azureStorageAccount (Premium FileStorage).',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!this.subnetId) {
|
|
||||||
OrchestratorLogger.logWarning('[Azure ACI] NFS file shares require VNet integration. Set azureSubnetId.');
|
|
||||||
} else {
|
|
||||||
OrchestratorLogger.log(`[Azure ACI] File Share: ${this.storageAccount}/${this.fileShareName} (NFS 4.1)`);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'blob-copy':
|
|
||||||
if (!this.storageAccount) {
|
|
||||||
OrchestratorLogger.logWarning('[Azure ACI] Storage type "blob-copy" requires azureStorageAccount to be set.');
|
|
||||||
} else {
|
|
||||||
OrchestratorLogger.log(`[Azure ACI] Blob container: ${this.storageAccount}/${this.blobContainer}`);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'in-memory':
|
|
||||||
OrchestratorLogger.log(
|
|
||||||
`[Azure ACI] In-memory volume (emptyDir): limited by ${this.memoryGb}GB container memory`,
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
OrchestratorLogger.logWarning(
|
|
||||||
`[Azure ACI] Unknown storage type '${this.storageType}'. Valid: azure-files, blob-copy, azure-files-nfs, in-memory`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.resourceGroup) {
|
|
||||||
OrchestratorLogger.logWarning(
|
|
||||||
'[Azure ACI] No resource group specified. Set azureResourceGroup input or AZURE_RESOURCE_GROUP env var.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async setupWorkflow(
|
|
||||||
buildGuid: string,
|
|
||||||
buildParameters: BuildParameters,
|
|
||||||
branchName: string,
|
|
||||||
defaultSecretsArray: { ParameterKey: string; EnvironmentVariable: string; ParameterValue: string }[],
|
|
||||||
) {
|
|
||||||
OrchestratorLogger.log(`[Azure ACI] Setting up workflow for build ${buildGuid}`);
|
|
||||||
ResourceTracking.logAllocationSummary('azure-aci setup');
|
|
||||||
|
|
||||||
// Verify Azure CLI is available
|
|
||||||
try {
|
|
||||||
await OrchestratorSystem.Run('az version --output json', false, true);
|
|
||||||
OrchestratorLogger.log('[Azure ACI] Azure CLI detected');
|
|
||||||
} catch {
|
|
||||||
throw new Error(
|
|
||||||
'[Azure ACI] Azure CLI not found. Install Azure CLI: https://learn.microsoft.com/en-us/cli/azure/install-azure-cli',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.subscriptionId) {
|
|
||||||
await OrchestratorSystem.Run(`az account set --subscription="${this.subscriptionId}"`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure resource group exists
|
|
||||||
if (this.resourceGroup) {
|
|
||||||
try {
|
|
||||||
await OrchestratorSystem.Run(`az group show --name "${this.resourceGroup}" --output json`, false, true);
|
|
||||||
OrchestratorLogger.log(`[Azure ACI] Resource group ${this.resourceGroup} exists`);
|
|
||||||
} catch {
|
|
||||||
OrchestratorLogger.log(`[Azure ACI] Creating resource group ${this.resourceGroup}`);
|
|
||||||
await OrchestratorSystem.Run(`az group create --name "${this.resourceGroup}" --location "${this.location}"`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Storage-specific setup
|
|
||||||
switch (this.storageType) {
|
|
||||||
case 'azure-files':
|
|
||||||
await this.setupStorageAccount('Standard_LRS', 'StorageV2');
|
|
||||||
await this.setupFileShare();
|
|
||||||
break;
|
|
||||||
case 'azure-files-nfs':
|
|
||||||
await this.setupStorageAccount('Premium_LRS', 'FileStorage');
|
|
||||||
await this.setupNfsFileShare();
|
|
||||||
break;
|
|
||||||
case 'blob-copy':
|
|
||||||
await this.setupStorageAccount('Standard_LRS', 'StorageV2');
|
|
||||||
await this.setupBlobContainer();
|
|
||||||
break;
|
|
||||||
case 'in-memory':
|
|
||||||
// No storage setup needed
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async setupStorageAccount(sku: string, kind: string): Promise<void> {
|
|
||||||
if (!this.storageAccount || !this.resourceGroup) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
await OrchestratorSystem.Run(
|
|
||||||
`az storage account show --name "${this.storageAccount}" --resource-group "${this.resourceGroup}" --output json`,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
OrchestratorLogger.log(`[Azure ACI] Storage account ${this.storageAccount} exists`);
|
|
||||||
} catch {
|
|
||||||
OrchestratorLogger.log(`[Azure ACI] Creating storage account ${this.storageAccount} (${sku}, ${kind})`);
|
|
||||||
await OrchestratorSystem.Run(
|
|
||||||
`az storage account create --name "${this.storageAccount}" --resource-group "${this.resourceGroup}" --location "${this.location}" --sku ${sku} --kind ${kind}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async setupFileShare(): Promise<void> {
|
|
||||||
if (!this.storageAccount || !this.resourceGroup) return;
|
|
||||||
try {
|
|
||||||
await OrchestratorSystem.Run(
|
|
||||||
`az storage share-rm show --storage-account "${this.storageAccount}" --name "${this.fileShareName}" --resource-group "${this.resourceGroup}" --output json`,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
} catch {
|
|
||||||
OrchestratorLogger.log(`[Azure ACI] Creating file share ${this.fileShareName} (${this.diskSizeGb}GB)`);
|
|
||||||
await OrchestratorSystem.Run(
|
|
||||||
`az storage share-rm create --storage-account "${this.storageAccount}" --name "${this.fileShareName}" --resource-group "${this.resourceGroup}" --quota ${this.diskSizeGb}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async setupNfsFileShare(): Promise<void> {
|
|
||||||
if (!this.storageAccount || !this.resourceGroup) return;
|
|
||||||
try {
|
|
||||||
await OrchestratorSystem.Run(
|
|
||||||
`az storage share-rm show --storage-account "${this.storageAccount}" --name "${this.fileShareName}" --resource-group "${this.resourceGroup}" --output json`,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
} catch {
|
|
||||||
OrchestratorLogger.log(`[Azure ACI] Creating NFS file share ${this.fileShareName} (${this.diskSizeGb}GB)`);
|
|
||||||
await OrchestratorSystem.Run(
|
|
||||||
`az storage share-rm create --storage-account "${this.storageAccount}" --name "${this.fileShareName}" --resource-group "${this.resourceGroup}" --quota ${this.diskSizeGb} --enabled-protocols NFS`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async setupBlobContainer(): Promise<void> {
|
|
||||||
if (!this.storageAccount || !this.resourceGroup) return;
|
|
||||||
try {
|
|
||||||
await OrchestratorSystem.Run(
|
|
||||||
`az storage container show --name "${this.blobContainer}" --account-name "${this.storageAccount}" --output json`,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
} catch {
|
|
||||||
OrchestratorLogger.log(`[Azure ACI] Creating blob container ${this.blobContainer}`);
|
|
||||||
await OrchestratorSystem.Run(
|
|
||||||
`az storage container create --name "${this.blobContainer}" --account-name "${this.storageAccount}"`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getStorageKey(): Promise<string> {
|
|
||||||
if (!this.storageAccount || !this.resourceGroup) return '';
|
|
||||||
try {
|
|
||||||
const keyJson = await OrchestratorSystem.Run(
|
|
||||||
`az storage account keys list --account-name "${this.storageAccount}" --resource-group "${this.resourceGroup}" --output json`,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
const keys = JSON.parse(keyJson);
|
|
||||||
return keys[0]?.value || '';
|
|
||||||
} catch (error: any) {
|
|
||||||
OrchestratorLogger.logWarning(`[Azure ACI] Could not get storage key: ${error.message}`);
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async buildVolumeFlags(mountdir: string): Promise<string> {
|
|
||||||
switch (this.storageType) {
|
|
||||||
case 'azure-files': {
|
|
||||||
const storageKey = await this.getStorageKey();
|
|
||||||
if (!storageKey) return '';
|
|
||||||
return [
|
|
||||||
`--azure-file-volume-account-name "${this.storageAccount}"`,
|
|
||||||
`--azure-file-volume-account-key "${storageKey}"`,
|
|
||||||
`--azure-file-volume-share-name "${this.fileShareName}"`,
|
|
||||||
`--azure-file-volume-mount-path "${mountdir}"`,
|
|
||||||
].join(' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'azure-files-nfs': {
|
|
||||||
// ACI NFS mount uses a YAML deployment template; for CLI we use the same
|
|
||||||
// azure-file-volume flags but the share must be NFS-enabled and
|
|
||||||
// the container must be in a VNet
|
|
||||||
const storageKey = await this.getStorageKey();
|
|
||||||
if (!storageKey) return '';
|
|
||||||
return [
|
|
||||||
`--azure-file-volume-account-name "${this.storageAccount}"`,
|
|
||||||
`--azure-file-volume-account-key "${storageKey}"`,
|
|
||||||
`--azure-file-volume-share-name "${this.fileShareName}"`,
|
|
||||||
`--azure-file-volume-mount-path "${mountdir}"`,
|
|
||||||
].join(' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'in-memory':
|
|
||||||
// ACI emptyDir volumes require YAML deployment; for simplicity we skip
|
|
||||||
// the volume mount and let the container use its own filesystem
|
|
||||||
OrchestratorLogger.log('[Azure ACI] In-memory mode: using container filesystem (no persistent mount)');
|
|
||||||
return '';
|
|
||||||
|
|
||||||
case 'blob-copy':
|
|
||||||
// No volume mount — artifacts are copied in/out via az storage blob commands
|
|
||||||
return '';
|
|
||||||
|
|
||||||
default:
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async runTaskInWorkflow(
|
|
||||||
buildGuid: string,
|
|
||||||
image: string,
|
|
||||||
commands: string,
|
|
||||||
mountdir: string,
|
|
||||||
workingdir: string,
|
|
||||||
environment: OrchestratorEnvironmentVariable[],
|
|
||||||
secrets: OrchestratorSecret[],
|
|
||||||
): Promise<string> {
|
|
||||||
OrchestratorLogger.log(`[Azure ACI] Running task for build ${buildGuid}`);
|
|
||||||
ResourceTracking.logAllocationSummary('azure-aci task');
|
|
||||||
|
|
||||||
const containerName = `unity-build-${buildGuid}`
|
|
||||||
.toLowerCase()
|
|
||||||
.replace(/[^a-z0-9-]/g, '-')
|
|
||||||
.slice(0, 63);
|
|
||||||
|
|
||||||
// Build environment variable flags
|
|
||||||
const allEnvVars = [
|
|
||||||
...environment.map((env) => `${env.name}=${env.value}`),
|
|
||||||
...secrets.map((s) => `${s.EnvironmentVariable}=${s.ParameterValue}`),
|
|
||||||
];
|
|
||||||
const envFlag = allEnvVars.length > 0 ? `--environment-variables ${allEnvVars.map((e) => `"${e}"`).join(' ')}` : '';
|
|
||||||
|
|
||||||
// Build volume flags based on storage type
|
|
||||||
const volumeFlags = await this.buildVolumeFlags(mountdir);
|
|
||||||
|
|
||||||
const subnetFlag = this.subnetId ? `--subnet "${this.subnetId}"` : '';
|
|
||||||
|
|
||||||
// For blob-copy, wrap the user command with copy-in/copy-out steps
|
|
||||||
let effectiveCommands = commands;
|
|
||||||
if (this.storageType === 'blob-copy' && this.storageAccount && commands) {
|
|
||||||
effectiveCommands = [
|
|
||||||
`az storage blob download-batch --destination "${mountdir}" --source "${this.blobContainer}" --account-name "${this.storageAccount}" 2>/dev/null || true`,
|
|
||||||
commands,
|
|
||||||
`az storage blob upload-batch --source "${mountdir}" --destination "${this.blobContainer}" --account-name "${this.storageAccount}" --overwrite`,
|
|
||||||
].join(' && ');
|
|
||||||
}
|
|
||||||
|
|
||||||
const commandFlag = effectiveCommands
|
|
||||||
? `--command-line "/bin/sh -c '${effectiveCommands.replace(/'/g, "'\\''")}'"`
|
|
||||||
: '';
|
|
||||||
|
|
||||||
const createCmd = [
|
|
||||||
'az container create',
|
|
||||||
`--resource-group "${this.resourceGroup}"`,
|
|
||||||
`--name "${containerName}"`,
|
|
||||||
`--image "${image}"`,
|
|
||||||
`--location "${this.location}"`,
|
|
||||||
`--cpu ${this.cpu}`,
|
|
||||||
`--memory ${this.memoryGb}`,
|
|
||||||
'--restart-policy Never',
|
|
||||||
'--os-type Linux',
|
|
||||||
volumeFlags,
|
|
||||||
envFlag,
|
|
||||||
subnetFlag,
|
|
||||||
commandFlag,
|
|
||||||
'--output json',
|
|
||||||
]
|
|
||||||
.filter(Boolean)
|
|
||||||
.join(' ');
|
|
||||||
|
|
||||||
try {
|
|
||||||
await OrchestratorSystem.Run(createCmd);
|
|
||||||
OrchestratorLogger.log(
|
|
||||||
`[Azure ACI] Container ${containerName} created (storage: ${this.storageType}), waiting for completion...`,
|
|
||||||
);
|
|
||||||
} catch (error: any) {
|
|
||||||
throw new Error(`[Azure ACI] Failed to create container: ${error.message}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const output = await this.waitForContainerCompletion(containerName);
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async waitForContainerCompletion(containerName: string): Promise<string> {
|
|
||||||
const maxWaitMs = 24 * 60 * 60 * 1000;
|
|
||||||
const pollIntervalMs = 15_000;
|
|
||||||
const startTime = Date.now();
|
|
||||||
let lastLogLength = 0;
|
|
||||||
|
|
||||||
while (Date.now() - startTime < maxWaitMs) {
|
|
||||||
try {
|
|
||||||
const stateJson = await OrchestratorSystem.Run(
|
|
||||||
`az container show --resource-group "${this.resourceGroup}" --name "${containerName}" --output json`,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
|
|
||||||
const state = JSON.parse(stateJson);
|
|
||||||
const containerState =
|
|
||||||
state.containers?.[0]?.instanceView?.currentState?.state || state.instanceView?.state || 'Unknown';
|
|
||||||
const provisioningState = state.provisioningState || 'Unknown';
|
|
||||||
|
|
||||||
// Stream logs incrementally
|
|
||||||
try {
|
|
||||||
const logs = await OrchestratorSystem.Run(
|
|
||||||
`az container logs --resource-group "${this.resourceGroup}" --name "${containerName}"`,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
if (logs && logs.length > lastLogLength) {
|
|
||||||
const newLogs = logs.slice(lastLogLength);
|
|
||||||
for (const line of newLogs.split('\n')) {
|
|
||||||
if (line.trim()) {
|
|
||||||
OrchestratorLogger.log(`[Build] ${line}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lastLogLength = logs.length;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// Logs may not be available yet
|
|
||||||
}
|
|
||||||
|
|
||||||
if (containerState === 'Terminated' || provisioningState === 'Succeeded') {
|
|
||||||
const exitCode = state.containers?.[0]?.instanceView?.currentState?.exitCode;
|
|
||||||
if (exitCode !== undefined && exitCode !== 0) {
|
|
||||||
throw new Error(`[Azure ACI] Container exited with code ${exitCode}`);
|
|
||||||
}
|
|
||||||
OrchestratorLogger.log('[Azure ACI] Container completed successfully');
|
|
||||||
try {
|
|
||||||
return await OrchestratorSystem.Run(
|
|
||||||
`az container logs --resource-group "${this.resourceGroup}" --name "${containerName}"`,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
} catch {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (provisioningState === 'Failed') {
|
|
||||||
const detail =
|
|
||||||
state.containers?.[0]?.instanceView?.currentState?.detailStatus ||
|
|
||||||
state.containers?.[0]?.instanceView?.events?.map((e: any) => e.message).join('; ') ||
|
|
||||||
'Unknown error';
|
|
||||||
throw new Error(`[Azure ACI] Container provisioning failed: ${detail}`);
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
|
||||||
if (error.message?.includes('Container provisioning failed') || error.message?.includes('exited with code')) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
OrchestratorLogger.logWarning(`[Azure ACI] Polling error: ${error.message}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error('[Azure ACI] Container execution timed out after 24 hours');
|
|
||||||
}
|
|
||||||
|
|
||||||
async cleanupWorkflow(
|
|
||||||
buildParameters: BuildParameters,
|
|
||||||
branchName: string,
|
|
||||||
defaultSecretsArray: { ParameterKey: string; EnvironmentVariable: string; ParameterValue: string }[],
|
|
||||||
) {
|
|
||||||
OrchestratorLogger.log('[Azure ACI] Cleaning up workflow');
|
|
||||||
}
|
|
||||||
|
|
||||||
async garbageCollect(
|
|
||||||
filter: string,
|
|
||||||
previewOnly: boolean,
|
|
||||||
olderThan: Number,
|
|
||||||
fullCache: boolean,
|
|
||||||
baseDependencies: boolean,
|
|
||||||
): Promise<string> {
|
|
||||||
OrchestratorLogger.log('[Azure ACI] Garbage collecting old container groups');
|
|
||||||
|
|
||||||
try {
|
|
||||||
const containersJson = await OrchestratorSystem.Run(
|
|
||||||
`az container list --resource-group "${this.resourceGroup}" --output json`,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
|
|
||||||
const containers = JSON.parse(containersJson || '[]');
|
|
||||||
const cutoffDate = new Date();
|
|
||||||
cutoffDate.setDate(cutoffDate.getDate() - Number(olderThan));
|
|
||||||
|
|
||||||
let deletedCount = 0;
|
|
||||||
for (const container of containers) {
|
|
||||||
const name = container.name || '';
|
|
||||||
if (!name.startsWith('unity-build-')) continue;
|
|
||||||
|
|
||||||
const createdAt = new Date(container.tags?.createdAt || container.properties?.provisioningState || 0);
|
|
||||||
const state = container.containers?.[0]?.instanceView?.currentState?.state || '';
|
|
||||||
|
|
||||||
if (state === 'Terminated' || createdAt < cutoffDate) {
|
|
||||||
if (previewOnly) {
|
|
||||||
OrchestratorLogger.log(`[Azure ACI] Would delete: ${name}`);
|
|
||||||
} else {
|
|
||||||
await OrchestratorSystem.Run(
|
|
||||||
`az container delete --resource-group "${this.resourceGroup}" --name "${name}" --yes`,
|
|
||||||
);
|
|
||||||
deletedCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return `Garbage collected ${deletedCount} Azure container instances`;
|
|
||||||
} catch (error: any) {
|
|
||||||
OrchestratorLogger.logWarning(`[Azure ACI] Garbage collection failed: ${error.message}`);
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async listResources(): Promise<ProviderResource[]> {
|
|
||||||
try {
|
|
||||||
const containersJson = await OrchestratorSystem.Run(
|
|
||||||
`az container list --resource-group "${this.resourceGroup}" --output json`,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
|
|
||||||
const containers = JSON.parse(containersJson || '[]');
|
|
||||||
return containers
|
|
||||||
.filter((c: any) => (c.name || '').startsWith('unity-build-'))
|
|
||||||
.map((c: any) => ({ Name: c.name || '' }));
|
|
||||||
} catch {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
listWorkflow(): Promise<ProviderWorkflow[]> {
|
|
||||||
throw new Error('[Azure ACI] listWorkflow not implemented for this experimental provider');
|
|
||||||
}
|
|
||||||
|
|
||||||
async watchWorkflow(): Promise<string> {
|
|
||||||
throw new Error('[Azure ACI] watchWorkflow not implemented for this experimental provider');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default AzureAciProvider;
|
|
||||||
@@ -1,435 +0,0 @@
|
|||||||
/**
|
|
||||||
* Google Cloud Run Jobs Provider (Experimental)
|
|
||||||
*
|
|
||||||
* Executes Unity builds as Cloud Run Jobs with configurable storage backends.
|
|
||||||
*
|
|
||||||
* Storage types:
|
|
||||||
* - gcs-fuse: Mount a GCS bucket as a POSIX filesystem via GCS FUSE sidecar.
|
|
||||||
* Unlimited size, best for large sequential reads/writes.
|
|
||||||
* Requires: gcpBucket
|
|
||||||
* - gcs-copy: Copy artifacts in/out of GCS before/after the build via gsutil.
|
|
||||||
* No mount overhead, simpler, works everywhere.
|
|
||||||
* Requires: gcpBucket
|
|
||||||
* - nfs: Mount a Filestore NFS share. True POSIX semantics, good random I/O,
|
|
||||||
* up to 100 TiB. Best for Library caching (many small random reads).
|
|
||||||
* Requires: gcpFilestoreIp, gcpFilestoreShare
|
|
||||||
* - in-memory: tmpfs volume (emptyDir). Fastest I/O but volatile and limited to 32 GiB.
|
|
||||||
* Good for scratch/temp space during builds.
|
|
||||||
*
|
|
||||||
* Prerequisites:
|
|
||||||
* - Google Cloud SDK authenticated (GOOGLE_APPLICATION_CREDENTIALS or gcloud auth)
|
|
||||||
* - Cloud Run Jobs API enabled
|
|
||||||
* - Service account with roles: Cloud Run Admin, Storage Admin, Logs Viewer
|
|
||||||
*
|
|
||||||
* @experimental This provider is experimental. APIs and behavior may change.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { ProviderInterface } from '../provider-interface';
|
|
||||||
import BuildParameters from '../../../build-parameters';
|
|
||||||
import OrchestratorLogger from '../../services/core/orchestrator-logger';
|
|
||||||
import OrchestratorEnvironmentVariable from '../../options/orchestrator-environment-variable';
|
|
||||||
import OrchestratorSecret from '../../options/orchestrator-secret';
|
|
||||||
import { ProviderResource } from '../provider-resource';
|
|
||||||
import { ProviderWorkflow } from '../provider-workflow';
|
|
||||||
import { OrchestratorSystem } from '../../services/core/orchestrator-system';
|
|
||||||
import { Input } from '../../..';
|
|
||||||
import ResourceTracking from '../../services/core/resource-tracking';
|
|
||||||
|
|
||||||
type GcpStorageType = 'gcs-fuse' | 'gcs-copy' | 'nfs' | 'in-memory';
|
|
||||||
|
|
||||||
class GcpCloudRunProvider implements ProviderInterface {
|
|
||||||
private readonly project: string;
|
|
||||||
private readonly region: string;
|
|
||||||
private readonly storageType: GcpStorageType;
|
|
||||||
private readonly bucket: string;
|
|
||||||
private readonly filestoreIp: string;
|
|
||||||
private readonly filestoreShare: string;
|
|
||||||
private readonly machineType: string;
|
|
||||||
private readonly diskSizeGb: number;
|
|
||||||
private readonly serviceAccount: string;
|
|
||||||
private readonly vpcConnector: string;
|
|
||||||
private buildParameters: BuildParameters;
|
|
||||||
|
|
||||||
constructor(buildParameters: BuildParameters) {
|
|
||||||
this.buildParameters = buildParameters;
|
|
||||||
this.project = buildParameters.gcpProject || process.env.GOOGLE_CLOUD_PROJECT || process.env.GCLOUD_PROJECT || '';
|
|
||||||
this.region = buildParameters.gcpRegion || Input.region || 'us-central1';
|
|
||||||
this.storageType = (buildParameters.gcpStorageType || 'gcs-fuse') as GcpStorageType;
|
|
||||||
this.bucket = buildParameters.gcpBucket || '';
|
|
||||||
this.filestoreIp = buildParameters.gcpFilestoreIp || '';
|
|
||||||
this.filestoreShare = buildParameters.gcpFilestoreShare || '/share1';
|
|
||||||
this.machineType = buildParameters.gcpMachineType || 'e2-standard-4';
|
|
||||||
this.diskSizeGb = Number.parseInt(buildParameters.gcpDiskSizeGb || '100', 10);
|
|
||||||
this.serviceAccount = buildParameters.gcpServiceAccount || '';
|
|
||||||
this.vpcConnector = buildParameters.gcpVpcConnector || '';
|
|
||||||
|
|
||||||
OrchestratorLogger.log('[GCP Cloud Run] Provider initialized (EXPERIMENTAL)');
|
|
||||||
OrchestratorLogger.log(`[GCP Cloud Run] Project: ${this.project || '(auto-detect)'}`);
|
|
||||||
OrchestratorLogger.log(`[GCP Cloud Run] Region: ${this.region}`);
|
|
||||||
OrchestratorLogger.log(`[GCP Cloud Run] Storage: ${this.storageType}`);
|
|
||||||
|
|
||||||
this.validateStorageConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
private validateStorageConfig(): void {
|
|
||||||
switch (this.storageType) {
|
|
||||||
case 'gcs-fuse':
|
|
||||||
case 'gcs-copy':
|
|
||||||
if (!this.bucket) {
|
|
||||||
OrchestratorLogger.logWarning(
|
|
||||||
`[GCP Cloud Run] Storage type '${this.storageType}' requires gcpBucket to be set.`,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
OrchestratorLogger.log(`[GCP Cloud Run] Bucket: gs://${this.bucket}`);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'nfs':
|
|
||||||
if (!this.filestoreIp) {
|
|
||||||
OrchestratorLogger.logWarning('[GCP Cloud Run] Storage type "nfs" requires gcpFilestoreIp to be set.');
|
|
||||||
} else {
|
|
||||||
OrchestratorLogger.log(`[GCP Cloud Run] Filestore: ${this.filestoreIp}:${this.filestoreShare}`);
|
|
||||||
}
|
|
||||||
if (!this.vpcConnector) {
|
|
||||||
OrchestratorLogger.logWarning(
|
|
||||||
'[GCP Cloud Run] NFS storage usually requires gcpVpcConnector for private network access to Filestore.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'in-memory':
|
|
||||||
OrchestratorLogger.log(`[GCP Cloud Run] In-memory volume: ${Math.min(this.diskSizeGb, 32)} GiB (max 32)`);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
OrchestratorLogger.logWarning(
|
|
||||||
`[GCP Cloud Run] Unknown storage type '${this.storageType}'. Valid: gcs-fuse, gcs-copy, nfs, in-memory`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.project) {
|
|
||||||
OrchestratorLogger.logWarning(
|
|
||||||
'[GCP Cloud Run] No project specified. Set gcpProject input or GOOGLE_CLOUD_PROJECT env var.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async setupWorkflow(
|
|
||||||
buildGuid: string,
|
|
||||||
buildParameters: BuildParameters,
|
|
||||||
branchName: string,
|
|
||||||
defaultSecretsArray: { ParameterKey: string; EnvironmentVariable: string; ParameterValue: string }[],
|
|
||||||
) {
|
|
||||||
OrchestratorLogger.log(`[GCP Cloud Run] Setting up workflow for build ${buildGuid}`);
|
|
||||||
ResourceTracking.logAllocationSummary('gcp-cloud-run setup');
|
|
||||||
|
|
||||||
// Verify gcloud CLI is available
|
|
||||||
try {
|
|
||||||
await OrchestratorSystem.Run('gcloud --version', false, true);
|
|
||||||
OrchestratorLogger.log('[GCP Cloud Run] gcloud CLI detected');
|
|
||||||
} catch {
|
|
||||||
throw new Error(
|
|
||||||
'[GCP Cloud Run] gcloud CLI not found. Install Google Cloud SDK: https://cloud.google.com/sdk/docs/install',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify Cloud Run Jobs API is enabled
|
|
||||||
try {
|
|
||||||
const projectFlag = this.project ? `--project=${this.project}` : '';
|
|
||||||
await OrchestratorSystem.Run(
|
|
||||||
`gcloud services list --enabled --filter="name:run.googleapis.com" ${projectFlag} --format="value(name)"`,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
} catch {
|
|
||||||
OrchestratorLogger.logWarning(
|
|
||||||
'[GCP Cloud Run] Could not verify Cloud Run API status. Ensure run.googleapis.com is enabled.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Storage-specific setup
|
|
||||||
if ((this.storageType === 'gcs-fuse' || this.storageType === 'gcs-copy') && this.bucket) {
|
|
||||||
await this.ensureBucketExists();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async ensureBucketExists(): Promise<void> {
|
|
||||||
try {
|
|
||||||
await OrchestratorSystem.Run(
|
|
||||||
`gcloud storage buckets describe gs://${this.bucket} --format="value(name)"`,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
OrchestratorLogger.log(`[GCP Cloud Run] Bucket gs://${this.bucket} exists`);
|
|
||||||
} catch {
|
|
||||||
OrchestratorLogger.log(`[GCP Cloud Run] Creating bucket gs://${this.bucket}`);
|
|
||||||
const projectFlag = this.project ? `--project=${this.project}` : '';
|
|
||||||
await OrchestratorSystem.Run(
|
|
||||||
`gcloud storage buckets create gs://${this.bucket} --location=${this.region} ${projectFlag}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private buildVolumeFlags(mountdir: string): { volumeFlags: string; mountFlags: string } {
|
|
||||||
switch (this.storageType) {
|
|
||||||
case 'gcs-fuse':
|
|
||||||
if (!this.bucket) return { volumeFlags: '', mountFlags: '' };
|
|
||||||
return {
|
|
||||||
volumeFlags: `--add-volume=name=gcs-fuse,type=cloud-storage,bucket=${this.bucket}`,
|
|
||||||
mountFlags: `--add-volume-mount=volume=gcs-fuse,mount-path=${mountdir}`,
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'nfs':
|
|
||||||
if (!this.filestoreIp) return { volumeFlags: '', mountFlags: '' };
|
|
||||||
return {
|
|
||||||
volumeFlags: `--add-volume=name=nfs-vol,type=nfs,location=${this.filestoreIp}:${this.filestoreShare}`,
|
|
||||||
mountFlags: `--add-volume-mount=volume=nfs-vol,mount-path=${mountdir}`,
|
|
||||||
};
|
|
||||||
|
|
||||||
case 'in-memory': {
|
|
||||||
const sizeGib = Math.min(this.diskSizeGb, 32);
|
|
||||||
return {
|
|
||||||
volumeFlags: `--add-volume=name=tmpfs-vol,type=in-memory,size-limit=${sizeGib}Gi`,
|
|
||||||
mountFlags: `--add-volume-mount=volume=tmpfs-vol,mount-path=${mountdir}`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'gcs-copy':
|
|
||||||
// No volume mount — artifacts are copied in/out via gsutil commands
|
|
||||||
return { volumeFlags: '', mountFlags: '' };
|
|
||||||
|
|
||||||
default:
|
|
||||||
return { volumeFlags: '', mountFlags: '' };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async copyArtifactsIn(mountdir: string): Promise<void> {
|
|
||||||
if (this.storageType !== 'gcs-copy' || !this.bucket) return;
|
|
||||||
OrchestratorLogger.log(`[GCP Cloud Run] Copying artifacts from gs://${this.bucket} to ${mountdir}`);
|
|
||||||
try {
|
|
||||||
await OrchestratorSystem.Run(`gcloud storage cp -r "gs://${this.bucket}/*" "${mountdir}/" || true`, false, true);
|
|
||||||
} catch {
|
|
||||||
OrchestratorLogger.log('[GCP Cloud Run] No existing artifacts to restore (bucket may be empty)');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async copyArtifactsOut(mountdir: string): Promise<void> {
|
|
||||||
if (this.storageType !== 'gcs-copy' || !this.bucket) return;
|
|
||||||
OrchestratorLogger.log(`[GCP Cloud Run] Uploading artifacts from ${mountdir} to gs://${this.bucket}`);
|
|
||||||
await OrchestratorSystem.Run(`gcloud storage cp -r "${mountdir}/*" "gs://${this.bucket}/"`, false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
async runTaskInWorkflow(
|
|
||||||
buildGuid: string,
|
|
||||||
image: string,
|
|
||||||
commands: string,
|
|
||||||
mountdir: string,
|
|
||||||
workingdir: string,
|
|
||||||
environment: OrchestratorEnvironmentVariable[],
|
|
||||||
secrets: OrchestratorSecret[],
|
|
||||||
): Promise<string> {
|
|
||||||
OrchestratorLogger.log(`[GCP Cloud Run] Running task for build ${buildGuid}`);
|
|
||||||
ResourceTracking.logAllocationSummary('gcp-cloud-run task');
|
|
||||||
|
|
||||||
const jobName = `unity-build-${buildGuid}`
|
|
||||||
.toLowerCase()
|
|
||||||
.replace(/[^a-z0-9-]/g, '-')
|
|
||||||
.slice(0, 63);
|
|
||||||
const projectFlag = this.project ? `--project=${this.project}` : '';
|
|
||||||
|
|
||||||
// Build environment variable flags
|
|
||||||
const envFlags = environment
|
|
||||||
.map((env) => `${env.name}=${env.value}`)
|
|
||||||
.concat(secrets.map((s) => `${s.EnvironmentVariable}=${s.ParameterValue}`));
|
|
||||||
const envString = envFlags.length > 0 ? `--set-env-vars="${envFlags.join(',')}"` : '';
|
|
||||||
|
|
||||||
// Build storage volume flags
|
|
||||||
const { volumeFlags, mountFlags } = this.buildVolumeFlags(mountdir);
|
|
||||||
|
|
||||||
// For gcs-copy, wrap the user command with copy-in/copy-out steps
|
|
||||||
let effectiveCommands = commands;
|
|
||||||
if (this.storageType === 'gcs-copy' && this.bucket && commands) {
|
|
||||||
effectiveCommands = [
|
|
||||||
`gcloud storage cp -r "gs://${this.bucket}/*" "${mountdir}/" 2>/dev/null || true`,
|
|
||||||
commands,
|
|
||||||
`gcloud storage cp -r "${mountdir}/*" "gs://${this.bucket}/"`,
|
|
||||||
].join(' && ');
|
|
||||||
}
|
|
||||||
|
|
||||||
const saFlag = this.serviceAccount ? `--service-account=${this.serviceAccount}` : '';
|
|
||||||
const vpcFlag = this.vpcConnector ? `--vpc-connector=${this.vpcConnector}` : '';
|
|
||||||
|
|
||||||
// Create the Cloud Run Job
|
|
||||||
const createCmd = [
|
|
||||||
'gcloud run jobs create',
|
|
||||||
jobName,
|
|
||||||
`--image=${image}`,
|
|
||||||
`--region=${this.region}`,
|
|
||||||
'--task-timeout=86400s',
|
|
||||||
'--max-retries=0',
|
|
||||||
'--cpu=4',
|
|
||||||
'--memory=16Gi',
|
|
||||||
volumeFlags,
|
|
||||||
mountFlags,
|
|
||||||
envString,
|
|
||||||
saFlag,
|
|
||||||
vpcFlag,
|
|
||||||
projectFlag,
|
|
||||||
'--format=json',
|
|
||||||
'--quiet',
|
|
||||||
]
|
|
||||||
.filter(Boolean)
|
|
||||||
.join(' ');
|
|
||||||
|
|
||||||
try {
|
|
||||||
await OrchestratorSystem.Run(createCmd);
|
|
||||||
OrchestratorLogger.log(`[GCP Cloud Run] Job ${jobName} created`);
|
|
||||||
} catch (error: any) {
|
|
||||||
if (error.message?.includes('already exists')) {
|
|
||||||
OrchestratorLogger.log(`[GCP Cloud Run] Job ${jobName} already exists, updating...`);
|
|
||||||
const updateCmd = createCmd.replace('jobs create', 'jobs update');
|
|
||||||
await OrchestratorSystem.Run(updateCmd);
|
|
||||||
} else {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Override the command if provided
|
|
||||||
if (effectiveCommands) {
|
|
||||||
const updateCmd = [
|
|
||||||
'gcloud run jobs update',
|
|
||||||
jobName,
|
|
||||||
`--region=${this.region}`,
|
|
||||||
'--command="/bin/sh"',
|
|
||||||
`--args="-c,${effectiveCommands}"`,
|
|
||||||
projectFlag,
|
|
||||||
'--quiet',
|
|
||||||
]
|
|
||||||
.filter(Boolean)
|
|
||||||
.join(' ');
|
|
||||||
|
|
||||||
await OrchestratorSystem.Run(updateCmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute the job
|
|
||||||
OrchestratorLogger.log(`[GCP Cloud Run] Executing job ${jobName} (storage: ${this.storageType})...`);
|
|
||||||
const executeCmd = [
|
|
||||||
'gcloud run jobs execute',
|
|
||||||
jobName,
|
|
||||||
`--region=${this.region}`,
|
|
||||||
projectFlag,
|
|
||||||
'--wait',
|
|
||||||
'--format=json',
|
|
||||||
'--quiet',
|
|
||||||
]
|
|
||||||
.filter(Boolean)
|
|
||||||
.join(' ');
|
|
||||||
|
|
||||||
let output = '';
|
|
||||||
try {
|
|
||||||
output = await OrchestratorSystem.Run(executeCmd);
|
|
||||||
OrchestratorLogger.log('[GCP Cloud Run] Job execution completed');
|
|
||||||
} catch (error: any) {
|
|
||||||
await this.streamJobLogs(jobName);
|
|
||||||
throw new Error(`[GCP Cloud Run] Job execution failed: ${error.message}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.streamJobLogs(jobName);
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async streamJobLogs(jobName: string): Promise<void> {
|
|
||||||
const projectFlag = this.project ? `--project=${this.project}` : '';
|
|
||||||
try {
|
|
||||||
const logs = await OrchestratorSystem.Run(
|
|
||||||
`gcloud logging read "resource.type=cloud_run_job AND resource.labels.job_name=${jobName}" ${projectFlag} --limit=1000 --format="value(textPayload)" --order=asc`,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
if (logs) {
|
|
||||||
for (const line of logs.split('\n')) {
|
|
||||||
if (line.trim()) {
|
|
||||||
OrchestratorLogger.log(`[Build] ${line}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
OrchestratorLogger.logWarning('[GCP Cloud Run] Could not retrieve job logs');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async cleanupWorkflow(
|
|
||||||
buildParameters: BuildParameters,
|
|
||||||
branchName: string,
|
|
||||||
defaultSecretsArray: { ParameterKey: string; EnvironmentVariable: string; ParameterValue: string }[],
|
|
||||||
) {
|
|
||||||
OrchestratorLogger.log('[GCP Cloud Run] Cleaning up workflow');
|
|
||||||
}
|
|
||||||
|
|
||||||
async garbageCollect(
|
|
||||||
filter: string,
|
|
||||||
previewOnly: boolean,
|
|
||||||
olderThan: Number,
|
|
||||||
fullCache: boolean,
|
|
||||||
baseDependencies: boolean,
|
|
||||||
): Promise<string> {
|
|
||||||
OrchestratorLogger.log('[GCP Cloud Run] Garbage collecting old jobs');
|
|
||||||
const projectFlag = this.project ? `--project=${this.project}` : '';
|
|
||||||
|
|
||||||
try {
|
|
||||||
const jobsJson = await OrchestratorSystem.Run(
|
|
||||||
`gcloud run jobs list --region=${this.region} ${projectFlag} --filter="metadata.name~unity-build-" --format="json(metadata.name,metadata.creationTimestamp)"`,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
|
|
||||||
const jobs = JSON.parse(jobsJson || '[]');
|
|
||||||
const cutoffDate = new Date();
|
|
||||||
cutoffDate.setDate(cutoffDate.getDate() - Number(olderThan));
|
|
||||||
|
|
||||||
let deletedCount = 0;
|
|
||||||
for (const job of jobs) {
|
|
||||||
const createdAt = new Date(job.metadata?.creationTimestamp || 0);
|
|
||||||
if (createdAt < cutoffDate) {
|
|
||||||
const name = job.metadata?.name;
|
|
||||||
if (previewOnly) {
|
|
||||||
OrchestratorLogger.log(`[GCP Cloud Run] Would delete: ${name}`);
|
|
||||||
} else {
|
|
||||||
await OrchestratorSystem.Run(
|
|
||||||
`gcloud run jobs delete ${name} --region=${this.region} ${projectFlag} --quiet`,
|
|
||||||
);
|
|
||||||
deletedCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return `Garbage collected ${deletedCount} Cloud Run jobs`;
|
|
||||||
} catch (error: any) {
|
|
||||||
OrchestratorLogger.logWarning(`[GCP Cloud Run] Garbage collection failed: ${error.message}`);
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async listResources(): Promise<ProviderResource[]> {
|
|
||||||
const projectFlag = this.project ? `--project=${this.project}` : '';
|
|
||||||
try {
|
|
||||||
const jobsJson = await OrchestratorSystem.Run(
|
|
||||||
`gcloud run jobs list --region=${this.region} ${projectFlag} --filter="metadata.name~unity-build-" --format="json(metadata.name)"`,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
|
|
||||||
const jobs = JSON.parse(jobsJson || '[]');
|
|
||||||
return jobs.map((job: any) => ({ Name: job.metadata?.name || '' }));
|
|
||||||
} catch {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
listWorkflow(): Promise<ProviderWorkflow[]> {
|
|
||||||
throw new Error('[GCP Cloud Run] listWorkflow not implemented for this experimental provider');
|
|
||||||
}
|
|
||||||
|
|
||||||
async watchWorkflow(): Promise<string> {
|
|
||||||
throw new Error('[GCP Cloud Run] watchWorkflow not implemented for this experimental provider');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default GcpCloudRunProvider;
|
|
||||||
@@ -62,8 +62,6 @@ export default async function loadProvider(
|
|||||||
'local-docker': './docker',
|
'local-docker': './docker',
|
||||||
'local-system': './local',
|
'local-system': './local',
|
||||||
local: './local',
|
local: './local',
|
||||||
'gcp-cloud-run': './gcp-cloud-run',
|
|
||||||
'azure-aci': './azure-aci',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
modulePath = providerModuleMap[providerSource] || providerSource;
|
modulePath = providerModuleMap[providerSource] || providerSource;
|
||||||
@@ -138,7 +136,7 @@ export class ProviderLoader {
|
|||||||
* @returns string[] - Array of available provider names
|
* @returns string[] - Array of available provider names
|
||||||
*/
|
*/
|
||||||
static getAvailableProviders(): string[] {
|
static getAvailableProviders(): string[] {
|
||||||
return ['aws', 'k8s', 'test', 'local-docker', 'local-system', 'local', 'gcp-cloud-run', 'azure-aci'];
|
return ['aws', 'k8s', 'test', 'local-docker', 'local-system', 'local'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -302,6 +302,7 @@ export class RemoteClient {
|
|||||||
|
|
||||||
RemoteClientLogger.log(`Initializing source repository for cloning with caching of LFS files`);
|
RemoteClientLogger.log(`Initializing source repository for cloning with caching of LFS files`);
|
||||||
await OrchestratorSystem.Run(`git config --global advice.detachedHead false`);
|
await OrchestratorSystem.Run(`git config --global advice.detachedHead false`);
|
||||||
|
await OrchestratorFolders.configureGitAuth();
|
||||||
RemoteClientLogger.log(`Cloning the repository being built:`);
|
RemoteClientLogger.log(`Cloning the repository being built:`);
|
||||||
await OrchestratorSystem.Run(`git config --global filter.lfs.smudge "git-lfs smudge --skip -- %f"`);
|
await OrchestratorSystem.Run(`git config --global filter.lfs.smudge "git-lfs smudge --skip -- %f"`);
|
||||||
await OrchestratorSystem.Run(`git config --global filter.lfs.process "git-lfs filter-process --skip"`);
|
await OrchestratorSystem.Run(`git config --global filter.lfs.process "git-lfs filter-process --skip"`);
|
||||||
@@ -411,12 +412,7 @@ export class RemoteClient {
|
|||||||
const gitPrivateToken = process.env.GIT_PRIVATE_TOKEN;
|
const gitPrivateToken = process.env.GIT_PRIVATE_TOKEN;
|
||||||
if (gitPrivateToken) {
|
if (gitPrivateToken) {
|
||||||
RemoteClientLogger.log(`Attempting to pull LFS files with GIT_PRIVATE_TOKEN...`);
|
RemoteClientLogger.log(`Attempting to pull LFS files with GIT_PRIVATE_TOKEN...`);
|
||||||
await OrchestratorSystem.Run(`git config --global --unset-all url."https://github.com/".insteadOf || true`);
|
await RemoteClient.configureTokenAuth(gitPrivateToken);
|
||||||
await OrchestratorSystem.Run(`git config --global --unset-all url."ssh://git@github.com/".insteadOf || true`);
|
|
||||||
await OrchestratorSystem.Run(`git config --global --unset-all url."git@github.com".insteadOf || true`);
|
|
||||||
await OrchestratorSystem.Run(
|
|
||||||
`git config --global url."https://${gitPrivateToken}@github.com/".insteadOf "https://github.com/"`,
|
|
||||||
);
|
|
||||||
await OrchestratorSystem.Run(`git lfs pull`, true);
|
await OrchestratorSystem.Run(`git lfs pull`, true);
|
||||||
await OrchestratorSystem.Run(`git lfs checkout || true`, true);
|
await OrchestratorSystem.Run(`git lfs checkout || true`, true);
|
||||||
RemoteClientLogger.log(`Successfully pulled LFS files with GIT_PRIVATE_TOKEN`);
|
RemoteClientLogger.log(`Successfully pulled LFS files with GIT_PRIVATE_TOKEN`);
|
||||||
@@ -432,12 +428,7 @@ export class RemoteClient {
|
|||||||
const githubToken = process.env.GITHUB_TOKEN;
|
const githubToken = process.env.GITHUB_TOKEN;
|
||||||
if (githubToken) {
|
if (githubToken) {
|
||||||
RemoteClientLogger.log(`Attempting to pull LFS files with GITHUB_TOKEN fallback...`);
|
RemoteClientLogger.log(`Attempting to pull LFS files with GITHUB_TOKEN fallback...`);
|
||||||
await OrchestratorSystem.Run(`git config --global --unset-all url."https://github.com/".insteadOf || true`);
|
await RemoteClient.configureTokenAuth(githubToken);
|
||||||
await OrchestratorSystem.Run(`git config --global --unset-all url."ssh://git@github.com/".insteadOf || true`);
|
|
||||||
await OrchestratorSystem.Run(`git config --global --unset-all url."git@github.com".insteadOf || true`);
|
|
||||||
await OrchestratorSystem.Run(
|
|
||||||
`git config --global url."https://${githubToken}@github.com/".insteadOf "https://github.com/"`,
|
|
||||||
);
|
|
||||||
await OrchestratorSystem.Run(`git lfs pull`, true);
|
await OrchestratorSystem.Run(`git lfs pull`, true);
|
||||||
await OrchestratorSystem.Run(`git lfs checkout || true`, true);
|
await OrchestratorSystem.Run(`git lfs checkout || true`, true);
|
||||||
RemoteClientLogger.log(`Successfully pulled LFS files with GITHUB_TOKEN`);
|
RemoteClientLogger.log(`Successfully pulled LFS files with GITHUB_TOKEN`);
|
||||||
@@ -501,4 +492,25 @@ export class RemoteClient {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure git authentication for a token. In header mode (default), uses
|
||||||
|
* http.extraHeader so the token never appears in URLs or git config output.
|
||||||
|
* In url mode (legacy), uses url.insteadOf to embed the token in URLs.
|
||||||
|
*/
|
||||||
|
private static async configureTokenAuth(token: string): Promise<void> {
|
||||||
|
if (OrchestratorFolders.useHeaderAuth) {
|
||||||
|
const encoded = Buffer.from(`x-access-token:${token}`).toString('base64');
|
||||||
|
await OrchestratorSystem.Run(
|
||||||
|
`git config --global http.https://github.com/.extraHeader "Authorization: Basic ${encoded}"`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await OrchestratorSystem.Run(`git config --global --unset-all url."https://github.com/".insteadOf || true`);
|
||||||
|
await OrchestratorSystem.Run(`git config --global --unset-all url."ssh://git@github.com/".insteadOf || true`);
|
||||||
|
await OrchestratorSystem.Run(`git config --global --unset-all url."git@github.com".insteadOf || true`);
|
||||||
|
await OrchestratorSystem.Run(
|
||||||
|
`git config --global url."https://${token}@github.com/".insteadOf "https://github.com/"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ printenv
|
|||||||
git config --global advice.detachedHead false
|
git config --global advice.detachedHead false
|
||||||
git config --global filter.lfs.smudge "git-lfs smudge --skip -- %f"
|
git config --global filter.lfs.smudge "git-lfs smudge --skip -- %f"
|
||||||
git config --global filter.lfs.process "git-lfs filter-process --skip"
|
git config --global filter.lfs.process "git-lfs filter-process --skip"
|
||||||
|
${OrchestratorFolders.gitAuthConfigScript}
|
||||||
BRANCH="${Orchestrator.buildParameters.orchestratorBranch}"
|
BRANCH="${Orchestrator.buildParameters.orchestratorBranch}"
|
||||||
REPO="${OrchestratorFolders.unityBuilderRepoUrl}"
|
REPO="${OrchestratorFolders.unityBuilderRepoUrl}"
|
||||||
if [ -n "$(git ls-remote --heads "$REPO" "$BRANCH" 2>/dev/null)" ]; then
|
if [ -n "$(git ls-remote --heads "$REPO" "$BRANCH" 2>/dev/null)" ]; then
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ export class BuildAutomationWorkflow implements WorkflowInterface {
|
|||||||
const commands = `mkdir -p ${OrchestratorFolders.ToLinuxFolder(
|
const commands = `mkdir -p ${OrchestratorFolders.ToLinuxFolder(
|
||||||
OrchestratorFolders.builderPathAbsolute,
|
OrchestratorFolders.builderPathAbsolute,
|
||||||
)}
|
)}
|
||||||
|
${OrchestratorFolders.gitAuthConfigScript}
|
||||||
BRANCH="${Orchestrator.buildParameters.orchestratorBranch}"
|
BRANCH="${Orchestrator.buildParameters.orchestratorBranch}"
|
||||||
REPO="${OrchestratorFolders.unityBuilderRepoUrl}"
|
REPO="${OrchestratorFolders.unityBuilderRepoUrl}"
|
||||||
DEST="${OrchestratorFolders.ToLinuxFolder(OrchestratorFolders.builderPathAbsolute)}"
|
DEST="${OrchestratorFolders.ToLinuxFolder(OrchestratorFolders.builderPathAbsolute)}"
|
||||||
|
|||||||
Reference in New Issue
Block a user