cdk-factory 0.9.10__py3-none-any.whl → 0.9.12__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cdk-factory might be problematic. Click here for more details.

cdk_factory/app.py CHANGED
@@ -32,47 +32,41 @@ class CdkAppFactory:
32
32
  config_path: str | None = None,
33
33
  outdir: str | None = None,
34
34
  add_env_context: bool = True,
35
- auto_detect_project_root: bool = True,
36
- is_pipeline: bool = False,
37
35
  ) -> None:
38
36
 
39
37
  self.args = args or CommandlineArgs()
40
38
  self.runtime_directory = runtime_directory
41
39
  self.config_path: str | None = config_path
42
40
  self.add_env_context = add_env_context
43
- self._is_pipeline = is_pipeline
44
41
 
45
- if not self.runtime_directory and auto_detect_project_root:
42
+ # Auto-detect runtime_directory if not provided
43
+ if not self.runtime_directory:
46
44
  self.runtime_directory = FileOperations.caller_app_dir()
47
45
 
48
- print(f"📂 Runtime directory: {self.runtime_directory}")
46
+ # Determine output directory with clear priority order:
47
+ # 1. Explicit outdir parameter (highest priority)
48
+ # 2. CDK_OUTDIR environment variable
49
+ # 3. Default: {runtime_directory}/cdk.out
49
50
 
50
- # Handle outdir - backward compatible with smart defaults
51
51
  supplied_outdir = outdir or (
52
52
  self.args.outdir if hasattr(self.args, "outdir") else None
53
53
  )
54
54
 
55
55
  if supplied_outdir:
56
- # If absolute path: use as-is (backward compatible)
56
+ # Explicit outdir: if relative, resolve against runtime_directory
57
+ # If absolute, use as-is
57
58
  if os.path.isabs(supplied_outdir):
58
59
  self.outdir = supplied_outdir
59
60
  else:
60
- # If relative path/name: treat as namespace within /tmp/cdk-factory
61
- namespace = supplied_outdir.rstrip("/")
62
- if not namespace or namespace in (".", ".."):
63
- namespace = "default"
64
- # TODO: NOT SURE IF WE SHOULD DO THIS
65
- self.outdir = f"/tmp/cdk-factory/{namespace}/cdk.out"
61
+ # Relative path: resolve against runtime_directory, not cwd
62
+ self.outdir = os.path.join(self.runtime_directory, supplied_outdir)
63
+ elif os.getenv("CDK_OUTDIR"):
64
+ # Environment variable override
65
+ self.outdir = os.path.abspath(os.getenv("CDK_OUTDIR"))
66
66
  else:
67
- # Default: cdk.out relative to runtime_directory (where app.py lives)
68
- # This ensures CDK CLI can find it when running via cdk.json
69
- self.outdir = str(Path(self.runtime_directory) / "cdk.out")
70
-
71
- # Env or CLI still win if you want to honor them:
72
- env_out = os.getenv("CDK_OUTDIR")
73
- if env_out:
74
- self.outdir = os.path.abspath(env_out)
75
- print(f"[cdk-factory] CDK_OUTDIR override -> {self.outdir}")
67
+ # Default: cdk.out in runtime_directory
68
+ # This resolves correctly in both local and CodeBuild environments
69
+ self.outdir = os.path.join(self.runtime_directory, "cdk.out")
76
70
 
77
71
  # Clean and recreate directory for fresh synthesis
78
72
  if os.path.exists(self.outdir):
@@ -81,8 +75,6 @@ class CdkAppFactory:
81
75
 
82
76
  self.app: aws_cdk.App = aws_cdk.App(outdir=self.outdir)
83
77
 
84
- print(f"📂 CDK output directory: {self.outdir}")
85
-
86
78
  def synth(
87
79
  self,
88
80
  cdk_app_file: str | None = None,
@@ -95,13 +87,9 @@ class CdkAppFactory:
95
87
  CloudAssembly: CDK CloudAssembly
96
88
  """
97
89
 
98
- print(f"👋 Synthesizing CDK App from the cdk-factory version: {__version__}")
99
-
100
- # Log consistent output directory
101
- print(f"📂 CDK output directory: {self.outdir}")
102
- print(
103
- f" └─ Consistent location works in both local and CodeBuild environments"
104
- )
90
+ print(f"👋 Synthesizing CDK App from cdk-factory v{__version__}")
91
+ print(f"📂 Runtime directory: {self.runtime_directory}")
92
+ print(f"📂 Output directory: {self.outdir}")
105
93
 
106
94
  if not paths:
107
95
  paths = []
@@ -140,6 +128,8 @@ class CdkAppFactory:
140
128
  # Validate that the assembly directory exists and has files
141
129
  self._validate_synth_output(assembly)
142
130
 
131
+ self._copy_cdk_out_to_project_root()
132
+
143
133
  return assembly
144
134
 
145
135
  def _validate_synth_output(self, assembly: CloudAssembly) -> None:
@@ -258,6 +248,33 @@ class CdkAppFactory:
258
248
  # Priority 4: Fallback to runtime_directory
259
249
  return str(current)
260
250
 
251
+ def _copy_cdk_out_to_project_root(self):
252
+ # Copy the cdk.out directory to the project root so it can be picked up by CodeBuild
253
+ # Source: the actual CDK output directory from the synthesis (e.g., /tmp/cdk-factory/cdk.out)
254
+ cdk_out_source = self.outdir
255
+
256
+ # raise Exception(f"cdk_out_source: {cdk_out_source}")
257
+
258
+ # Destination: project root (two directories up from devops/cdk-iac where this file lives)
259
+ project_root = os.getenv("CODEBUILD_SRC_DIR")
260
+ if not project_root:
261
+ return
262
+
263
+ cdk_out_dest = os.path.join(project_root, "cdk.out")
264
+
265
+ print(f"👉 Project root: {project_root}")
266
+ print(f"👉 CDK output source: {cdk_out_source}")
267
+ print(f"👉 CDK output destination: {cdk_out_dest}")
268
+
269
+ if os.path.exists(cdk_out_dest):
270
+ print("❌ CDK output directory already exists, skipping copy")
271
+ return
272
+ else:
273
+ print("✅ CDK output directory does not exist, copying")
274
+
275
+ shutil.copytree(cdk_out_source, cdk_out_dest)
276
+ print(f"✅ Copied CDK output to {cdk_out_dest}")
277
+
261
278
 
262
279
  if __name__ == "__main__":
263
280
  # deploy_test()
@@ -359,14 +359,17 @@ class PipelineFactoryStack(IStack):
359
359
 
360
360
  build_commands = self._get_build_commands()
361
361
 
362
- # Use consistent /tmp/cdk-factory/cdk.out location
363
- # This matches the output directory configured in CdkAppFactory
364
- # cdk_out_directory = "/tmp/cdk-factory/cdk.out"
365
- cdk_out_directory = self.workload.output_directory
362
+ # Convert absolute output directory to relative path for BuildSpec
363
+ # This prevents baking in local absolute paths
364
+ cdk_out_directory = self._get_relative_output_directory()
365
+
366
+ if cdk_out_directory.startswith("/"):
367
+ raise ValueError("CDK output directory must be a relative path")
366
368
 
367
369
  # Debug logging - will be baked into buildspec
368
- build_commands.append(f"echo '👉 CDK output directory: {cdk_out_directory}'")
369
- build_commands.append("echo '👉 Consistent location in all environments'")
370
+ build_commands.append(
371
+ f"echo '👉 CDK output directory (relative): {cdk_out_directory}'"
372
+ )
370
373
 
371
374
  shell = pipelines.ShellStep(
372
375
  "CDK Synth",
@@ -377,6 +380,34 @@ class PipelineFactoryStack(IStack):
377
380
 
378
381
  return shell
379
382
 
383
+ def _get_relative_output_directory(self) -> str:
384
+ """
385
+ Convert absolute output directory to relative path from repository root.
386
+ This prevents baking local absolute paths into the BuildSpec.
387
+
388
+ Example:
389
+ Absolute: /Users/eric/project/devops/cdk-iac/cdk.out
390
+ Relative: devops/cdk-iac/cdk.out
391
+ """
392
+ output_dir = self.workload.output_directory
393
+
394
+ # Get the current working directory (repository root during synthesis)
395
+ cwd = os.getcwd()
396
+
397
+ # Convert to absolute paths for reliable comparison
398
+ abs_output = os.path.abspath(output_dir)
399
+ abs_cwd = os.path.abspath(cwd)
400
+
401
+ # Compute relative path from repo root to output directory
402
+ try:
403
+ relative_path = os.path.relpath(abs_output, abs_cwd)
404
+ return relative_path
405
+ except ValueError:
406
+ print(f"Failed to compute relative path from {abs_output} to {abs_cwd}")
407
+ # Different drives on Windows or other edge case
408
+ # Fall back to basename approach (just the directory name)
409
+ return "cdk.out"
410
+
380
411
  def _get_build_commands(self) -> List[str]:
381
412
  # print("generating building commands")
382
413
 
cdk_factory/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.9.10"
1
+ __version__ = "0.9.12"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cdk_factory
3
- Version: 0.9.10
3
+ Version: 0.9.12
4
4
  Summary: CDK Factory. A QuickStarter and best practices setup for CDK projects
5
5
  Author-email: Eric Wilson <eric.wilson@geekcafe.com>
6
6
  License: MIT License
@@ -1,8 +1,8 @@
1
1
  cdk_factory/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- cdk_factory/app.py,sha256=VPO4ohK54hcWJa9Auq06t0oAW2nLekMGjSxAnxUWCvs,9640
2
+ cdk_factory/app.py,sha256=RnX0-pwdTAPAdKJK_j13Zl8anf9zYKBwboR0KA8K8xM,10346
3
3
  cdk_factory/cdk.json,sha256=SKZKhJ2PBpFH78j-F8S3VDYW-lf76--Q2I3ON-ZIQfw,3106
4
4
  cdk_factory/cli.py,sha256=FGbCTS5dYCNsfp-etshzvFlGDCjC28r6rtzYbe7KoHI,6407
5
- cdk_factory/version.py,sha256=5nY2lKMmQwtU8FXTQ2Qpv9EUNfy2UJF9cHFr82n7ARw,23
5
+ cdk_factory/version.py,sha256=XR5b9xrEQYlPbzUgeAtHjn10uKetzrpCdRIvgcGJkoI,23
6
6
  cdk_factory/builds/README.md,sha256=9BBWd7bXpyKdMU_g2UljhQwrC9i5O_Tvkb6oPvndoZk,90
7
7
  cdk_factory/commands/command_loader.py,sha256=QbLquuP_AdxtlxlDy-2IWCQ6D-7qa58aphnDPtp_uTs,3744
8
8
  cdk_factory/configurations/base_config.py,sha256=JKjhNsy0RCUZy1s8n5D_aXXI-upR9izaLtCTfKYiV9k,9624
@@ -65,7 +65,7 @@ cdk_factory/interfaces/live_ssm_resolver.py,sha256=3FIr9a02SXqZmbFs3RT0WxczWEQR_
65
65
  cdk_factory/interfaces/ssm_parameter_mixin.py,sha256=uA2j8HmAOpuEA9ynRj51s0WjUHMVLsbLQN-QS9NKyHA,12089
66
66
  cdk_factory/lambdas/health_handler.py,sha256=dd40ykKMxWCFEIyp2ZdQvAGNjw_ylI9CSm1N24Hp2ME,196
67
67
  cdk_factory/pipeline/path_utils.py,sha256=fvWdrcb4onmpIu1APkHLhXg8zWfK74HcW3Ra2ynxfXM,2586
68
- cdk_factory/pipeline/pipeline_factory.py,sha256=PqaPu5tQpkMObSgoHUxVcuA5UoI8CaMRiX2jx4XTg9c,16111
68
+ cdk_factory/pipeline/pipeline_factory.py,sha256=rvtkdlTPJG477nTVRN8S2ksWt4bwpd9eVLFd9WO02pM,17248
69
69
  cdk_factory/pipeline/stage.py,sha256=Be7ExMB9A-linRM18IQDOzQ-cP_I2_ThRNzlT4FIrUg,437
70
70
  cdk_factory/pipeline/security/policies.py,sha256=H3-S6nipz3UtF9Pc5eJYr4-aREUTCaJWMjOUyd6Rdv4,4406
71
71
  cdk_factory/pipeline/security/roles.py,sha256=ZB_O5H_BXgotvVspS2kVad9EMcY-a_-vU7Nm1_Z5MB8,4985
@@ -120,8 +120,8 @@ cdk_factory/utilities/lambda_function_utilities.py,sha256=S1GvBsY_q2cyUiaud3HORJ
120
120
  cdk_factory/utilities/os_execute.py,sha256=5Op0LY_8Y-pUm04y1k8MTpNrmQvcLmQHPQITEP7EuSU,1019
121
121
  cdk_factory/utils/api_gateway_utilities.py,sha256=If7Xu5s_UxmuV-kL3JkXxPLBdSVUKoLtohm0IUFoiV8,4378
122
122
  cdk_factory/workload/workload_factory.py,sha256=yBUDGIuB8-5p_mGcVFxsD2ZoZIziak3yh3LL3JvS0M4,5903
123
- cdk_factory-0.9.10.dist-info/METADATA,sha256=B9EhOfGJhkb_Du8nOE5NmJ0A-YqDU0ou8a6l6o7E8GM,2451
124
- cdk_factory-0.9.10.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
125
- cdk_factory-0.9.10.dist-info/entry_points.txt,sha256=S1DPe0ORcdiwEALMN_WIo3UQrW_g4YdQCLEsc_b0Swg,53
126
- cdk_factory-0.9.10.dist-info/licenses/LICENSE,sha256=NOtdOeLwg2il_XBJdXUPFPX8JlV4dqTdDGAd2-khxT8,1066
127
- cdk_factory-0.9.10.dist-info/RECORD,,
123
+ cdk_factory-0.9.12.dist-info/METADATA,sha256=wgeRcZWqPKX7AJQGcU38dz44uB09hpGdp-MVTjfxsOA,2451
124
+ cdk_factory-0.9.12.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
125
+ cdk_factory-0.9.12.dist-info/entry_points.txt,sha256=S1DPe0ORcdiwEALMN_WIo3UQrW_g4YdQCLEsc_b0Swg,53
126
+ cdk_factory-0.9.12.dist-info/licenses/LICENSE,sha256=NOtdOeLwg2il_XBJdXUPFPX8JlV4dqTdDGAd2-khxT8,1066
127
+ cdk_factory-0.9.12.dist-info/RECORD,,