Skip to content

Commit fa2e3b7

Browse files
committed
fixing issue for deployment dev
1 parent eb2982a commit fa2e3b7

File tree

2 files changed

+39
-150
lines changed

2 files changed

+39
-150
lines changed

.github/workflows/snowpark-ci-cd.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ jobs:
2929
# Install from requirements.txt
3030
pip install -r requirements.txt
3131
32-
# Verify Snow CLI installation - use simpler command that works with older versions
32+
# Just verify Snow CLI version - don't try to use other commands that might not exist
3333
snow --version || echo "Snow CLI version check failed"
34-
snow object list --help || echo "Snow CLI command check failed"
3534
3635
- name: Set environment variables based on branch
3736
run: |
@@ -114,16 +113,17 @@ jobs:
114113
run: |
115114
python -m pip install --upgrade pip
116115
117-
# Install from requirements.txt
118-
pip install -r requirements.txt
116+
# Install from requirements.txt with force reinstall for key packages
117+
pip install -r requirements.txt --force-reinstall
119118
120-
# Install Snow CLI and Snowpark extension explicitly
121-
pip install snowflake-cli snowflake-cli-labs
122-
snow extension install snowpark
119+
# Install specific version we know works (avoid 0.2.9)
120+
pip install snowflake-connector-python==3.13.2 snowflake-snowpark-python==1.25.0
123121
124-
# Verify Snow CLI installation
122+
# Just verify Snow CLI version - no extension or snowpark commands
125123
snow --version
126-
snow help | grep snowpark
124+
125+
# Try an informative command that should work in most versions
126+
snow --help || echo "Can't get help"
127127
128128
- name: Set environment variables based on branch
129129
run: |

scripts/deployment_files/snowflake_deployer.py

Lines changed: 30 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -406,53 +406,25 @@ def fallback_deploy_udf(conn_config, component_path, component_name, project_con
406406
conn.close()
407407

408408
def verify_snow_cli_installation():
409-
"""Verify Snow CLI is installed and available, install if missing."""
409+
"""Verify Snow CLI is installed and available."""
410410
try:
411-
# Try to check if snow CLI is installed
411+
# Only check if snow CLI is installed with basic version command
412412
result = subprocess.run(["snow", "--version"], capture_output=True, text=True)
413413
version_output = result.stdout.strip()
414414
logger.info(f"Snow CLI is installed: {version_output}")
415415

416-
# Parse the version number to determine command availability
417-
version_str = version_output.split(": ")[-1] if ": " in version_output else version_output
418-
version_parts = version_str.split('.')
419-
420-
try:
421-
major = int(version_parts[0])
422-
minor = int(version_parts[1]) if len(version_parts) > 1 else 0
423-
424-
logger.info(f"Snow CLI version parsed: {major}.{minor}")
425-
426-
# Use appropriate commands based on version
427-
if major == 0 and minor < 3:
428-
# For older versions like 0.2.9, check if we can list objects
429-
check_cmd = ["snow", "object", "list", "--help"]
430-
logger.info("Using Snow CLI legacy commands (v0.2.x)")
431-
else:
432-
# For newer versions, we expect snowpark commands
433-
check_cmd = ["snow", "--help"]
434-
logger.info("Using Snow CLI modern commands (v0.3+)")
435-
436-
# Check if basic commands work
437-
help_result = subprocess.run(check_cmd, capture_output=True, text=True)
438-
if help_result.returncode != 0:
439-
logger.warning(f"Snow CLI command check failed: {help_result.stderr}")
440-
else:
441-
logger.info("Snow CLI command check passed")
442-
except (ValueError, IndexError):
443-
logger.warning(f"Could not parse Snow CLI version: {version_str}")
444-
416+
# Don't try to parse version or run other commands that may not exist
445417
return True
446418

447419
except (subprocess.SubprocessError, FileNotFoundError):
448420
logger.warning("Snow CLI not found. Attempting to install...")
449421

450422
try:
451-
# Install Snow CLI using pip
452-
subprocess.run(["pip", "install", "--upgrade", "snowflake-cli==0.3.0", "snowflake-cli-labs==0.2.0"], check=True)
423+
# Install Snow CLI using pip - no need to specify exact version
424+
subprocess.run(["pip", "install", "snowflake-cli"], check=True)
453425
logger.info("Successfully installed Snow CLI via pip")
454426

455-
# Verify installation
427+
# Verify installation with minimal command
456428
result = subprocess.run(["snow", "--version"], capture_output=True, text=True)
457429
logger.info(f"Verified Snow CLI installation: {result.stdout.strip()}")
458430

@@ -462,59 +434,35 @@ def verify_snow_cli_installation():
462434
return False
463435

464436
def deploy_snowpark_projects(root_directory, profile_name, check_git_changes=False, git_ref='HEAD~1'):
465-
"""Deploy all Snowpark projects found in the root directory using Snow CLI."""
437+
"""Deploy all Snowpark projects found in the root directory using direct connection."""
466438
logger.info(f"Deploying all Snowpark apps in root directory {root_directory}")
467439

468-
# Ensure Snow CLI is installed
469-
if not verify_snow_cli_installation():
470-
logger.error("Snow CLI is not available. Cannot proceed with deployment.")
471-
return False
440+
# Verify Snow CLI exists, but we'll use direct deployment instead
441+
verify_snow_cli_installation()
472442

473-
# Get connection config for environment variables
443+
# Get connection config
474444
conn_config = get_connection_config(profile_name)
475445
if conn_config is None:
476446
return False
477447

478-
# Set environment variables for Snow CLI
448+
# Set environment variables (still useful for some commands)
479449
os.environ["SNOWFLAKE_ACCOUNT"] = conn_config.get('account', '')
480450
os.environ["SNOWFLAKE_USER"] = conn_config.get('user', '')
481451
os.environ["SNOWFLAKE_ROLE"] = conn_config.get('role', '')
482452
os.environ["SNOWFLAKE_WAREHOUSE"] = conn_config.get('warehouse', '')
483453
os.environ["SNOWFLAKE_DATABASE"] = conn_config.get('database', '')
484454

485-
# Handle password or key-based authentication
486455
if 'password' in conn_config:
487456
os.environ["SNOWFLAKE_PASSWORD"] = conn_config.get('password', '')
488457
elif 'private_key_path' in conn_config:
489458
os.environ["SNOWFLAKE_PRIVATE_KEY_PATH"] = conn_config.get('private_key_path', '')
490-
491-
# Try to get the Snow CLI version to determine command format
492-
try:
493-
version_result = subprocess.run(["snow", "--version"], capture_output=True, text=True)
494-
version_output = version_result.stdout.strip()
495-
version_str = version_output.split(": ")[-1] if ": " in version_output else version_output
496-
version_parts = version_str.split('.')
497-
major = int(version_parts[0])
498-
minor = int(version_parts[1]) if len(version_parts) > 1 else 0
499-
500-
# Set command format based on version
501-
if major == 0 and minor < 3:
502-
# Old Snow CLI (0.2.x) uses different commands
503-
use_legacy_commands = True
504-
logger.info("Using legacy Snow CLI commands (v0.2.x)")
505-
else:
506-
use_legacy_commands = False
507-
logger.info("Using modern Snow CLI commands (v0.3+)")
508-
except Exception as e:
509-
logger.warning(f"Could not determine Snow CLI version: {str(e)}. Will use fallback.")
510-
use_legacy_commands = True
511459

512460
# Stats for summary
513461
projects_found = 0
514462
projects_deployed = 0
515463
projects_skipped = 0
516464

517-
# Walk the entire directory structure recursively
465+
# Walk the directory structure
518466
success = True
519467
for (directory_path, directory_names, file_names) in os.walk(root_directory):
520468
# Get just the last/final folder name in the directory path
@@ -548,6 +496,7 @@ def deploy_snowpark_projects(root_directory, profile_name, check_git_changes=Fal
548496
projects_skipped += 1
549497
should_deploy = False
550498

499+
# If the project should be deployed
551500
if should_deploy:
552501
# Read the project config
553502
project_settings = {}
@@ -568,91 +517,31 @@ def deploy_snowpark_projects(root_directory, profile_name, check_git_changes=Fal
568517
# Save current directory
569518
current_dir = os.getcwd()
570519

571-
# Decide deployment method based on CLI version
572-
deployment_successful = False
520+
# Skip trying to use Snow CLI snowpark commands, go directly to fallback deployment
521+
logger.info(f"Using direct deployment method for {project_name}")
573522

574-
try:
575-
# Change to project directory
576-
os.chdir(f"{directory_path}")
523+
# Get function information from project config
524+
if 'functions' in project_settings.get('snowpark', {}) and project_settings['snowpark']['functions']:
525+
function_config = project_settings['snowpark']['functions'][0]
526+
function_name = function_config.get('name', project_name)
577527

578-
# List directory contents for debugging
579-
logger.info(f"Directory contents of {directory_path}:")
580-
for item in os.listdir('.'):
581-
logger.info(f" - {item}")
582-
583-
if use_legacy_commands:
584-
# Legacy Snow CLI (0.2.x) - use native Python UDF deployment
585-
logger.info("Using fallback deployment method for Snow CLI 0.2.x")
586-
587-
# Get function information from project config
588-
if 'functions' in project_settings.get('snowpark', {}) and project_settings['snowpark']['functions']:
589-
function_config = project_settings['snowpark']['functions'][0]
590-
function_name = function_config.get('name', component_name)
591-
592-
# Use fallback deployment
593-
if fallback_deploy_udf(conn_config, directory_path, function_name, project_settings):
594-
logger.info(f"Successfully deployed {project_name} using fallback method")
595-
deployment_successful = True
596-
projects_deployed += 1
597-
else:
598-
logger.error("No function definition found in project config")
528+
# Use direct deployment method
529+
if fallback_deploy_udf(conn_config, directory_path, function_name, project_settings):
530+
logger.info(f"Successfully deployed {project_name} using direct method")
531+
projects_deployed += 1
599532
else:
600-
# Modern Snow CLI (0.3+) - use snowpark commands
601-
# Build the project
602-
logger.info("Building project with Snow CLI...")
603-
build_cmd = ["snow", "snowpark", "build", "--temporary-connection",
604-
"--account", os.environ["SNOWFLAKE_ACCOUNT"],
605-
"--user", os.environ["SNOWFLAKE_USER"],
606-
"--role", os.environ["SNOWFLAKE_ROLE"],
607-
"--warehouse", os.environ["SNOWFLAKE_WAREHOUSE"],
608-
"--database", os.environ["SNOWFLAKE_DATABASE"]]
609-
610-
logger.info(f"Executing: {' '.join(build_cmd)}")
611-
build_result = subprocess.run(build_cmd, capture_output=True, text=True)
612-
logger.info(f"Build STDOUT: {build_result.stdout}")
613-
logger.info(f"Build STDERR: {build_result.stderr}")
614-
615-
# Deploy the project
616-
logger.info("Deploying project with Snow CLI...")
617-
deploy_cmd = ["snow", "snowpark", "deploy", "--replace", "--temporary-connection",
618-
"--account", os.environ["SNOWFLAKE_ACCOUNT"],
619-
"--user", os.environ["SNOWFLAKE_USER"],
620-
"--role", os.environ["SNOWFLAKE_ROLE"],
621-
"--warehouse", os.environ["SNOWFLAKE_WAREHOUSE"],
622-
"--database", os.environ["SNOWFLAKE_DATABASE"]]
623-
624-
logger.info(f"Executing: {' '.join(deploy_cmd)}")
625-
deploy_result = subprocess.run(deploy_cmd, capture_output=True, text=True)
626-
logger.info(f"Deploy STDOUT: {deploy_result.stdout}")
627-
logger.info(f"Deploy STDERR: {deploy_result.stderr}")
628-
629-
if build_result.returncode != 0 or deploy_result.returncode != 0:
630-
logger.error(f"Failed to deploy project in {directory_path}")
631-
# Try fallback method
632-
logger.info(f"Attempting fallback deployment for {project_name}")
633-
function_name = project_name
634-
if 'functions' in project_settings.get('snowpark', {}) and project_settings['snowpark']['functions']:
635-
function_name = project_settings['snowpark']['functions'][0].get('name', project_name)
636-
637-
if fallback_deploy_udf(conn_config, directory_path, function_name, project_settings):
638-
logger.info(f"Fallback deployment successful for {project_name}")
639-
deployment_successful = True
640-
projects_deployed += 1
641-
else:
642-
logger.info(f"Successfully deployed project in {directory_path}")
643-
deployment_successful = True
644-
projects_deployed += 1
645-
646-
except Exception as e:
647-
logger.error(f"Error processing project in {directory_path}: {str(e)}")
533+
logger.error(f"Failed to deploy {project_name}")
534+
success = False
535+
else:
536+
logger.error(f"No function definition found in project config for {project_name}")
648537
success = False
649-
finally:
650-
# Restore original directory
651-
os.chdir(current_dir)
652538

653539
except Exception as e:
654540
logger.error(f"Error processing project in {directory_path}: {str(e)}")
655541
success = False
542+
finally:
543+
# Restore original directory
544+
os.chdir(current_dir)
656545

657546
# Log summary
658547
logger.info(f"Deployment summary: Found {projects_found} projects, deployed {projects_deployed}, skipped {projects_skipped}")

0 commit comments

Comments
 (0)