Skip to content

Commit ff1bc75

Browse files
committed
fix(docker): support Windows auth and network flows
1 parent aba08da commit ff1bc75

44 files changed

Lines changed: 612 additions & 131 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docker-compose.api.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ services:
3939
restart: unless-stopped
4040
cpus: ${DOCKER_GIT_CONTROLLER_CPUS:-0.9}
4141
mem_limit: ${DOCKER_GIT_CONTROLLER_MEMORY:-921m}
42-
memswap_limit: ${DOCKER_GIT_CONTROLLER_MEMORY:-921m}
42+
memswap_limit: ${DOCKER_GIT_CONTROLLER_MEMORY_SWAP:-1842m}
4343
pids_limit: ${DOCKER_GIT_CONTROLLER_PIDS:-4096}
4444

4545
volumes:

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ services:
4141
restart: unless-stopped
4242
cpus: ${DOCKER_GIT_CONTROLLER_CPUS:-0.9}
4343
mem_limit: ${DOCKER_GIT_CONTROLLER_MEMORY:-921m}
44-
memswap_limit: ${DOCKER_GIT_CONTROLLER_MEMORY:-921m}
44+
memswap_limit: ${DOCKER_GIT_CONTROLLER_MEMORY_SWAP:-1842m}
4545
pids_limit: ${DOCKER_GIT_CONTROLLER_PIDS:-4096}
4646

4747
volumes:

packages/app/src/docker-git/controller-resource-limits-shell.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Effect, Either } from "effect"
33
import {
44
controllerCpuLimitEnvKey,
55
controllerMemoryLimitEnvKey,
6+
controllerMemorySwapLimitEnvKey,
67
controllerPidsLimitEnvKey,
78
controllerResourceLimitsForceRecreateEnvKey,
89
resolveControllerResourceLimitEnv
@@ -78,6 +79,7 @@ export const prepareControllerResourceLimitEnv = (): Effect.Effect<void, Control
7879
Effect.sync(() => {
7980
process.env[controllerCpuLimitEnvKey] = resolved.right.cpus
8081
process.env[controllerMemoryLimitEnvKey] = resolved.right.memory
82+
process.env[controllerMemorySwapLimitEnvKey] = resolved.right.memorySwap
8183
process.env[controllerPidsLimitEnvKey] = resolved.right.pids
8284
})
8385
)

packages/app/src/docker-git/controller-resource-limits.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99

1010
export const controllerCpuLimitEnvKey = "DOCKER_GIT_CONTROLLER_CPUS"
1111
export const controllerMemoryLimitEnvKey = "DOCKER_GIT_CONTROLLER_MEMORY"
12+
export const controllerMemorySwapLimitEnvKey = "DOCKER_GIT_CONTROLLER_MEMORY_SWAP"
1213
export const controllerPidsLimitEnvKey = "DOCKER_GIT_CONTROLLER_PIDS"
1314
export const controllerResourceLimitsForceRecreateEnvKey = "DOCKER_GIT_CONTROLLER_RESOURCE_LIMITS_FORCE_RECREATE"
1415

@@ -34,6 +35,7 @@ export type ControllerResourceLimitIntent = {
3435
export type ControllerResourceLimitEnv = {
3536
readonly cpus: string
3637
readonly memory: string
38+
readonly memorySwap: string
3739
readonly pids: string
3840
}
3941

@@ -305,6 +307,7 @@ export const resolveControllerResourceLimitEnv = (
305307
return {
306308
cpus: String(resolved.cpuLimit),
307309
memory: resolved.ramLimit,
310+
memorySwap: resolved.swapLimit,
308311
pids: pidsLimit
309312
}
310313
})

packages/app/src/docker-git/frontend-lib/core/command-builders-shared.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ const parsePort = (value: string): Either.Either<number, ParseError> => {
3030
return Either.right(parsed)
3131
}
3232

33+
export const trimTrailingPathSeparators = (value: string): string => {
34+
let end = value.length
35+
while (end > 0 && (value[end - 1] === "/" || value[end - 1] === "\\")) {
36+
end -= 1
37+
}
38+
return value.slice(0, end)
39+
}
40+
3341
/**
3442
* Parses a raw SSH port value into the valid Docker host-port range.
3543
*

packages/app/src/docker-git/frontend-lib/core/command-builders.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
parseDockerNetworkMode,
99
parseGpuMode,
1010
parseSshPort,
11-
parseSshUser
11+
parseSshUser,
12+
trimTrailingPathSeparators
1213
} from "./command-builders-shared.js"
1314
import { type RawOptions } from "./command-options.js"
1415
import {
@@ -21,12 +22,11 @@ import {
2122
resolveRepoInput
2223
} from "./domain.js"
2324
import { resolveResourceLimitsIntent } from "./resource-limits.js"
24-
import { trimRightChar } from "./strings.js"
2525
import { normalizeAuthLabel, normalizeGitTokenLabel } from "./token-labels.js"
2626

2727
export { nonEmpty } from "./command-builders-shared.js"
2828

29-
const normalizeSecretsRoot = (value: string): string => trimRightChar(value, "/")
29+
const normalizeSecretsRoot = trimTrailingPathSeparators
3030

3131
type RepoBasics = {
3232
readonly repoUrl: string

packages/app/src/docker-git/frontend-lib/usecases/path-helpers.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ const expandHome = (value: string, home: string | null): string => {
3535
const trimTrailingSlash = (value: string): string => {
3636
let end = value.length
3737
while (end > 0) {
38+
if (end === 1 && value[0] === "/") {
39+
break
40+
}
41+
if (end === 3 && /^[a-z]:[\\/]/iu.test(value.slice(0, end))) {
42+
break
43+
}
3844
const char = value[end - 1]
3945
if (char !== "/" && char !== "\\") {
4046
break
@@ -44,14 +50,21 @@ const trimTrailingSlash = (value: string): string => {
4450
return value.slice(0, end)
4551
}
4652

53+
const homePathSeparator = (home: string): string => home.includes("\\") && !home.includes("/") ? "\\" : "/"
54+
55+
const joinHomePath = (home: string, child: string): string => {
56+
const root = trimTrailingSlash(home)
57+
return `${root}${homePathSeparator(root)}${child}`
58+
}
59+
4760
export const defaultProjectsRoot = (cwd: string): string => {
4861
const home = resolveHomeDir()
4962
const explicit = process.env["DOCKER_GIT_PROJECTS_ROOT"]?.trim()
5063
if (explicit && explicit.length > 0) {
5164
return expandHome(explicit, home)
5265
}
5366
if (home !== null) {
54-
return `${trimTrailingSlash(home)}/.docker-git`
67+
return joinHomePath(home, ".docker-git")
5568
}
5669
return `${cwd}/.docker-git`
5770
}

packages/app/src/lib/core/command-builders-shared.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ const parsePort = (value: string): Either.Either<number, ParseError> => {
3030
return Either.right(parsed)
3131
}
3232

33+
export const trimTrailingPathSeparators = (value: string): string => {
34+
let end = value.length
35+
while (end > 0 && (value[end - 1] === "/" || value[end - 1] === "\\")) {
36+
end -= 1
37+
}
38+
return value.slice(0, end)
39+
}
40+
3341
/**
3442
* Parses a raw SSH port value into the valid Docker host-port range.
3543
*

packages/app/src/lib/core/command-builders.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
parseDockerNetworkMode,
99
parseGpuMode,
1010
parseSshPort,
11-
parseSshUser
11+
parseSshUser,
12+
trimTrailingPathSeparators
1213
} from "./command-builders-shared.js"
1314
import { type RawOptions } from "./command-options.js"
1415
import {
@@ -21,12 +22,11 @@ import {
2122
resolveRepoInput
2223
} from "./domain.js"
2324
import { resolveResourceLimitsIntent } from "./resource-limits.js"
24-
import { trimRightChar } from "./strings.js"
2525
import { normalizeAuthLabel, normalizeGitTokenLabel } from "./token-labels.js"
2626

2727
export { nonEmpty } from "./command-builders-shared.js"
2828

29-
const normalizeSecretsRoot = (value: string): string => trimRightChar(value, "/")
29+
const normalizeSecretsRoot = trimTrailingPathSeparators
3030

3131
type RepoBasics = {
3232
readonly repoUrl: string

packages/app/src/lib/core/templates/docker-compose.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,12 @@ const renderGpu = (gpu: TemplateConfig["gpu"]): string =>
8282

8383
const renderBootstrapMounts = (): string => ` - ${bootstrapVolumeKey}:/opt/docker-git/bootstrap/source:ro`
8484

85+
const renderYamlSingleQuoted = (value: string): string => `'${value.replaceAll("'", "''")}'`
86+
8587
const renderEnvFiles = (config: TemplateConfig): string =>
86-
` env_file:\n - ${config.envGlobalPath}\n - ${config.envProjectPath}\n`
88+
` env_file:\n - ${renderYamlSingleQuoted(config.envGlobalPath)}\n - ${
89+
renderYamlSingleQuoted(config.envProjectPath)
90+
}\n`
8791

8892
const buildPlaywrightFragments = (
8993
config: TemplateConfig,

0 commit comments

Comments
 (0)