mirror of
https://github.com/game-ci/unity-builder.git
synced 2026-05-31 22:06:16 -07:00
Compare commits
5 Commits
feature/or
...
feature/cl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5fd895bd6 | ||
|
|
302a250b3d | ||
|
|
d17b099593 | ||
|
|
f4bc5d20c4 | ||
|
|
d8563369e1 |
9
.github/workflows/orchestrator-integrity.yml
vendored
9
.github/workflows/orchestrator-integrity.yml
vendored
@@ -196,15 +196,6 @@ jobs:
|
||||
fi
|
||||
- run: yarn install --frozen-lockfile
|
||||
# ==========================================
|
||||
# FAST UNIT TESTS (no infra required, fast-fail gate)
|
||||
# ==========================================
|
||||
- name: Run orchestrator unit tests (fast, no infra)
|
||||
timeout-minutes: 2
|
||||
run: >-
|
||||
yarn run test
|
||||
--testPathPattern="orchestrator-guid|orchestrator-folders|task-parameter-serializer|follow-log-stream-service|runner-availability-service|provider-url-parser|provider-loader|provider-git-manager|orchestrator-image|orchestrator-hooks|orchestrator-github-checks"
|
||||
--verbose --detectOpenHandles --forceExit --runInBand
|
||||
# ==========================================
|
||||
# K8S TESTS SECTION
|
||||
# ==========================================
|
||||
- name: Clean up disk space before K8s tests
|
||||
|
||||
118
action.yml
118
action.yml
@@ -182,8 +182,8 @@ inputs:
|
||||
required: false
|
||||
default: ''
|
||||
description:
|
||||
'[Orchestrator] Run a custom job instead of the standard build automation for orchestrator (in yaml format with the
|
||||
keys image, secrets (name, value object array), command line string)'
|
||||
'[Orchestrator] Run a custom job instead of the standard build automation for orchestrator (in yaml format with
|
||||
the keys image, secrets (name, value object array), command line string)'
|
||||
awsStackName:
|
||||
default: 'game-ci'
|
||||
required: false
|
||||
@@ -279,6 +279,120 @@ inputs:
|
||||
description:
|
||||
'[Orchestrator] Specifies the repo for the unity builder. Useful if you forked the repo for testing, features, or
|
||||
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:
|
||||
volume:
|
||||
|
||||
854
dist/index.js
generated
vendored
854
dist/index.js
generated
vendored
@@ -361,6 +361,27 @@ class BuildParameters {
|
||||
inputPullCommand: orchestrator_options_1.default.inputPullCommand,
|
||||
pullInputList: orchestrator_options_1.default.pullInputList,
|
||||
kubeStorageClass: orchestrator_options_1.default.kubeStorageClass,
|
||||
gcpProject: input_1.default.gcpProject,
|
||||
gcpRegion: input_1.default.gcpRegion,
|
||||
gcpStorageType: input_1.default.gcpStorageType,
|
||||
gcpBucket: input_1.default.gcpBucket,
|
||||
gcpFilestoreIp: input_1.default.gcpFilestoreIp,
|
||||
gcpFilestoreShare: input_1.default.gcpFilestoreShare,
|
||||
gcpMachineType: input_1.default.gcpMachineType,
|
||||
gcpDiskSizeGb: input_1.default.gcpDiskSizeGb,
|
||||
gcpServiceAccount: input_1.default.gcpServiceAccount,
|
||||
gcpVpcConnector: input_1.default.gcpVpcConnector,
|
||||
azureResourceGroup: input_1.default.azureResourceGroup,
|
||||
azureLocation: input_1.default.azureLocation,
|
||||
azureStorageType: input_1.default.azureStorageType,
|
||||
azureStorageAccount: input_1.default.azureStorageAccount,
|
||||
azureBlobContainer: input_1.default.azureBlobContainer,
|
||||
azureFileShareName: input_1.default.azureFileShareName,
|
||||
azureSubscriptionId: input_1.default.azureSubscriptionId,
|
||||
azureCpu: input_1.default.azureCpu,
|
||||
azureMemoryGb: input_1.default.azureMemoryGb,
|
||||
azureDiskSizeGb: input_1.default.azureDiskSizeGb,
|
||||
azureSubnetId: input_1.default.azureSubnetId,
|
||||
cacheKey: orchestrator_options_1.default.cacheKey,
|
||||
maxRetainedWorkspaces: Number.parseInt(orchestrator_options_1.default.maxRetainedWorkspaces),
|
||||
useLargePackages: orchestrator_options_1.default.useLargePackages,
|
||||
@@ -1826,6 +1847,71 @@ class Input {
|
||||
static get skipActivation() {
|
||||
return Input.getInput('skipActivation')?.toLowerCase() ?? 'false';
|
||||
}
|
||||
// GCP Cloud Run (Experimental)
|
||||
static get gcpProject() {
|
||||
return Input.getInput('gcpProject') ?? '';
|
||||
}
|
||||
static get gcpRegion() {
|
||||
return Input.getInput('gcpRegion') ?? '';
|
||||
}
|
||||
static get gcpStorageType() {
|
||||
return Input.getInput('gcpStorageType') ?? 'gcs-fuse';
|
||||
}
|
||||
static get gcpBucket() {
|
||||
return Input.getInput('gcpBucket') ?? '';
|
||||
}
|
||||
static get gcpFilestoreIp() {
|
||||
return Input.getInput('gcpFilestoreIp') ?? '';
|
||||
}
|
||||
static get gcpFilestoreShare() {
|
||||
return Input.getInput('gcpFilestoreShare') ?? '/share1';
|
||||
}
|
||||
static get gcpMachineType() {
|
||||
return Input.getInput('gcpMachineType') ?? 'e2-standard-4';
|
||||
}
|
||||
static get gcpDiskSizeGb() {
|
||||
return Input.getInput('gcpDiskSizeGb') ?? '100';
|
||||
}
|
||||
static get gcpServiceAccount() {
|
||||
return Input.getInput('gcpServiceAccount') ?? '';
|
||||
}
|
||||
static get gcpVpcConnector() {
|
||||
return Input.getInput('gcpVpcConnector') ?? '';
|
||||
}
|
||||
// Azure Container Instances (Experimental)
|
||||
static get azureResourceGroup() {
|
||||
return Input.getInput('azureResourceGroup') ?? '';
|
||||
}
|
||||
static get azureLocation() {
|
||||
return Input.getInput('azureLocation') ?? '';
|
||||
}
|
||||
static get azureStorageType() {
|
||||
return Input.getInput('azureStorageType') ?? 'azure-files';
|
||||
}
|
||||
static get azureStorageAccount() {
|
||||
return Input.getInput('azureStorageAccount') ?? '';
|
||||
}
|
||||
static get azureBlobContainer() {
|
||||
return Input.getInput('azureBlobContainer') ?? 'unity-builds';
|
||||
}
|
||||
static get azureFileShareName() {
|
||||
return Input.getInput('azureFileShareName') ?? 'unity-builds';
|
||||
}
|
||||
static get azureSubscriptionId() {
|
||||
return Input.getInput('azureSubscriptionId') ?? '';
|
||||
}
|
||||
static get azureCpu() {
|
||||
return Input.getInput('azureCpu') ?? '4';
|
||||
}
|
||||
static get azureMemoryGb() {
|
||||
return Input.getInput('azureMemoryGb') ?? '16';
|
||||
}
|
||||
static get azureDiskSizeGb() {
|
||||
return Input.getInput('azureDiskSizeGb') ?? '100';
|
||||
}
|
||||
static get azureSubnetId() {
|
||||
return Input.getInput('azureSubnetId') ?? '';
|
||||
}
|
||||
static ToEnvVarFormat(input) {
|
||||
if (input.toUpperCase() === input) {
|
||||
return input;
|
||||
@@ -2501,6 +2587,8 @@ const core = __importStar(__nccwpck_require__(42186));
|
||||
const test_1 = __importDefault(__nccwpck_require__(6389));
|
||||
const local_1 = __importDefault(__nccwpck_require__(48195));
|
||||
const docker_1 = __importDefault(__nccwpck_require__(91739));
|
||||
const gcp_cloud_run_1 = __importDefault(__nccwpck_require__(84818));
|
||||
const azure_aci_1 = __importDefault(__nccwpck_require__(94129));
|
||||
const provider_loader_1 = __importDefault(__nccwpck_require__(50822));
|
||||
const github_1 = __importDefault(__nccwpck_require__(83654));
|
||||
const shared_workspace_locking_1 = __importDefault(__nccwpck_require__(54222));
|
||||
@@ -2619,6 +2707,14 @@ class Orchestrator {
|
||||
case 'local':
|
||||
Orchestrator.Provider = new local_1.default();
|
||||
break;
|
||||
case 'gcp-cloud-run':
|
||||
orchestrator_logger_1.default.log('⚠ EXPERIMENTAL: GCP Cloud Run Jobs provider');
|
||||
Orchestrator.Provider = new gcp_cloud_run_1.default(Orchestrator.buildParameters);
|
||||
break;
|
||||
case 'azure-aci':
|
||||
orchestrator_logger_1.default.log('⚠ EXPERIMENTAL: Azure Container Instances provider');
|
||||
Orchestrator.Provider = new azure_aci_1.default(Orchestrator.buildParameters);
|
||||
break;
|
||||
default:
|
||||
// Try to load provider using the dynamic loader for unknown providers
|
||||
try {
|
||||
@@ -4749,6 +4845,417 @@ class TaskService {
|
||||
exports.TaskService = TaskService;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 94129:
|
||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
const orchestrator_logger_1 = __importDefault(__nccwpck_require__(32549));
|
||||
const orchestrator_system_1 = __nccwpck_require__(9744);
|
||||
const __1 = __nccwpck_require__(41359);
|
||||
const resource_tracking_1 = __importDefault(__nccwpck_require__(42604));
|
||||
class AzureAciProvider {
|
||||
constructor(buildParameters) {
|
||||
this.buildParameters = buildParameters;
|
||||
this.resourceGroup = buildParameters.azureResourceGroup || process.env.AZURE_RESOURCE_GROUP || '';
|
||||
this.location = buildParameters.azureLocation || __1.Input.region || 'eastus';
|
||||
this.storageType = (buildParameters.azureStorageType || 'azure-files');
|
||||
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 || '';
|
||||
orchestrator_logger_1.default.log('[Azure ACI] Provider initialized (EXPERIMENTAL)');
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] Resource Group: ${this.resourceGroup || '(not set)'}`);
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] Location: ${this.location}`);
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] Storage: ${this.storageType}`);
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] Resources: ${this.cpu} CPU, ${this.memoryGb}GB RAM`);
|
||||
this.validateStorageConfig();
|
||||
}
|
||||
validateStorageConfig() {
|
||||
switch (this.storageType) {
|
||||
case 'azure-files':
|
||||
if (!this.storageAccount) {
|
||||
orchestrator_logger_1.default.logWarning('[Azure ACI] Storage type "azure-files" requires azureStorageAccount to be set.');
|
||||
}
|
||||
else {
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] File Share: ${this.storageAccount}/${this.fileShareName} (SMB)`);
|
||||
}
|
||||
break;
|
||||
case 'azure-files-nfs':
|
||||
if (!this.storageAccount) {
|
||||
orchestrator_logger_1.default.logWarning('[Azure ACI] Storage type "azure-files-nfs" requires azureStorageAccount (Premium FileStorage).');
|
||||
}
|
||||
if (!this.subnetId) {
|
||||
orchestrator_logger_1.default.logWarning('[Azure ACI] NFS file shares require VNet integration. Set azureSubnetId.');
|
||||
}
|
||||
else {
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] File Share: ${this.storageAccount}/${this.fileShareName} (NFS 4.1)`);
|
||||
}
|
||||
break;
|
||||
case 'blob-copy':
|
||||
if (!this.storageAccount) {
|
||||
orchestrator_logger_1.default.logWarning('[Azure ACI] Storage type "blob-copy" requires azureStorageAccount to be set.');
|
||||
}
|
||||
else {
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] Blob container: ${this.storageAccount}/${this.blobContainer}`);
|
||||
}
|
||||
break;
|
||||
case 'in-memory':
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] In-memory volume (emptyDir): limited by ${this.memoryGb}GB container memory`);
|
||||
break;
|
||||
default:
|
||||
orchestrator_logger_1.default.logWarning(`[Azure ACI] Unknown storage type '${this.storageType}'. Valid: azure-files, blob-copy, azure-files-nfs, in-memory`);
|
||||
}
|
||||
if (!this.resourceGroup) {
|
||||
orchestrator_logger_1.default.logWarning('[Azure ACI] No resource group specified. Set azureResourceGroup input or AZURE_RESOURCE_GROUP env var.');
|
||||
}
|
||||
}
|
||||
async setupWorkflow(buildGuid, buildParameters, branchName, defaultSecretsArray) {
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] Setting up workflow for build ${buildGuid}`);
|
||||
resource_tracking_1.default.logAllocationSummary('azure-aci setup');
|
||||
// Verify Azure CLI is available
|
||||
try {
|
||||
await orchestrator_system_1.OrchestratorSystem.Run('az version --output json', false, true);
|
||||
orchestrator_logger_1.default.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 orchestrator_system_1.OrchestratorSystem.Run(`az account set --subscription="${this.subscriptionId}"`);
|
||||
}
|
||||
// Ensure resource group exists
|
||||
if (this.resourceGroup) {
|
||||
try {
|
||||
await orchestrator_system_1.OrchestratorSystem.Run(`az group show --name "${this.resourceGroup}" --output json`, false, true);
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] Resource group ${this.resourceGroup} exists`);
|
||||
}
|
||||
catch {
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] Creating resource group ${this.resourceGroup}`);
|
||||
await orchestrator_system_1.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;
|
||||
}
|
||||
}
|
||||
async setupStorageAccount(sku, kind) {
|
||||
if (!this.storageAccount || !this.resourceGroup)
|
||||
return;
|
||||
try {
|
||||
await orchestrator_system_1.OrchestratorSystem.Run(`az storage account show --name "${this.storageAccount}" --resource-group "${this.resourceGroup}" --output json`, false, true);
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] Storage account ${this.storageAccount} exists`);
|
||||
}
|
||||
catch {
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] Creating storage account ${this.storageAccount} (${sku}, ${kind})`);
|
||||
await orchestrator_system_1.OrchestratorSystem.Run(`az storage account create --name "${this.storageAccount}" --resource-group "${this.resourceGroup}" --location "${this.location}" --sku ${sku} --kind ${kind}`);
|
||||
}
|
||||
}
|
||||
async setupFileShare() {
|
||||
if (!this.storageAccount || !this.resourceGroup)
|
||||
return;
|
||||
try {
|
||||
await orchestrator_system_1.OrchestratorSystem.Run(`az storage share-rm show --storage-account "${this.storageAccount}" --name "${this.fileShareName}" --resource-group "${this.resourceGroup}" --output json`, false, true);
|
||||
}
|
||||
catch {
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] Creating file share ${this.fileShareName} (${this.diskSizeGb}GB)`);
|
||||
await orchestrator_system_1.OrchestratorSystem.Run(`az storage share-rm create --storage-account "${this.storageAccount}" --name "${this.fileShareName}" --resource-group "${this.resourceGroup}" --quota ${this.diskSizeGb}`);
|
||||
}
|
||||
}
|
||||
async setupNfsFileShare() {
|
||||
if (!this.storageAccount || !this.resourceGroup)
|
||||
return;
|
||||
try {
|
||||
await orchestrator_system_1.OrchestratorSystem.Run(`az storage share-rm show --storage-account "${this.storageAccount}" --name "${this.fileShareName}" --resource-group "${this.resourceGroup}" --output json`, false, true);
|
||||
}
|
||||
catch {
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] Creating NFS file share ${this.fileShareName} (${this.diskSizeGb}GB)`);
|
||||
await orchestrator_system_1.OrchestratorSystem.Run(`az storage share-rm create --storage-account "${this.storageAccount}" --name "${this.fileShareName}" --resource-group "${this.resourceGroup}" --quota ${this.diskSizeGb} --enabled-protocols NFS`);
|
||||
}
|
||||
}
|
||||
async setupBlobContainer() {
|
||||
if (!this.storageAccount || !this.resourceGroup)
|
||||
return;
|
||||
try {
|
||||
await orchestrator_system_1.OrchestratorSystem.Run(`az storage container show --name "${this.blobContainer}" --account-name "${this.storageAccount}" --output json`, false, true);
|
||||
}
|
||||
catch {
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] Creating blob container ${this.blobContainer}`);
|
||||
await orchestrator_system_1.OrchestratorSystem.Run(`az storage container create --name "${this.blobContainer}" --account-name "${this.storageAccount}"`);
|
||||
}
|
||||
}
|
||||
async getStorageKey() {
|
||||
if (!this.storageAccount || !this.resourceGroup)
|
||||
return '';
|
||||
try {
|
||||
const keyJson = await orchestrator_system_1.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) {
|
||||
orchestrator_logger_1.default.logWarning(`[Azure ACI] Could not get storage key: ${error.message}`);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
async buildVolumeFlags(mountdir) {
|
||||
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
|
||||
orchestrator_logger_1.default.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, image, commands, mountdir, workingdir, environment, secrets) {
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] Running task for build ${buildGuid}`);
|
||||
resource_tracking_1.default.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 orchestrator_system_1.OrchestratorSystem.Run(createCmd);
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] Container ${containerName} created (storage: ${this.storageType}), waiting for completion...`);
|
||||
}
|
||||
catch (error) {
|
||||
throw new Error(`[Azure ACI] Failed to create container: ${error.message}`);
|
||||
}
|
||||
const output = await this.waitForContainerCompletion(containerName);
|
||||
return output;
|
||||
}
|
||||
async waitForContainerCompletion(containerName) {
|
||||
const maxWaitMs = 24 * 60 * 60 * 1000;
|
||||
const pollIntervalMs = 15000;
|
||||
const startTime = Date.now();
|
||||
let lastLogLength = 0;
|
||||
while (Date.now() - startTime < maxWaitMs) {
|
||||
try {
|
||||
const stateJson = await orchestrator_system_1.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 orchestrator_system_1.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()) {
|
||||
orchestrator_logger_1.default.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}`);
|
||||
}
|
||||
orchestrator_logger_1.default.log('[Azure ACI] Container completed successfully');
|
||||
try {
|
||||
return await orchestrator_system_1.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) => e.message).join('; ') ||
|
||||
'Unknown error';
|
||||
throw new Error(`[Azure ACI] Container provisioning failed: ${detail}`);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
if (error.message?.includes('Container provisioning failed') || error.message?.includes('exited with code')) {
|
||||
throw error;
|
||||
}
|
||||
orchestrator_logger_1.default.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, branchName, defaultSecretsArray) {
|
||||
orchestrator_logger_1.default.log('[Azure ACI] Cleaning up workflow');
|
||||
}
|
||||
async garbageCollect(filter, previewOnly, olderThan, fullCache, baseDependencies) {
|
||||
orchestrator_logger_1.default.log('[Azure ACI] Garbage collecting old container groups');
|
||||
try {
|
||||
const containersJson = await orchestrator_system_1.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) {
|
||||
orchestrator_logger_1.default.log(`[Azure ACI] Would delete: ${name}`);
|
||||
}
|
||||
else {
|
||||
await orchestrator_system_1.OrchestratorSystem.Run(`az container delete --resource-group "${this.resourceGroup}" --name "${name}" --yes`);
|
||||
deletedCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return `Garbage collected ${deletedCount} Azure container instances`;
|
||||
}
|
||||
catch (error) {
|
||||
orchestrator_logger_1.default.logWarning(`[Azure ACI] Garbage collection failed: ${error.message}`);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
async listResources() {
|
||||
try {
|
||||
const containersJson = await orchestrator_system_1.OrchestratorSystem.Run(`az container list --resource-group "${this.resourceGroup}" --output json`, false, true);
|
||||
const containers = JSON.parse(containersJson || '[]');
|
||||
return containers
|
||||
.filter((c) => (c.name || '').startsWith('unity-build-'))
|
||||
.map((c) => ({ Name: c.name || '' }));
|
||||
}
|
||||
catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
listWorkflow() {
|
||||
throw new Error('[Azure ACI] listWorkflow not implemented for this experimental provider');
|
||||
}
|
||||
async watchWorkflow() {
|
||||
throw new Error('[Azure ACI] watchWorkflow not implemented for this experimental provider');
|
||||
}
|
||||
}
|
||||
exports["default"] = AzureAciProvider;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 91739:
|
||||
@@ -4926,6 +5433,349 @@ find ${sharedFolder} -maxdepth 1 -type f -name "test-*" -exec cp -a {} /github/w
|
||||
exports["default"] = LocalDockerOrchestrator;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 84818:
|
||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
const orchestrator_logger_1 = __importDefault(__nccwpck_require__(32549));
|
||||
const orchestrator_system_1 = __nccwpck_require__(9744);
|
||||
const __1 = __nccwpck_require__(41359);
|
||||
const resource_tracking_1 = __importDefault(__nccwpck_require__(42604));
|
||||
class GcpCloudRunProvider {
|
||||
constructor(buildParameters) {
|
||||
this.buildParameters = buildParameters;
|
||||
this.project = buildParameters.gcpProject || process.env.GOOGLE_CLOUD_PROJECT || process.env.GCLOUD_PROJECT || '';
|
||||
this.region = buildParameters.gcpRegion || __1.Input.region || 'us-central1';
|
||||
this.storageType = (buildParameters.gcpStorageType || 'gcs-fuse');
|
||||
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 || '';
|
||||
orchestrator_logger_1.default.log('[GCP Cloud Run] Provider initialized (EXPERIMENTAL)');
|
||||
orchestrator_logger_1.default.log(`[GCP Cloud Run] Project: ${this.project || '(auto-detect)'}`);
|
||||
orchestrator_logger_1.default.log(`[GCP Cloud Run] Region: ${this.region}`);
|
||||
orchestrator_logger_1.default.log(`[GCP Cloud Run] Storage: ${this.storageType}`);
|
||||
this.validateStorageConfig();
|
||||
}
|
||||
validateStorageConfig() {
|
||||
switch (this.storageType) {
|
||||
case 'gcs-fuse':
|
||||
case 'gcs-copy':
|
||||
if (!this.bucket) {
|
||||
orchestrator_logger_1.default.logWarning(`[GCP Cloud Run] Storage type '${this.storageType}' requires gcpBucket to be set.`);
|
||||
}
|
||||
else {
|
||||
orchestrator_logger_1.default.log(`[GCP Cloud Run] Bucket: gs://${this.bucket}`);
|
||||
}
|
||||
break;
|
||||
case 'nfs':
|
||||
if (!this.filestoreIp) {
|
||||
orchestrator_logger_1.default.logWarning('[GCP Cloud Run] Storage type "nfs" requires gcpFilestoreIp to be set.');
|
||||
}
|
||||
else {
|
||||
orchestrator_logger_1.default.log(`[GCP Cloud Run] Filestore: ${this.filestoreIp}:${this.filestoreShare}`);
|
||||
}
|
||||
if (!this.vpcConnector) {
|
||||
orchestrator_logger_1.default.logWarning('[GCP Cloud Run] NFS storage usually requires gcpVpcConnector for private network access to Filestore.');
|
||||
}
|
||||
break;
|
||||
case 'in-memory':
|
||||
orchestrator_logger_1.default.log(`[GCP Cloud Run] In-memory volume: ${Math.min(this.diskSizeGb, 32)} GiB (max 32)`);
|
||||
break;
|
||||
default:
|
||||
orchestrator_logger_1.default.logWarning(`[GCP Cloud Run] Unknown storage type '${this.storageType}'. Valid: gcs-fuse, gcs-copy, nfs, in-memory`);
|
||||
}
|
||||
if (!this.project) {
|
||||
orchestrator_logger_1.default.logWarning('[GCP Cloud Run] No project specified. Set gcpProject input or GOOGLE_CLOUD_PROJECT env var.');
|
||||
}
|
||||
}
|
||||
async setupWorkflow(buildGuid, buildParameters, branchName, defaultSecretsArray) {
|
||||
orchestrator_logger_1.default.log(`[GCP Cloud Run] Setting up workflow for build ${buildGuid}`);
|
||||
resource_tracking_1.default.logAllocationSummary('gcp-cloud-run setup');
|
||||
// Verify gcloud CLI is available
|
||||
try {
|
||||
await orchestrator_system_1.OrchestratorSystem.Run('gcloud --version', false, true);
|
||||
orchestrator_logger_1.default.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 orchestrator_system_1.OrchestratorSystem.Run(`gcloud services list --enabled --filter="name:run.googleapis.com" ${projectFlag} --format="value(name)"`, false, true);
|
||||
}
|
||||
catch {
|
||||
orchestrator_logger_1.default.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();
|
||||
}
|
||||
}
|
||||
async ensureBucketExists() {
|
||||
try {
|
||||
await orchestrator_system_1.OrchestratorSystem.Run(`gcloud storage buckets describe gs://${this.bucket} --format="value(name)"`, false, true);
|
||||
orchestrator_logger_1.default.log(`[GCP Cloud Run] Bucket gs://${this.bucket} exists`);
|
||||
}
|
||||
catch {
|
||||
orchestrator_logger_1.default.log(`[GCP Cloud Run] Creating bucket gs://${this.bucket}`);
|
||||
const projectFlag = this.project ? `--project=${this.project}` : '';
|
||||
await orchestrator_system_1.OrchestratorSystem.Run(`gcloud storage buckets create gs://${this.bucket} --location=${this.region} ${projectFlag}`);
|
||||
}
|
||||
}
|
||||
buildVolumeFlags(mountdir) {
|
||||
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: '' };
|
||||
}
|
||||
}
|
||||
async copyArtifactsIn(mountdir) {
|
||||
if (this.storageType !== 'gcs-copy' || !this.bucket)
|
||||
return;
|
||||
orchestrator_logger_1.default.log(`[GCP Cloud Run] Copying artifacts from gs://${this.bucket} to ${mountdir}`);
|
||||
try {
|
||||
await orchestrator_system_1.OrchestratorSystem.Run(`gcloud storage cp -r "gs://${this.bucket}/*" "${mountdir}/" || true`, false, true);
|
||||
}
|
||||
catch {
|
||||
orchestrator_logger_1.default.log('[GCP Cloud Run] No existing artifacts to restore (bucket may be empty)');
|
||||
}
|
||||
}
|
||||
async copyArtifactsOut(mountdir) {
|
||||
if (this.storageType !== 'gcs-copy' || !this.bucket)
|
||||
return;
|
||||
orchestrator_logger_1.default.log(`[GCP Cloud Run] Uploading artifacts from ${mountdir} to gs://${this.bucket}`);
|
||||
await orchestrator_system_1.OrchestratorSystem.Run(`gcloud storage cp -r "${mountdir}/*" "gs://${this.bucket}/"`, false, true);
|
||||
}
|
||||
async runTaskInWorkflow(buildGuid, image, commands, mountdir, workingdir, environment, secrets) {
|
||||
orchestrator_logger_1.default.log(`[GCP Cloud Run] Running task for build ${buildGuid}`);
|
||||
resource_tracking_1.default.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 orchestrator_system_1.OrchestratorSystem.Run(createCmd);
|
||||
orchestrator_logger_1.default.log(`[GCP Cloud Run] Job ${jobName} created`);
|
||||
}
|
||||
catch (error) {
|
||||
if (error.message?.includes('already exists')) {
|
||||
orchestrator_logger_1.default.log(`[GCP Cloud Run] Job ${jobName} already exists, updating...`);
|
||||
const updateCmd = createCmd.replace('jobs create', 'jobs update');
|
||||
await orchestrator_system_1.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 orchestrator_system_1.OrchestratorSystem.Run(updateCmd);
|
||||
}
|
||||
// Execute the job
|
||||
orchestrator_logger_1.default.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 orchestrator_system_1.OrchestratorSystem.Run(executeCmd);
|
||||
orchestrator_logger_1.default.log('[GCP Cloud Run] Job execution completed');
|
||||
}
|
||||
catch (error) {
|
||||
await this.streamJobLogs(jobName);
|
||||
throw new Error(`[GCP Cloud Run] Job execution failed: ${error.message}`);
|
||||
}
|
||||
await this.streamJobLogs(jobName);
|
||||
return output;
|
||||
}
|
||||
async streamJobLogs(jobName) {
|
||||
const projectFlag = this.project ? `--project=${this.project}` : '';
|
||||
try {
|
||||
const logs = await orchestrator_system_1.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()) {
|
||||
orchestrator_logger_1.default.log(`[Build] ${line}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
orchestrator_logger_1.default.logWarning('[GCP Cloud Run] Could not retrieve job logs');
|
||||
}
|
||||
}
|
||||
async cleanupWorkflow(buildParameters, branchName, defaultSecretsArray) {
|
||||
orchestrator_logger_1.default.log('[GCP Cloud Run] Cleaning up workflow');
|
||||
}
|
||||
async garbageCollect(filter, previewOnly, olderThan, fullCache, baseDependencies) {
|
||||
orchestrator_logger_1.default.log('[GCP Cloud Run] Garbage collecting old jobs');
|
||||
const projectFlag = this.project ? `--project=${this.project}` : '';
|
||||
try {
|
||||
const jobsJson = await orchestrator_system_1.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) {
|
||||
orchestrator_logger_1.default.log(`[GCP Cloud Run] Would delete: ${name}`);
|
||||
}
|
||||
else {
|
||||
await orchestrator_system_1.OrchestratorSystem.Run(`gcloud run jobs delete ${name} --region=${this.region} ${projectFlag} --quiet`);
|
||||
deletedCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return `Garbage collected ${deletedCount} Cloud Run jobs`;
|
||||
}
|
||||
catch (error) {
|
||||
orchestrator_logger_1.default.logWarning(`[GCP Cloud Run] Garbage collection failed: ${error.message}`);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
async listResources() {
|
||||
const projectFlag = this.project ? `--project=${this.project}` : '';
|
||||
try {
|
||||
const jobsJson = await orchestrator_system_1.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) => ({ Name: job.metadata?.name || '' }));
|
||||
}
|
||||
catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
listWorkflow() {
|
||||
throw new Error('[GCP Cloud Run] listWorkflow not implemented for this experimental provider');
|
||||
}
|
||||
async watchWorkflow() {
|
||||
throw new Error('[GCP Cloud Run] watchWorkflow not implemented for this experimental provider');
|
||||
}
|
||||
}
|
||||
exports["default"] = GcpCloudRunProvider;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 66990:
|
||||
@@ -7061,6 +7911,8 @@ async function loadProvider(providerSource, buildParameters) {
|
||||
'local-docker': './docker',
|
||||
'local-system': './local',
|
||||
local: './local',
|
||||
'gcp-cloud-run': './gcp-cloud-run',
|
||||
'azure-aci': './azure-aci',
|
||||
};
|
||||
modulePath = providerModuleMap[providerSource] || providerSource;
|
||||
orchestrator_logger_1.default.log(`Loading provider from module path: ${modulePath}`);
|
||||
@@ -7125,7 +7977,7 @@ class ProviderLoader {
|
||||
* @returns string[] - Array of available provider names
|
||||
*/
|
||||
static getAvailableProviders() {
|
||||
return ['aws', 'k8s', 'test', 'local-docker', 'local-system', 'local'];
|
||||
return ['aws', 'k8s', 'test', 'local-docker', 'local-system', 'local', 'gcp-cloud-run', 'azure-aci'];
|
||||
}
|
||||
/**
|
||||
* Cleans up old cached repositories
|
||||
|
||||
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
@@ -107,6 +107,31 @@ class BuildParameters {
|
||||
public unityHubVersionOnMac!: 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) {
|
||||
return buildParameters.maxRetainedWorkspaces > 0 && Orchestrator.lockedWorkspace !== ``;
|
||||
}
|
||||
@@ -228,6 +253,27 @@ class BuildParameters {
|
||||
inputPullCommand: OrchestratorOptions.inputPullCommand,
|
||||
pullInputList: OrchestratorOptions.pullInputList,
|
||||
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,
|
||||
maxRetainedWorkspaces: Number.parseInt(OrchestratorOptions.maxRetainedWorkspaces),
|
||||
useLargePackages: OrchestratorOptions.useLargePackages,
|
||||
|
||||
@@ -282,6 +282,92 @@ class Input {
|
||||
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) {
|
||||
if (input.toUpperCase() === input) {
|
||||
return input;
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
import { OrchestratorFolders } from './orchestrator-folders';
|
||||
|
||||
// Mock Orchestrator
|
||||
jest.mock('../orchestrator', () => ({
|
||||
__esModule: true,
|
||||
default: {
|
||||
buildParameters: {
|
||||
buildGuid: 'test-guid-abc',
|
||||
cacheKey: 'my-cache-key',
|
||||
projectPath: 'test-project',
|
||||
buildPath: 'Builds',
|
||||
maxRetainedWorkspaces: 0,
|
||||
gitPrivateToken: 'ghp_test123',
|
||||
orchestratorRepoName: 'game-ci/unity-builder',
|
||||
githubRepo: 'user/my-game',
|
||||
},
|
||||
lockedWorkspace: '',
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('../../build-parameters', () => ({
|
||||
__esModule: true,
|
||||
default: {
|
||||
shouldUseRetainedWorkspaceMode: jest.fn().mockReturnValue(false),
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('./orchestrator-options', () => ({
|
||||
__esModule: true,
|
||||
default: {
|
||||
useSharedBuilder: false,
|
||||
},
|
||||
}));
|
||||
|
||||
// Normalize paths for cross-platform test compatibility
|
||||
const normalize = (p: string) => p.replace(/\\/g, '/');
|
||||
|
||||
describe('OrchestratorFolders', () => {
|
||||
describe('static constants', () => {
|
||||
it('repositoryFolder is "repo"', () => {
|
||||
expect(OrchestratorFolders.repositoryFolder).toBe('repo');
|
||||
});
|
||||
|
||||
it('buildVolumeFolder is "data"', () => {
|
||||
expect(OrchestratorFolders.buildVolumeFolder).toBe('data');
|
||||
});
|
||||
|
||||
it('cacheFolder is "cache"', () => {
|
||||
expect(OrchestratorFolders.cacheFolder).toBe('cache');
|
||||
});
|
||||
});
|
||||
|
||||
describe('ToLinuxFolder', () => {
|
||||
it('converts backslashes to forward slashes', () => {
|
||||
expect(OrchestratorFolders.ToLinuxFolder('C:\\Users\\test\\project')).toBe('C:/Users/test/project');
|
||||
});
|
||||
|
||||
it('preserves forward slashes', () => {
|
||||
expect(OrchestratorFolders.ToLinuxFolder('/home/user/project')).toBe('/home/user/project');
|
||||
});
|
||||
|
||||
it('handles mixed slashes', () => {
|
||||
expect(OrchestratorFolders.ToLinuxFolder('some/path\\mixed/slashes\\here')).toBe('some/path/mixed/slashes/here');
|
||||
});
|
||||
|
||||
it('handles empty string', () => {
|
||||
expect(OrchestratorFolders.ToLinuxFolder('')).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('path computations (non-retained workspace mode)', () => {
|
||||
it('uniqueOrchestratorJobFolderAbsolute uses buildGuid', () => {
|
||||
const result = normalize(OrchestratorFolders.uniqueOrchestratorJobFolderAbsolute);
|
||||
expect(result).toBe('/data/test-guid-abc');
|
||||
});
|
||||
|
||||
it('cacheFolderForAllFull returns /data/cache', () => {
|
||||
const result = normalize(OrchestratorFolders.cacheFolderForAllFull);
|
||||
expect(result).toBe('/data/cache');
|
||||
});
|
||||
|
||||
it('cacheFolderForCacheKeyFull includes cache key', () => {
|
||||
const result = normalize(OrchestratorFolders.cacheFolderForCacheKeyFull);
|
||||
expect(result).toBe('/data/cache/my-cache-key');
|
||||
});
|
||||
|
||||
it('repoPathAbsolute is under job folder', () => {
|
||||
const result = normalize(OrchestratorFolders.repoPathAbsolute);
|
||||
expect(result).toBe('/data/test-guid-abc/repo');
|
||||
});
|
||||
|
||||
it('projectPathAbsolute includes project path', () => {
|
||||
const result = normalize(OrchestratorFolders.projectPathAbsolute);
|
||||
expect(result).toBe('/data/test-guid-abc/repo/test-project');
|
||||
});
|
||||
|
||||
it('libraryFolderAbsolute is under project path', () => {
|
||||
const result = normalize(OrchestratorFolders.libraryFolderAbsolute);
|
||||
expect(result).toBe('/data/test-guid-abc/repo/test-project/Library');
|
||||
});
|
||||
|
||||
it('projectBuildFolderAbsolute uses buildPath', () => {
|
||||
const result = normalize(OrchestratorFolders.projectBuildFolderAbsolute);
|
||||
expect(result).toBe('/data/test-guid-abc/repo/Builds');
|
||||
});
|
||||
|
||||
it('lfsFolderAbsolute is under .git/lfs', () => {
|
||||
const result = normalize(OrchestratorFolders.lfsFolderAbsolute);
|
||||
expect(result).toBe('/data/test-guid-abc/repo/.git/lfs');
|
||||
});
|
||||
|
||||
it('lfsCacheFolderFull is under cache key', () => {
|
||||
const result = normalize(OrchestratorFolders.lfsCacheFolderFull);
|
||||
expect(result).toBe('/data/cache/my-cache-key/lfs');
|
||||
});
|
||||
|
||||
it('libraryCacheFolderFull is under cache key', () => {
|
||||
const result = normalize(OrchestratorFolders.libraryCacheFolderFull);
|
||||
expect(result).toBe('/data/cache/my-cache-key/Library');
|
||||
});
|
||||
});
|
||||
|
||||
describe('builderPathAbsolute', () => {
|
||||
it('uses job folder when shared builder is disabled', () => {
|
||||
const result = normalize(OrchestratorFolders.builderPathAbsolute);
|
||||
expect(result).toBe('/data/test-guid-abc/builder');
|
||||
});
|
||||
});
|
||||
|
||||
describe('repo URLs', () => {
|
||||
it('unityBuilderRepoUrl includes token and repo name', () => {
|
||||
const url = OrchestratorFolders.unityBuilderRepoUrl;
|
||||
expect(url).toBe('https://ghp_test123@github.com/game-ci/unity-builder.git');
|
||||
});
|
||||
|
||||
it('targetBuildRepoUrl includes token and github repo', () => {
|
||||
const url = OrchestratorFolders.targetBuildRepoUrl;
|
||||
expect(url).toBe('https://ghp_test123@github.com/user/my-game.git');
|
||||
});
|
||||
});
|
||||
|
||||
describe('purgeRemoteCaching', () => {
|
||||
it('returns false when env var is not set', () => {
|
||||
const original = process.env.PURGE_REMOTE_BUILDER_CACHE;
|
||||
delete process.env.PURGE_REMOTE_BUILDER_CACHE;
|
||||
expect(OrchestratorFolders.purgeRemoteCaching).toBe(false);
|
||||
if (original !== undefined) process.env.PURGE_REMOTE_BUILDER_CACHE = original;
|
||||
});
|
||||
|
||||
it('returns true when env var is set', () => {
|
||||
const original = process.env.PURGE_REMOTE_BUILDER_CACHE;
|
||||
process.env.PURGE_REMOTE_BUILDER_CACHE = 'true';
|
||||
expect(OrchestratorFolders.purgeRemoteCaching).toBe(true);
|
||||
if (original !== undefined) {
|
||||
process.env.PURGE_REMOTE_BUILDER_CACHE = original;
|
||||
} else {
|
||||
delete process.env.PURGE_REMOTE_BUILDER_CACHE;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,53 +0,0 @@
|
||||
import OrchestratorNamespace from './orchestrator-guid';
|
||||
|
||||
describe('OrchestratorNamespace', () => {
|
||||
describe('generateGuid', () => {
|
||||
it('generates a guid with correct format', () => {
|
||||
const guid = OrchestratorNamespace.generateGuid('42', 'StandaloneLinux64');
|
||||
// Format: {runNumber}-{platform}-{nanoid4}
|
||||
expect(guid).toMatch(/^42-linux64-[a-z0-9]{4}$/);
|
||||
});
|
||||
|
||||
it('strips "standalone" prefix from platform (case-insensitive)', () => {
|
||||
const guid = OrchestratorNamespace.generateGuid('1', 'StandaloneWindows64');
|
||||
expect(guid).toMatch(/^1-windows64-[a-z0-9]{4}$/);
|
||||
});
|
||||
|
||||
it('lowercases platform name', () => {
|
||||
const guid = OrchestratorNamespace.generateGuid('5', 'Android');
|
||||
expect(guid).toMatch(/^5-android-[a-z0-9]{4}$/);
|
||||
});
|
||||
|
||||
it('handles numeric run number', () => {
|
||||
const guid = OrchestratorNamespace.generateGuid(100, 'iOS');
|
||||
expect(guid).toMatch(/^100-ios-[a-z0-9]{4}$/);
|
||||
});
|
||||
|
||||
it('generates unique guids on repeated calls', () => {
|
||||
const guids = new Set<string>();
|
||||
for (let i = 0; i < 20; i++) {
|
||||
guids.add(OrchestratorNamespace.generateGuid('1', 'StandaloneLinux64'));
|
||||
}
|
||||
// With 4 alphanumeric chars (36^4 = ~1.7M possibilities), 20 calls should almost certainly be unique
|
||||
expect(guids.size).toBeGreaterThan(1);
|
||||
});
|
||||
|
||||
it('handles StandaloneOSX platform', () => {
|
||||
const guid = OrchestratorNamespace.generateGuid('7', 'StandaloneOSX');
|
||||
expect(guid).toMatch(/^7-osx-[a-z0-9]{4}$/);
|
||||
});
|
||||
|
||||
it('handles WebGL platform (no standalone prefix)', () => {
|
||||
const guid = OrchestratorNamespace.generateGuid('3', 'WebGL');
|
||||
expect(guid).toMatch(/^3-webgl-[a-z0-9]{4}$/);
|
||||
});
|
||||
|
||||
it('uses only lowercase alphanumeric characters in nanoid portion', () => {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const guid = OrchestratorNamespace.generateGuid('1', 'test');
|
||||
const nanoidPart = guid.split('-').pop()!;
|
||||
expect(nanoidPart).toMatch(/^[0-9a-z]{4}$/);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -13,6 +13,8 @@ import OrchestratorEnvironmentVariable from './options/orchestrator-environment-
|
||||
import TestOrchestrator from './providers/test';
|
||||
import LocalOrchestrator from './providers/local';
|
||||
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 GitHub from '../github';
|
||||
import SharedWorkspaceLocking from './services/core/shared-workspace-locking';
|
||||
@@ -158,6 +160,14 @@ class Orchestrator {
|
||||
case 'local':
|
||||
Orchestrator.Provider = new LocalOrchestrator();
|
||||
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:
|
||||
// Try to load provider using the dynamic loader for unknown providers
|
||||
try {
|
||||
|
||||
536
src/model/orchestrator/providers/azure-aci/index.ts
Normal file
536
src/model/orchestrator/providers/azure-aci/index.ts
Normal file
@@ -0,0 +1,536 @@
|
||||
/**
|
||||
* 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;
|
||||
435
src/model/orchestrator/providers/gcp-cloud-run/index.ts
Normal file
435
src/model/orchestrator/providers/gcp-cloud-run/index.ts
Normal file
@@ -0,0 +1,435 @@
|
||||
/**
|
||||
* 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,6 +62,8 @@ export default async function loadProvider(
|
||||
'local-docker': './docker',
|
||||
'local-system': './local',
|
||||
local: './local',
|
||||
'gcp-cloud-run': './gcp-cloud-run',
|
||||
'azure-aci': './azure-aci',
|
||||
};
|
||||
|
||||
modulePath = providerModuleMap[providerSource] || providerSource;
|
||||
@@ -136,7 +138,7 @@ export class ProviderLoader {
|
||||
* @returns string[] - Array of available provider names
|
||||
*/
|
||||
static getAvailableProviders(): string[] {
|
||||
return ['aws', 'k8s', 'test', 'local-docker', 'local-system', 'local'];
|
||||
return ['aws', 'k8s', 'test', 'local-docker', 'local-system', 'local', 'gcp-cloud-run', 'azure-aci'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
import { FollowLogStreamService } from './follow-log-stream-service';
|
||||
import * as core from '@actions/core';
|
||||
import GitHub from '../../../github';
|
||||
|
||||
// Mock dependencies
|
||||
jest.mock('../../../github', () => ({
|
||||
__esModule: true,
|
||||
default: {
|
||||
updateGitHubCheck: jest.fn(),
|
||||
githubInputEnabled: false,
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('@actions/core', () => ({
|
||||
warning: jest.fn(),
|
||||
setOutput: jest.fn(),
|
||||
setFailed: jest.fn(),
|
||||
error: jest.fn(),
|
||||
getInput: jest.fn().mockReturnValue(''),
|
||||
}));
|
||||
|
||||
jest.mock('../../orchestrator', () => ({
|
||||
__esModule: true,
|
||||
default: {
|
||||
buildParameters: {
|
||||
logId: 'test-log-id-123',
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('../../options/orchestrator-statics', () => ({
|
||||
OrchestratorStatics: {
|
||||
logPrefix: 'TEST',
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('./orchestrator-logger', () => ({
|
||||
__esModule: true,
|
||||
default: {
|
||||
log: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('FollowLogStreamService', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
FollowLogStreamService.Reset();
|
||||
FollowLogStreamService.errors = '';
|
||||
});
|
||||
|
||||
describe('Reset', () => {
|
||||
it('resets DidReceiveEndOfTransmission to false', () => {
|
||||
FollowLogStreamService.DidReceiveEndOfTransmission = true;
|
||||
FollowLogStreamService.Reset();
|
||||
expect(FollowLogStreamService.DidReceiveEndOfTransmission).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleIteration', () => {
|
||||
it('detects end of transmission marker', () => {
|
||||
const result = FollowLogStreamService.handleIteration('---test-log-id-123', true, false, '');
|
||||
expect(FollowLogStreamService.DidReceiveEndOfTransmission).toBe(true);
|
||||
expect(result.shouldReadLogs).toBe(false);
|
||||
});
|
||||
|
||||
it('does not trigger end of transmission for non-matching log ID', () => {
|
||||
const result = FollowLogStreamService.handleIteration('---different-log-id', true, false, '');
|
||||
expect(FollowLogStreamService.DidReceiveEndOfTransmission).toBe(false);
|
||||
expect(result.shouldReadLogs).toBe(true);
|
||||
});
|
||||
|
||||
it('detects Library rebuild message', () => {
|
||||
FollowLogStreamService.handleIteration(
|
||||
'Rebuilding Library because the asset database could not be found!',
|
||||
true,
|
||||
false,
|
||||
'',
|
||||
);
|
||||
expect(GitHub.updateGitHubCheck).toHaveBeenCalledWith('Library was not found, importing new Library', '');
|
||||
expect(core.warning).toHaveBeenCalledWith('LIBRARY NOT FOUND!');
|
||||
expect(core.setOutput).toHaveBeenCalledWith('library-found', 'false');
|
||||
});
|
||||
|
||||
it('detects Build succeeded message', () => {
|
||||
FollowLogStreamService.handleIteration('Build succeeded', true, false, '');
|
||||
expect(GitHub.updateGitHubCheck).toHaveBeenCalledWith('Build succeeded', 'Build succeeded');
|
||||
expect(core.setOutput).toHaveBeenCalledWith('build-result', 'success');
|
||||
});
|
||||
|
||||
it('detects Build fail message', () => {
|
||||
FollowLogStreamService.handleIteration('Build fail', true, false, '');
|
||||
expect(GitHub.updateGitHubCheck).toHaveBeenCalled();
|
||||
expect(core.setOutput).toHaveBeenCalledWith('build-result', 'failed');
|
||||
expect(core.setFailed).toHaveBeenCalledWith('unity build failed');
|
||||
expect(core.error).toHaveBeenCalledWith('BUILD FAILED!');
|
||||
});
|
||||
|
||||
it('accumulates error messages with "error " pattern', () => {
|
||||
FollowLogStreamService.handleIteration('error CS0001: Something went wrong', true, false, '');
|
||||
expect(FollowLogStreamService.errors).toContain('error CS0001: Something went wrong');
|
||||
expect(core.error).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('accumulates error messages with "error: " pattern', () => {
|
||||
FollowLogStreamService.handleIteration('Fatal Error: Out of memory', true, false, '');
|
||||
expect(FollowLogStreamService.errors).toContain('Fatal Error: Out of memory');
|
||||
});
|
||||
|
||||
it('accumulates "command failed: " messages', () => {
|
||||
FollowLogStreamService.handleIteration('command failed: git pull', true, false, '');
|
||||
expect(FollowLogStreamService.errors).toContain('command failed: git pull');
|
||||
});
|
||||
|
||||
it('accumulates "invalid " messages', () => {
|
||||
FollowLogStreamService.handleIteration('invalid configuration value', true, false, '');
|
||||
expect(FollowLogStreamService.errors).toContain('invalid configuration value');
|
||||
});
|
||||
|
||||
it('accumulates "cannot be found" messages', () => {
|
||||
FollowLogStreamService.handleIteration('Assembly cannot be found', true, false, '');
|
||||
expect(FollowLogStreamService.errors).toContain('Assembly cannot be found');
|
||||
});
|
||||
|
||||
it('appends message to output', () => {
|
||||
const result = FollowLogStreamService.handleIteration('Some normal log line', true, false, 'previous output\n');
|
||||
expect(result.output).toContain('Some normal log line');
|
||||
expect(result.output).toContain('previous output');
|
||||
});
|
||||
|
||||
it('preserves shouldCleanup value', () => {
|
||||
const result = FollowLogStreamService.handleIteration('normal message', true, true, '');
|
||||
expect(result.shouldCleanup).toBe(true);
|
||||
});
|
||||
|
||||
it('does not change shouldReadLogs for normal messages', () => {
|
||||
const result = FollowLogStreamService.handleIteration('Just a regular build log', true, false, '');
|
||||
expect(result.shouldReadLogs).toBe(true);
|
||||
});
|
||||
|
||||
it('includes accumulated errors in Build fail GitHub check message', () => {
|
||||
FollowLogStreamService.errors = '\nprevious error';
|
||||
FollowLogStreamService.handleIteration('Build fail', true, false, '');
|
||||
const updateCall = (GitHub.updateGitHubCheck as jest.Mock).mock.calls[0];
|
||||
expect(updateCall[0]).toContain('previous error');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,207 +0,0 @@
|
||||
import { TaskParameterSerializer } from './task-parameter-serializer';
|
||||
|
||||
// Mock dependencies that TaskParameterSerializer uses internally
|
||||
jest.mock('@actions/core', () => ({
|
||||
getInput: jest.fn().mockReturnValue(''),
|
||||
setOutput: jest.fn(),
|
||||
info: jest.fn(),
|
||||
warning: jest.fn(),
|
||||
error: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('../../options/orchestrator-options', () => ({
|
||||
__esModule: true,
|
||||
default: {
|
||||
getInput: jest.fn().mockReturnValue(undefined),
|
||||
ToEnvVarFormat: (input: string) => {
|
||||
if (input.toUpperCase() === input) {
|
||||
return input;
|
||||
}
|
||||
return input
|
||||
.replace(/([A-Z])/g, ' $1')
|
||||
.trim()
|
||||
.toUpperCase()
|
||||
.replace(/ /g, '_');
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('../../options/orchestrator-options-reader', () => ({
|
||||
__esModule: true,
|
||||
default: {
|
||||
GetProperties: jest.fn().mockReturnValue([]),
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('../../options/orchestrator-query-override', () => ({
|
||||
__esModule: true,
|
||||
default: {
|
||||
queryOverrides: undefined,
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('../hooks/command-hook-service', () => ({
|
||||
CommandHookService: {
|
||||
getHooks: jest.fn().mockReturnValue([]),
|
||||
getSecrets: jest.fn().mockReturnValue([]),
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('../../../input', () => ({
|
||||
__esModule: true,
|
||||
default: {},
|
||||
}));
|
||||
|
||||
jest.mock('../../../github', () => ({
|
||||
__esModule: true,
|
||||
default: {
|
||||
githubInputEnabled: false,
|
||||
},
|
||||
}));
|
||||
|
||||
describe('TaskParameterSerializer', () => {
|
||||
describe('ToEnvVarFormat', () => {
|
||||
it('converts camelCase to UPPER_SNAKE_CASE', () => {
|
||||
expect(TaskParameterSerializer.ToEnvVarFormat('targetPlatform')).toBe('TARGET_PLATFORM');
|
||||
});
|
||||
|
||||
it('converts single word to uppercase', () => {
|
||||
expect(TaskParameterSerializer.ToEnvVarFormat('version')).toBe('VERSION');
|
||||
});
|
||||
|
||||
it('preserves already-uppercase strings', () => {
|
||||
expect(TaskParameterSerializer.ToEnvVarFormat('AWS_REGION')).toBe('AWS_REGION');
|
||||
});
|
||||
|
||||
it('handles multi-word camelCase', () => {
|
||||
expect(TaskParameterSerializer.ToEnvVarFormat('buildPlatformTarget')).toBe('BUILD_PLATFORM_TARGET');
|
||||
});
|
||||
|
||||
it('handles string starting with uppercase', () => {
|
||||
expect(TaskParameterSerializer.ToEnvVarFormat('BuildGuid')).toBe('BUILD_GUID');
|
||||
});
|
||||
});
|
||||
|
||||
describe('UndoEnvVarFormat', () => {
|
||||
it('converts UPPER_SNAKE_CASE back to camelCase', () => {
|
||||
expect(TaskParameterSerializer.UndoEnvVarFormat('TARGET_PLATFORM')).toBe('targetPlatform');
|
||||
});
|
||||
|
||||
it('handles single word', () => {
|
||||
expect(TaskParameterSerializer.UndoEnvVarFormat('VERSION')).toBe('version');
|
||||
});
|
||||
|
||||
it('handles multiple underscores', () => {
|
||||
expect(TaskParameterSerializer.UndoEnvVarFormat('BUILD_PLATFORM_TARGET')).toBe('buildPlatformTarget');
|
||||
});
|
||||
});
|
||||
|
||||
describe('round-trip conversion', () => {
|
||||
it('ToEnvVarFormat -> UndoEnvVarFormat returns original for simple camelCase', () => {
|
||||
const original = 'targetPlatform';
|
||||
const envVar = TaskParameterSerializer.ToEnvVarFormat(original);
|
||||
const roundTrip = TaskParameterSerializer.UndoEnvVarFormat(envVar);
|
||||
expect(roundTrip).toBe(original);
|
||||
});
|
||||
|
||||
it('round-trips multi-word keys', () => {
|
||||
const original = 'cacheKey';
|
||||
const envVar = TaskParameterSerializer.ToEnvVarFormat(original);
|
||||
const roundTrip = TaskParameterSerializer.UndoEnvVarFormat(envVar);
|
||||
expect(roundTrip).toBe(original);
|
||||
});
|
||||
});
|
||||
|
||||
describe('uniqBy', () => {
|
||||
it('removes duplicates by key function', () => {
|
||||
const items = [
|
||||
{ name: 'A', value: '1' },
|
||||
{ name: 'B', value: '2' },
|
||||
{ name: 'A', value: '3' },
|
||||
];
|
||||
const result = TaskParameterSerializer.uniqBy(items, (x) => x.name);
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0].value).toBe('1');
|
||||
expect(result[1].value).toBe('2');
|
||||
});
|
||||
|
||||
it('returns all items when no duplicates', () => {
|
||||
const items = [
|
||||
{ name: 'A', value: '1' },
|
||||
{ name: 'B', value: '2' },
|
||||
{ name: 'C', value: '3' },
|
||||
];
|
||||
const result = TaskParameterSerializer.uniqBy(items, (x) => x.name);
|
||||
expect(result).toHaveLength(3);
|
||||
});
|
||||
|
||||
it('handles empty array', () => {
|
||||
const result = TaskParameterSerializer.uniqBy([], (x) => x.name);
|
||||
expect(result).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('keeps first occurrence when duplicates exist', () => {
|
||||
const items = [
|
||||
{ name: 'KEY', value: 'first' },
|
||||
{ name: 'KEY', value: 'second' },
|
||||
{ name: 'KEY', value: 'third' },
|
||||
];
|
||||
const result = TaskParameterSerializer.uniqBy(items, (x) => x.name);
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0].value).toBe('first');
|
||||
});
|
||||
});
|
||||
|
||||
describe('blockedParameterNames', () => {
|
||||
it('contains expected blocked names', () => {
|
||||
expect(TaskParameterSerializer.blockedParameterNames.has('0')).toBe(true);
|
||||
expect(TaskParameterSerializer.blockedParameterNames.has('length')).toBe(true);
|
||||
expect(TaskParameterSerializer.blockedParameterNames.has('prototype')).toBe(true);
|
||||
expect(TaskParameterSerializer.blockedParameterNames.has('')).toBe(true);
|
||||
expect(TaskParameterSerializer.blockedParameterNames.has('unityVersion')).toBe(true);
|
||||
expect(TaskParameterSerializer.blockedParameterNames.has('CUSTOM_JOB')).toBe(true);
|
||||
});
|
||||
|
||||
it('does not block valid parameter names', () => {
|
||||
expect(TaskParameterSerializer.blockedParameterNames.has('targetPlatform')).toBe(false);
|
||||
expect(TaskParameterSerializer.blockedParameterNames.has('buildGuid')).toBe(false);
|
||||
expect(TaskParameterSerializer.blockedParameterNames.has('cacheKey')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('readDefaultSecrets', () => {
|
||||
it('returns an array', () => {
|
||||
const secrets = TaskParameterSerializer.readDefaultSecrets();
|
||||
expect(Array.isArray(secrets)).toBe(true);
|
||||
});
|
||||
|
||||
it('includes secrets from environment when present', () => {
|
||||
const originalSerial = process.env.UNITY_SERIAL;
|
||||
process.env.UNITY_SERIAL = 'test-serial';
|
||||
|
||||
const secrets = TaskParameterSerializer.readDefaultSecrets();
|
||||
const serialSecret = secrets.find((s) => s.ParameterKey === 'UNITY_SERIAL');
|
||||
expect(serialSecret).toBeDefined();
|
||||
expect(serialSecret?.ParameterValue).toBe('test-serial');
|
||||
|
||||
if (originalSerial !== undefined) {
|
||||
process.env.UNITY_SERIAL = originalSerial;
|
||||
} else {
|
||||
delete process.env.UNITY_SERIAL;
|
||||
}
|
||||
});
|
||||
|
||||
it('excludes secrets not in environment', () => {
|
||||
const originalSerial = process.env.UNITY_SERIAL;
|
||||
delete process.env.UNITY_SERIAL;
|
||||
|
||||
const secrets = TaskParameterSerializer.readDefaultSecrets();
|
||||
const serialSecret = secrets.find((s) => s.ParameterKey === 'UNITY_SERIAL');
|
||||
expect(serialSecret).toBeUndefined();
|
||||
|
||||
if (originalSerial !== undefined) {
|
||||
process.env.UNITY_SERIAL = originalSerial;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user