Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/en/farm-config-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ Git repository format: `https://<token>@github.com/<repositoryPath>.git`.
- *Optional*
> Maximum number of running instances. No limit by default. When limit is reached, new builds will be rejected.

### `instanceHashLength`
- *Number*
- *Optional*
> Maximum length of instance hash. If set, the hash is truncated to this length. Minimum value is 4; when not set, no truncation is applied.

### `defaultBranch`
- *String*
- *Required*
Expand Down
5 changes: 5 additions & 0 deletions docs/ru/farm-config-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
- *Optional*
> Максимальное количество запущенных инстансов. По умолчанию без ограничения. Когда лимит достигнут, новые сборки будут отклонены.

### `instanceHashLength`
- *Number*
- *Optional*
> Максимальная длина хэша инстанса. Если задано, хэш обрезается до этой длины. Минимальное значение — 4; если не задано, обрезка не применяется.

### `defaultBranch`
- *String*
- *Required*
Expand Down
10 changes: 9 additions & 1 deletion src/server/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export function getProviderConfig() {
return envConfig.farmProvider;
}

const INSTANCE_HASH_LENGTH = getGlobalFarmConfig().instanceHashLength;

export function generateInstanceHash(
// required to ensure passing all props
info: Required<Pick<Instance, 'branch' | 'instanceConfigName' | 'vcs' | 'project'>> & {
Expand Down Expand Up @@ -47,7 +49,13 @@ export function generateInstanceHash(
runEnvVariables: additionalRunEnvVariables,
});
// replace first number with alphabet symbol for support most domain's standard implementation
return hash.replace(/^[0-9]{1}/, 'x');
let result = hash.replace(/^[0-9]{1}/, 'x');

if (INSTANCE_HASH_LENGTH) {
result = result.slice(0, Math.max(INSTANCE_HASH_LENGTH, 4));
}

return result;
}

/** @deprecated */
Expand Down
1 change: 0 additions & 1 deletion src/server/utils/instance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ const restartInstance = async (instance: Instance) => {

/**
* Get all projects with instances
*
* @returns Array of projects with instances
*/
const getProjectsWithInstances = async () => {
Expand Down
1 change: 1 addition & 0 deletions src/shared/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export interface FarmConfigBase {
urlTemplate?: string;
defaultBranch?: string;
vcs?: string;
instanceHashLength?: number;

vcsCredentials?: {
[key: string]: VcsCredentialsConfig | undefined;
Expand Down