| 26 | } |
| 27 | |
| 28 | func (d *deployCmd) Command(celer *configs.Celer) *cobra.Command { |
| 29 | d.celer = celer |
| 30 | command := &cobra.Command{ |
| 31 | Use: "deploy", |
| 32 | Short: "Deploy with selected platform and project.", |
| 33 | Long: `Deploy builds and installs all packages defined in the current project. |
| 34 | |
| 35 | After successful deployment, you can optionally export a snapshot |
| 36 | for reproducible builds using the --snapshot flag, and you can also |
| 37 | strip installed binaries and libraies with --strip. |
| 38 | |
| 39 | Examples: |
| 40 | celer deploy --force # Force deploy and ignore installed |
| 41 | celer deploy --snapshot=${filepath} # Initialize with conf repo |
| 42 | celer deploy --strip # Strip installed binaries and libraries`, |
| 43 | Args: d.validateArgs, |
| 44 | RunE: func(cmd *cobra.Command, args []string) error { |
| 45 | if err := d.celer.Init(); err != nil { |
| 46 | return color.PrintError(err, "failed to init celer.") |
| 47 | } |
| 48 | |
| 49 | platformName := expr.If(d.celer.Platform().GetName() != "", d.celer.Platform().GetName(), "native") |
| 50 | projectName := d.celer.Project().GetName() |
| 51 | |
| 52 | // Display deployment header. |
| 53 | color.Println(color.Title, "=======================================================================") |
| 54 | color.Printf(color.Title, "🚀 start to deploy:\n") |
| 55 | color.Printf(color.Title, "📌 platform: %s\n", platformName) |
| 56 | color.Printf(color.Title, "📌 project: %s\n", projectName) |
| 57 | color.Println(color.Title, "=======================================================================") |
| 58 | |
| 59 | // Check circular dependency and version conflict. |
| 60 | if err := d.checkProject(); err != nil { |
| 61 | return color.PrintError(err, "failed to check circular dependency and version conflict.") |
| 62 | } |
| 63 | |
| 64 | // Resolve all dependency refs before any clone/download begins. |
| 65 | if err := d.resolveAllRefs(); err != nil { |
| 66 | return color.PrintError(err, "failed to resolve refs.") |
| 67 | } |
| 68 | |
| 69 | if err := d.celer.Deploy(d.force, d.strip); err != nil { |
| 70 | return color.PrintError(err, "failed to deploy celer.") |
| 71 | } |
| 72 | |
| 73 | color.PrintSuccess("%s has been successfully deployed.", projectName) |
| 74 | |
| 75 | // Export snapshot if requested. |
| 76 | if d.snapshotPath != "" { |
| 77 | if err := snapshot.Export(d.celer, d.snapshotPath); err != nil { |
| 78 | return fmt.Errorf("failed to export snapshot -> %w", err) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | return nil |
| 83 | }, |
| 84 | ValidArgsFunction: d.completion, |
| 85 | } |