cdk-factory 0.9.6__py3-none-any.whl → 0.9.8__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 +30 -21
- cdk_factory/pipeline/path_utils.py +68 -0
- cdk_factory/pipeline/pipeline_factory.py +8 -42
- cdk_factory/version.py +1 -1
- {cdk_factory-0.9.6.dist-info → cdk_factory-0.9.8.dist-info}/METADATA +1 -1
- {cdk_factory-0.9.6.dist-info → cdk_factory-0.9.8.dist-info}/RECORD +9 -8
- {cdk_factory-0.9.6.dist-info → cdk_factory-0.9.8.dist-info}/WHEEL +0 -0
- {cdk_factory-0.9.6.dist-info → cdk_factory-0.9.8.dist-info}/entry_points.txt +0 -0
- {cdk_factory-0.9.6.dist-info → cdk_factory-0.9.8.dist-info}/licenses/LICENSE +0 -0
cdk_factory/app.py
CHANGED
|
@@ -4,10 +4,16 @@ Geek Cafe, LLC
|
|
|
4
4
|
Maintainers: Eric Wilson
|
|
5
5
|
MIT License. See Project Root for the license information.
|
|
6
6
|
"""
|
|
7
|
+
import json
|
|
7
8
|
import os
|
|
9
|
+
import shutil
|
|
10
|
+
import sys
|
|
11
|
+
import warnings
|
|
8
12
|
from pathlib import Path
|
|
13
|
+
from typing import Optional
|
|
9
14
|
import aws_cdk
|
|
10
15
|
from aws_cdk.cx_api import CloudAssembly
|
|
16
|
+
from aws_lambda_powertools import Logger
|
|
11
17
|
|
|
12
18
|
from cdk_factory.utilities.commandline_args import CommandlineArgs
|
|
13
19
|
from cdk_factory.workload.workload_factory import WorkloadFactory
|
|
@@ -35,19 +41,28 @@ class CdkAppFactory:
|
|
|
35
41
|
self.add_env_context = add_env_context
|
|
36
42
|
self._is_pipeline = is_pipeline
|
|
37
43
|
|
|
38
|
-
#
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
# ALWAYS use /tmp/cdk-factory for consistent, predictable output location
|
|
45
|
+
# This works in both local dev and CodeBuild environments
|
|
46
|
+
CDK_FACTORY_BASE_DIR = "/tmp/cdk-factory"
|
|
47
|
+
|
|
48
|
+
# Use outdir as a namespace directory (not full path)
|
|
49
|
+
# This allows multiple projects/deployments to coexist without conflicts
|
|
50
|
+
supplied_outdir = outdir or (self.args.outdir if hasattr(self.args, 'outdir') else None)
|
|
51
|
+
|
|
52
|
+
if supplied_outdir:
|
|
53
|
+
# Extract just the directory name (not full path)
|
|
54
|
+
namespace = os.path.basename(supplied_outdir.rstrip('/'))
|
|
55
|
+
if not namespace or namespace in ('.', '..'):
|
|
56
|
+
namespace = "default"
|
|
57
|
+
self.outdir = f"{CDK_FACTORY_BASE_DIR}/{namespace}/cdk.out"
|
|
49
58
|
else:
|
|
50
|
-
|
|
59
|
+
# Default namespace
|
|
60
|
+
self.outdir = f"{CDK_FACTORY_BASE_DIR}/cdk.out"
|
|
61
|
+
|
|
62
|
+
# Clean and recreate directory for fresh synthesis
|
|
63
|
+
if os.path.exists(self.outdir):
|
|
64
|
+
shutil.rmtree(self.outdir)
|
|
65
|
+
os.makedirs(self.outdir, exist_ok=True)
|
|
51
66
|
|
|
52
67
|
self.app: aws_cdk.App = aws_cdk.App(outdir=self.outdir)
|
|
53
68
|
|
|
@@ -65,15 +80,9 @@ class CdkAppFactory:
|
|
|
65
80
|
|
|
66
81
|
print(f"👋 Synthesizing CDK App from the cdk-factory version: {__version__}")
|
|
67
82
|
|
|
68
|
-
# Log
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
print(f"📂 CDK output directory configured: {self.outdir}")
|
|
72
|
-
if not os.path.isabs(self.outdir):
|
|
73
|
-
print(f" └─ Resolves to: {resolved_outdir}")
|
|
74
|
-
else:
|
|
75
|
-
print(f"📂 CDK output directory: using CDK default (./cdk.out in current directory)")
|
|
76
|
-
print(f" └─ Current directory: {os.getcwd()}")
|
|
83
|
+
# Log consistent output directory
|
|
84
|
+
print(f"📂 CDK output directory: {self.outdir}")
|
|
85
|
+
print(f" └─ Consistent location works in both local and CodeBuild environments")
|
|
77
86
|
|
|
78
87
|
if not paths:
|
|
79
88
|
paths = []
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pipeline path utility functions.
|
|
3
|
+
|
|
4
|
+
This module contains path conversion utilities used by the pipeline factory.
|
|
5
|
+
Separated from pipeline_factory.py to avoid circular import issues.
|
|
6
|
+
"""
|
|
7
|
+
import os
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def convert_app_file_to_relative_directory(cdk_app_file: str) -> str:
|
|
12
|
+
"""
|
|
13
|
+
Convert a CDK app.py file path to a relative directory path.
|
|
14
|
+
|
|
15
|
+
CRITICAL: This ensures paths are ALWAYS relative before being baked into the buildspec.
|
|
16
|
+
This prevents:
|
|
17
|
+
1. Local absolute paths from being baked into CloudFormation templates
|
|
18
|
+
2. Self-mutate loops due to changing CODEBUILD_SRC_DIR paths
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
cdk_app_file: Path to app.py (can be absolute or relative)
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
Relative directory path (e.g., "devops/cdk-iac") or empty string for root
|
|
25
|
+
|
|
26
|
+
Examples:
|
|
27
|
+
>>> convert_app_file_to_relative_directory("/project/devops/cdk-iac/app.py")
|
|
28
|
+
"devops/cdk-iac"
|
|
29
|
+
|
|
30
|
+
>>> convert_app_file_to_relative_directory("devops/cdk-iac/app.py")
|
|
31
|
+
"devops/cdk-iac"
|
|
32
|
+
|
|
33
|
+
>>> convert_app_file_to_relative_directory("/project/app.py")
|
|
34
|
+
""
|
|
35
|
+
"""
|
|
36
|
+
cdk_app_file_path = Path(cdk_app_file)
|
|
37
|
+
|
|
38
|
+
# If absolute path, try to make it relative
|
|
39
|
+
if cdk_app_file_path.is_absolute():
|
|
40
|
+
# Check if we have a project root hint (CODEBUILD_SRC_DIR or current working directory)
|
|
41
|
+
codebuild_src = os.getenv('CODEBUILD_SRC_DIR')
|
|
42
|
+
base_dir = codebuild_src if codebuild_src else os.getcwd()
|
|
43
|
+
|
|
44
|
+
try:
|
|
45
|
+
# Resolve symlinks (important for macOS where /var -> /private/var)
|
|
46
|
+
resolved_file = str(Path(cdk_app_file_path).resolve())
|
|
47
|
+
resolved_base = str(Path(base_dir).resolve())
|
|
48
|
+
|
|
49
|
+
# Make it relative to base directory
|
|
50
|
+
rel_path = os.path.relpath(resolved_file, resolved_base)
|
|
51
|
+
# If we ended up going outside (../), that's probably wrong
|
|
52
|
+
if not rel_path.startswith('..'):
|
|
53
|
+
cdk_app_file_path = Path(rel_path)
|
|
54
|
+
except ValueError:
|
|
55
|
+
# Different drives on Windows - can't make relative
|
|
56
|
+
pass
|
|
57
|
+
|
|
58
|
+
# Remove /app.py to get directory
|
|
59
|
+
cdk_directory = str(cdk_app_file_path.parent if cdk_app_file_path.name == 'app.py' else cdk_app_file_path.parent)
|
|
60
|
+
|
|
61
|
+
# Normalize to use forward slashes (works on Windows and Linux)
|
|
62
|
+
cdk_directory = cdk_directory.replace('\\', '/')
|
|
63
|
+
|
|
64
|
+
# If it's just '.' (current directory), use empty string
|
|
65
|
+
if cdk_directory in ('.', './'):
|
|
66
|
+
cdk_directory = ""
|
|
67
|
+
|
|
68
|
+
return cdk_directory
|
|
@@ -26,11 +26,12 @@ from cdk_factory.workload.workload_factory import WorkloadConfig
|
|
|
26
26
|
from cdk_factory.configurations.cdk_config import CdkConfig
|
|
27
27
|
from cdk_factory.configurations.pipeline_stage import PipelineStageConfig
|
|
28
28
|
from cdk_factory.interfaces.istack import IStack
|
|
29
|
+
from cdk_factory.pipeline.path_utils import convert_app_file_to_relative_directory
|
|
29
30
|
|
|
30
31
|
logger = Logger()
|
|
31
32
|
|
|
32
33
|
|
|
33
|
-
class PipelineFactoryStack(
|
|
34
|
+
class PipelineFactoryStack(IStack):
|
|
34
35
|
"""
|
|
35
36
|
Pipeline Stacks wrap up your application for a CI/CD pipeline Stack
|
|
36
37
|
"""
|
|
@@ -355,51 +356,16 @@ class PipelineFactoryStack(cdk.Stack):
|
|
|
355
356
|
def _get_synth_shell_step(self) -> pipelines.ShellStep:
|
|
356
357
|
if not self.workload.cdk_app_file:
|
|
357
358
|
raise ValueError("CDK app file is not defined")
|
|
358
|
-
cdk_directory = self.workload.cdk_app_file.removesuffix("/app.py")
|
|
359
359
|
|
|
360
360
|
build_commands = self._get_build_commands()
|
|
361
361
|
|
|
362
|
-
#
|
|
363
|
-
#
|
|
364
|
-
|
|
365
|
-
import os
|
|
366
|
-
from pathlib import Path
|
|
367
|
-
|
|
368
|
-
# Get the directory portion of cdk_app_file
|
|
369
|
-
cdk_dir_path = Path(cdk_directory)
|
|
370
|
-
|
|
371
|
-
# If we have CODEBUILD_SRC_DIR, use it as the base to calculate relative path
|
|
372
|
-
codebuild_src = os.getenv('CODEBUILD_SRC_DIR')
|
|
373
|
-
|
|
374
|
-
if codebuild_src and cdk_dir_path.is_absolute():
|
|
375
|
-
# Calculate relative path from CodeBuild source directory
|
|
376
|
-
# Example: /codebuild/.../src/devops/cdk-iac relative to /codebuild/.../src = devops/cdk-iac
|
|
377
|
-
try:
|
|
378
|
-
cdk_relative_dir = os.path.relpath(str(cdk_dir_path), codebuild_src)
|
|
379
|
-
# If relpath resulted in going up directories (starts with ..), use empty
|
|
380
|
-
# If relpath is '.' (same directory), use empty (app.py at root)
|
|
381
|
-
if cdk_relative_dir.startswith('..') or cdk_relative_dir == '.':
|
|
382
|
-
cdk_relative_dir = ""
|
|
383
|
-
except ValueError:
|
|
384
|
-
# Paths on different drives (Windows) - fallback to empty
|
|
385
|
-
cdk_relative_dir = ""
|
|
386
|
-
elif cdk_dir_path.is_absolute():
|
|
387
|
-
# No CODEBUILD_SRC_DIR but path is absolute - can't determine relative path reliably
|
|
388
|
-
# Fallback to empty (will use "cdk.out" at root)
|
|
389
|
-
cdk_relative_dir = ""
|
|
390
|
-
else:
|
|
391
|
-
# Path is already relative - use as-is
|
|
392
|
-
cdk_relative_dir = str(cdk_dir_path)
|
|
393
|
-
|
|
394
|
-
# Construct the path to cdk.out relative to project root
|
|
395
|
-
if cdk_relative_dir:
|
|
396
|
-
cdk_out_directory = f"{cdk_relative_dir}/cdk.out"
|
|
397
|
-
else:
|
|
398
|
-
cdk_out_directory = "cdk.out"
|
|
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"
|
|
399
365
|
|
|
400
|
-
|
|
401
|
-
build_commands.append(f"echo 👉
|
|
402
|
-
build_commands.append("echo 👉
|
|
366
|
+
# Debug logging - will be baked into buildspec
|
|
367
|
+
build_commands.append(f"echo '👉 CDK output directory: {cdk_out_directory}'")
|
|
368
|
+
build_commands.append("echo '👉 Consistent location in all environments'")
|
|
403
369
|
|
|
404
370
|
shell = pipelines.ShellStep(
|
|
405
371
|
"CDK Synth",
|
cdk_factory/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.9.
|
|
1
|
+
__version__ = "0.9.8"
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
cdk_factory/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
cdk_factory/app.py,sha256=
|
|
2
|
+
cdk_factory/app.py,sha256=S0KsLivg-DOUGMWwvh1UKA5aU4uI0ckR8r4SwfxN8Mc,9068
|
|
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=
|
|
5
|
+
cdk_factory/version.py,sha256=GI3Cr15wC6XhdahtMoSOf62d2gYve5G_PiR_xx_RGKc,22
|
|
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
|
|
@@ -64,7 +64,8 @@ cdk_factory/interfaces/istack.py,sha256=bhTBs-o9FgKwvJMSuwxjUV6D3nUlvZHVzfm27jP9
|
|
|
64
64
|
cdk_factory/interfaces/live_ssm_resolver.py,sha256=3FIr9a02SXqZmbFs3RT0WxczWEQR_CF7QSt7kWbDrVE,8163
|
|
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
|
-
cdk_factory/pipeline/
|
|
67
|
+
cdk_factory/pipeline/path_utils.py,sha256=fvWdrcb4onmpIu1APkHLhXg8zWfK74HcW3Ra2ynxfXM,2586
|
|
68
|
+
cdk_factory/pipeline/pipeline_factory.py,sha256=cuoVTAICSOw3c0pgVMKNmRArHooecBqMKfKXfQ_wMRw,16050
|
|
68
69
|
cdk_factory/pipeline/stage.py,sha256=Be7ExMB9A-linRM18IQDOzQ-cP_I2_ThRNzlT4FIrUg,437
|
|
69
70
|
cdk_factory/pipeline/security/policies.py,sha256=H3-S6nipz3UtF9Pc5eJYr4-aREUTCaJWMjOUyd6Rdv4,4406
|
|
70
71
|
cdk_factory/pipeline/security/roles.py,sha256=ZB_O5H_BXgotvVspS2kVad9EMcY-a_-vU7Nm1_Z5MB8,4985
|
|
@@ -119,8 +120,8 @@ cdk_factory/utilities/lambda_function_utilities.py,sha256=S1GvBsY_q2cyUiaud3HORJ
|
|
|
119
120
|
cdk_factory/utilities/os_execute.py,sha256=5Op0LY_8Y-pUm04y1k8MTpNrmQvcLmQHPQITEP7EuSU,1019
|
|
120
121
|
cdk_factory/utils/api_gateway_utilities.py,sha256=If7Xu5s_UxmuV-kL3JkXxPLBdSVUKoLtohm0IUFoiV8,4378
|
|
121
122
|
cdk_factory/workload/workload_factory.py,sha256=yBUDGIuB8-5p_mGcVFxsD2ZoZIziak3yh3LL3JvS0M4,5903
|
|
122
|
-
cdk_factory-0.9.
|
|
123
|
-
cdk_factory-0.9.
|
|
124
|
-
cdk_factory-0.9.
|
|
125
|
-
cdk_factory-0.9.
|
|
126
|
-
cdk_factory-0.9.
|
|
123
|
+
cdk_factory-0.9.8.dist-info/METADATA,sha256=ToYLBXdK0G1SMgbAjuFLg_RQP8K2XnPsgRM-dQ0wRsc,2450
|
|
124
|
+
cdk_factory-0.9.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
125
|
+
cdk_factory-0.9.8.dist-info/entry_points.txt,sha256=S1DPe0ORcdiwEALMN_WIo3UQrW_g4YdQCLEsc_b0Swg,53
|
|
126
|
+
cdk_factory-0.9.8.dist-info/licenses/LICENSE,sha256=NOtdOeLwg2il_XBJdXUPFPX8JlV4dqTdDGAd2-khxT8,1066
|
|
127
|
+
cdk_factory-0.9.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|