Skip to content

Commit

Permalink
basic amazon now working
Browse files Browse the repository at this point in the history
  • Loading branch information
aronchick committed Dec 14, 2024
1 parent 9736d9f commit 2e306d4
Show file tree
Hide file tree
Showing 16 changed files with 953 additions and 659 deletions.
1 change: 1 addition & 0 deletions .cspell/custom-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ dryrun
dupl
eastasia
eastus
enis
errcheck
Errf
errgroup
Expand Down
10 changes: 5 additions & 5 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# shellcheck disable=SC1090
. <( flox activate; );

unset GOROOT
export PATH=$PATH:$GOROOT/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
export PATH=/Users/daaronch/.cache/flox/run/aronchick/andaime.19a05c92/bin:$PATH
unset GOROOT
export PATH=$PATH:$GOROOT/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
export PATH=/Users/daaronch/.cache/flox/run/aronchick/andaime.19a05c92/bin:$PATH
31 changes: 21 additions & 10 deletions cmd/andaime.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,23 @@ func GetSession(region string) *session.Session {

return sess
}

// getUbuntuAMIId retrieves the latest Ubuntu AMI ID from AWS for a given architecture.
// It specifically looks for Ubuntu 22.04 (Jammy) images from Canonical.
//
// Parameters:
//
// svc: AWS EC2 service client
// arch: Target architecture (e.g., "x86_64" or "arm64")
//
// Returns:
//
// string: AMI ID if found
// error: Error if any occurred during the operation
func getUbuntuAMIId(svc *ec2.EC2, arch string) (string, error) {
const ubuntuVersion = "ubuntu-jammy-22.04"
const canonicalOwnerID = "099720109477"

describeImagesInput := &ec2.DescribeImagesInput{
Filters: []*ec2.Filter{
{
Expand All @@ -208,34 +224,29 @@ func getUbuntuAMIId(svc *ec2.EC2, arch string) (string, error) {
Values: aws.StringSlice([]string{"available"}),
},
},
Owners: aws.StringSlice([]string{"099720109477"}), // Canonical's owner ID
Owners: aws.StringSlice([]string{canonicalOwnerID}),
}

// Call DescribeImages to find matching AMIs
result, err := svc.DescribeImages(describeImagesInput)
if err != nil {
fmt.Printf("Failed to describe images, %v\n", err)
return "", err
return "", fmt.Errorf("failed to describe images: %w", err)
}

if len(result.Images) == 0 {
fmt.Println("No Ubuntu AMIs found")
return "", err
return "", fmt.Errorf("no Ubuntu AMIs found")
}

// Filter the results to find the latest image that matches the desired pattern
var latestImage *ec2.Image
for _, image := range result.Images {
if strings.Contains(*image.Name, "ubuntu-jammy-22.04") {
if strings.Contains(*image.Name, ubuntuVersion) {
if latestImage == nil || *image.CreationDate > *latestImage.CreationDate {
latestImage = image
}
}
}

if latestImage == nil {
fmt.Println("No matching Ubuntu 22.04 AMIs found")
return "", fmt.Errorf("no matching Ubuntu 22.04 AMIs found")
return "", fmt.Errorf("no matching %s AMIs found", ubuntuVersion)
}

if VerboseModeFlag {
Expand Down
30 changes: 22 additions & 8 deletions cmd/beta/aws/create_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"time"

"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/bacalhau-project/andaime/pkg/display"
"github.com/bacalhau-project/andaime/pkg/logger"
"github.com/bacalhau-project/andaime/pkg/models"
Expand Down Expand Up @@ -103,13 +102,6 @@ func ExecuteCreateDeployment(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("failed to write VPC ID to config: %w", err)
}

// Ensure EC2 client is initialized
ec2Client := awsProvider.GetEC2Client()
if ec2Client == nil {
ec2Client = ec2.NewFromConfig(*awsProvider.GetConfig())
awsProvider.SetEC2Client(ec2Client)
}

m := display.NewDisplayModel(deployment)
prog := display.GetGlobalProgramFunc()

Expand Down Expand Up @@ -317,13 +309,35 @@ func runDeployment(ctx context.Context, awsProvider *aws_provider.AWSProvider) e
)
}

machine.SetMachineResourceState(
models.ServiceTypeSSH.Name,
models.ResourceStatePending,
)

if err := sshConfig.WaitForSSH(ctx, sshutils.SSHRetryAttempts, sshutils.GetAggregateSSHTimeout()); err != nil {
machine.SetMachineResourceState(
models.ServiceTypeSSH.Name,
models.ResourceStateFailed,
)
return fmt.Errorf(
"failed to establish SSH connection to machine %s: %w",
machine.GetName(),
err,
)
}
machine.SetMachineResourceState(
models.ServiceTypeSSH.Name,
models.ResourceStateSucceeded,
)

m.QueueUpdate(display.UpdateAction{
MachineName: machine.GetName(),
UpdateData: display.UpdateData{
UpdateType: display.UpdateTypeResource,
ResourceType: "SSH",
ResourceState: models.MachineResourceState(models.ServiceTypeSSH.State),
},
})

l.Infof("Machine %s is accessible via SSH", machine.GetName())
}
Expand Down
Loading

0 comments on commit 2e306d4

Please sign in to comment.