|
7 | 7 | stderrors "errors" |
8 | 8 | "fmt" |
9 | 9 | "net/url" |
10 | | - "os" |
11 | | - osexec "os/exec" |
12 | | - "path/filepath" |
13 | 10 | "strconv" |
14 | 11 | "strings" |
15 | 12 | "text/template" |
@@ -72,9 +69,6 @@ const ( |
72 | 69 |
|
73 | 70 | var forwarderContractVersion = semver.MustParse("1.0.0") |
74 | 71 |
|
75 | | -var aptosLookPath = osexec.LookPath |
76 | | -var aptosContainerImage = aptosContainerImageFromDocker |
77 | | - |
78 | 72 | type Aptos struct{} |
79 | 73 |
|
80 | 74 | type methodConfigSettings struct { |
@@ -551,12 +545,6 @@ func ensureForwarder( |
551 | 545 | Msg("Aptos deployer account not confirmed visible yet; proceeding with deploy retries") |
552 | 546 | } |
553 | 547 |
|
554 | | - restoreAptosCLI, err := prepareAptosCLI(ctx, containerName) |
555 | | - if err != nil { |
556 | | - return "", fmt.Errorf("failed to prepare Aptos CLI for forwarder deploy on chain selector %d: %w", chain.ChainSelector(), err) |
557 | | - } |
558 | | - defer restoreAptosCLI() |
559 | | - |
560 | 548 | var deployedAddress string |
561 | 549 | var pendingTxHash string |
562 | 550 | var lastDeployErr error |
@@ -605,89 +593,6 @@ func ensureForwarder( |
605 | 593 | return addr, nil |
606 | 594 | } |
607 | 595 |
|
608 | | -// prepareAptosCLI makes the host aptos CLI available for Move package |
609 | | -// compilation. Local CRE runners do not always have aptos installed, so fall |
610 | | -// back to a thin wrapper that runs the CLI from the existing Aptos container |
611 | | -// image with the current working directory bind-mounted. |
612 | | -func prepareAptosCLI(ctx context.Context, containerName string) (func(), error) { |
613 | | - if _, err := aptosLookPath("aptos"); err == nil { |
614 | | - return func() {}, nil |
615 | | - } |
616 | | - |
617 | | - containerName = strings.TrimSpace(containerName) |
618 | | - if containerName == "" { |
619 | | - return nil, pkgerrors.New("aptos CLI not found on PATH and no Aptos container is available for fallback") |
620 | | - } |
621 | | - |
622 | | - image, err := aptosContainerImage(ctx, containerName) |
623 | | - if err != nil { |
624 | | - return nil, err |
625 | | - } |
626 | | - |
627 | | - wrapperDir, err := os.MkdirTemp("", "aptos-cli-wrapper-*") |
628 | | - if err != nil { |
629 | | - return nil, fmt.Errorf("create Aptos CLI wrapper directory: %w", err) |
630 | | - } |
631 | | - |
632 | | - wrapperPath := filepath.Join(wrapperDir, "aptos") |
633 | | - script := fmt.Sprintf(`#!/bin/sh |
634 | | -set -eu |
635 | | -pwd_path="$(pwd -P)" |
636 | | -exec docker run --rm \ |
637 | | - --user "$(id -u):$(id -g)" \ |
638 | | - -v "$pwd_path:$pwd_path" \ |
639 | | - -w "$pwd_path" \ |
640 | | - --entrypoint aptos \ |
641 | | - %q "$@" |
642 | | -`, image) |
643 | | - if err := os.WriteFile(wrapperPath, []byte(script), 0o600); err != nil { |
644 | | - _ = os.RemoveAll(wrapperDir) |
645 | | - return nil, fmt.Errorf("write Aptos CLI wrapper script: %w", err) |
646 | | - } |
647 | | - if err := os.Chmod(wrapperPath, 0o700); err != nil { |
648 | | - _ = os.RemoveAll(wrapperDir) |
649 | | - return nil, fmt.Errorf("mark Aptos CLI wrapper script executable: %w", err) |
650 | | - } |
651 | | - |
652 | | - oldPath := os.Getenv("PATH") |
653 | | - if oldPath == "" { |
654 | | - if err := os.Setenv("PATH", wrapperDir); err != nil { |
655 | | - _ = os.RemoveAll(wrapperDir) |
656 | | - return nil, fmt.Errorf("prepend Aptos CLI wrapper to PATH: %w", err) |
657 | | - } |
658 | | - } else { |
659 | | - if err := os.Setenv("PATH", wrapperDir+string(os.PathListSeparator)+oldPath); err != nil { |
660 | | - _ = os.RemoveAll(wrapperDir) |
661 | | - return nil, fmt.Errorf("prepend Aptos CLI wrapper to PATH: %w", err) |
662 | | - } |
663 | | - } |
664 | | - |
665 | | - return func() { |
666 | | - _ = os.Setenv("PATH", oldPath) |
667 | | - _ = os.RemoveAll(wrapperDir) |
668 | | - }, nil |
669 | | -} |
670 | | - |
671 | | -// PrepareAptosCLI ensures the aptos CLI is available for local smoke tests and |
672 | | -// setup phases that compile Move packages on the host. |
673 | | -func PrepareAptosCLI(ctx context.Context, containerName string) (func(), error) { |
674 | | - return prepareAptosCLI(ctx, containerName) |
675 | | -} |
676 | | - |
677 | | -func aptosContainerImageFromDocker(ctx context.Context, containerName string) (string, error) { |
678 | | - out, err := osexec.CommandContext(ctx, "docker", "inspect", "--format", "{{.Config.Image}}", containerName).CombinedOutput() |
679 | | - if err != nil { |
680 | | - return "", fmt.Errorf("inspect Aptos container image for %q: %w (%s)", containerName, err, strings.TrimSpace(string(out))) |
681 | | - } |
682 | | - |
683 | | - image := strings.TrimSpace(string(out)) |
684 | | - if image == "" { |
685 | | - return "", fmt.Errorf("inspect Aptos container image for %q: empty image reference", containerName) |
686 | | - } |
687 | | - |
688 | | - return image, nil |
689 | | -} |
690 | | - |
691 | 596 | // addForwarderToDataStore seals a new datastore snapshot with the Aptos |
692 | 597 | // forwarder address so later setup phases can reuse it without redeploying. |
693 | 598 | func addForwarderToDataStore(creEnv *cre.Environment, chainSelector uint64, address string) error { |
|
0 commit comments