@@ -4,6 +4,7 @@ import type * as Path from "@effect/platform/Path"
44import { Effect , Match } from "effect"
55
66import { type TemplateConfig } from "../core/domain.js"
7+ import { dockerGitScriptNames } from "../core/docker-git-scripts.js"
78import { resolveComposeResourceLimits , withDefaultResourceLimitIntent } from "../core/resource-limits.js"
89import { type FileSpec , planFiles } from "../core/templates.js"
910import { FileExistsError } from "./errors.js"
@@ -102,6 +103,40 @@ const failOnExistingFiles = (
102103 return Effect . fail ( new FileExistsError ( { path : firstPath } ) )
103104}
104105
106+ // CHANGE: discover and copy docker-git scripts into the project build context
107+ // WHY: scripts must be part of the Docker build context for COPY into the image
108+ // REF: issue-176
109+ // PURITY: SHELL
110+ // EFFECT: Effect<void, PlatformError, FileSystem | Path>
111+ // INVARIANT: only copies scripts that exist in the workspace; missing scripts are skipped
112+ // COMPLEXITY: O(|dockerGitScriptNames|)
113+ const provisionDockerGitScripts = (
114+ fs : FileSystem . FileSystem ,
115+ path : Path . Path ,
116+ baseDir : string
117+ ) : Effect . Effect < void , PlatformError > =>
118+ Effect . gen ( function * ( _ ) {
119+ const workspaceRoot = process . cwd ( )
120+ const sourceScriptsDir = path . join ( workspaceRoot , "scripts" )
121+ const targetScriptsDir = path . join ( baseDir , "scripts" )
122+
123+ const sourceExists = yield * _ ( fs . exists ( sourceScriptsDir ) )
124+ if ( ! sourceExists ) {
125+ return
126+ }
127+
128+ yield * _ ( fs . makeDirectory ( targetScriptsDir , { recursive : true } ) )
129+
130+ for ( const scriptName of dockerGitScriptNames ) {
131+ const sourcePath = path . join ( sourceScriptsDir , scriptName )
132+ const targetPath = path . join ( targetScriptsDir , scriptName )
133+ const exists = yield * _ ( fs . exists ( sourcePath ) )
134+ if ( exists ) {
135+ yield * _ ( fs . copyFile ( sourcePath , targetPath ) )
136+ }
137+ }
138+ } )
139+
105140// CHANGE: write generated docker-git files to disk
106141// WHY: isolate all filesystem effects in a thin shell
107142// QUOTE(ТЗ): "создавать докер образы"
@@ -150,5 +185,10 @@ export const writeProjectFiles = (
150185 }
151186 }
152187
188+ // CHANGE: provision docker-git scripts into project build context
189+ // WHY: Dockerfile COPY scripts/ requires scripts to be in the build context
190+ // REF: issue-176
191+ yield * _ ( provisionDockerGitScripts ( fs , path , baseDir ) )
192+
153193 return created
154194 } )
0 commit comments