Skip to content

Commit

Permalink
Imprs
Browse files Browse the repository at this point in the history
  • Loading branch information
krystian-panek-vmltech committed Oct 27, 2023
1 parent 1990a1a commit 8d99ad7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
10 changes: 9 additions & 1 deletion internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (c Client) DirEnsure(path string) error {
func (c Client) FileExists(path string) (bool, error) {
out, err := c.RunShell(fmt.Sprintf("test -f %s && echo '0' || echo '1'", path))
if err != nil {
return false, err
return false, fmt.Errorf("cannot check if file exists '%s': %w", path, err)
}
return strings.TrimSpace(string(out)) == "0", nil
}
Expand All @@ -147,6 +147,14 @@ func (c Client) FileMove(oldPath string, newPath string) error {
return nil
}

func (c Client) DirExists(path string) (bool, error) {
out, err := c.RunShell(fmt.Sprintf("test -d %s && echo '0' || echo '1'", path))
if err != nil {
return false, fmt.Errorf("cannot check if directory exists '%s': %w", path, err)
}
return strings.TrimSpace(string(out)) == "0", nil
}

func (c Client) DirCopy(localPath string, remotePath string, override bool) error {
if err := c.DirEnsure(remotePath); err != nil {
return err
Expand Down
41 changes: 37 additions & 4 deletions internal/provider/instance_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"fmt"
"github.com/hashicorp/terraform-plugin-log/tflog"
"gopkg.in/yaml.v3"
)

type InstanceClient ClientContext[InstanceResourceModel]
Expand All @@ -28,11 +29,17 @@ func (ic *InstanceClient) prepareDataDir() error {
return nil
}

func (ic *InstanceClient) installCompose() error { // TODO do not rely on github script here maybe
out, err := ic.cl.RunShellWithEnv(fmt.Sprintf("cd %s && curl -s https://raw.githubusercontent.com/wttech/aemc/main/project-init.sh?token=1 | sh", ic.DataDir()))
tflog.Info(ic.ctx, string(out))
func (ic *InstanceClient) installComposeWrapper() error {
exists, err := ic.cl.FileExists(fmt.Sprintf("%s/aemw", ic.DataDir()))
if err != nil {
return fmt.Errorf("cannot install AEM Compose CLI: %w", err)
return fmt.Errorf("cannot check if AEM Compose CLI wrapper is installed: %w", err)
}
if !exists {
out, err := ic.cl.RunShellWithEnv(fmt.Sprintf("cd %s && curl -s 'https://raw.githubusercontent.com/wttech/aemc/main/pkg/project/common/aemw' -o 'aemw'", ic.DataDir()))
tflog.Info(ic.ctx, string(out))
if err != nil {
return fmt.Errorf("cannot download AEM Compose CLI wrapper: %w", err)
}
}
return nil
}
Expand Down Expand Up @@ -84,3 +91,29 @@ func (ic *InstanceClient) launch() error {

return nil
}

type InstanceStatus struct {
Data struct {
Instances []struct {
ID string `yaml:"id"`
URL string `yaml:"url"`
AemVersion string `yaml:"aem_version"`
Attributes []string `yaml:"attributes"`
RunModes []string `yaml:"run_modes"`
HealthChecks []string `yaml:"health_checks"`
Dir string `yaml:"dir"`
} `yaml:"instances"`
}
}

func (ic *InstanceClient) ReadStatus() (InstanceStatus, error) {

Check failure on line 109 in internal/provider/instance_client.go

View workflow job for this annotation

GitHub Actions / Build

other declaration of ReadStatus

Check failure on line 109 in internal/provider/instance_client.go

View workflow job for this annotation

GitHub Actions / generate

other declaration of ReadStatus

Check failure on line 109 in internal/provider/instance_client.go

View workflow job for this annotation

GitHub Actions / Build

other declaration of ReadStatus

Check failure on line 109 in internal/provider/instance_client.go

View workflow job for this annotation

GitHub Actions / generate

other declaration of ReadStatus
var status InstanceStatus
yamlBytes, err := ic.cl.RunShellWithEnv(fmt.Sprintf("cd %s && sh aemw instance status --output-format yaml", ic.DataDir()))
if err != nil {
return status, err
}
if err := yaml.Unmarshal(yamlBytes, &status); err != nil {
return status, fmt.Errorf("unable to parse AEM instance status: %w", err)
}
return status, nil
}

0 comments on commit 8d99ad7

Please sign in to comment.