Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable AWS ARM/Gravition support #581

Merged
merged 1 commit into from
Jul 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions config/java/server-aws-arm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
apiVersion: minectl.ediri.io/v1alpha1
kind: MinecraftServer
metadata:
name: minecraft-server
spec:
monitoring:
enabled: false
server:
cloud: aws
region: eu-central-1
size: c6g.xlarge
ssh:
port: 22
keyfolder: "/Users/dirien/Tools/repos/stackit-minecraft/minecraft/ssh/minecraft"
fail2ban:
bantime: 1000
maxretry: 3
port: 25565
arm: true
minecraft:
java:
openjdk: 17
xmx: 2G
xms: 2G
rcon:
password: test
port: 25575
enabled: true
broadcast: true
edition: java
version: "1.19"
eula: true
properties: |
level-seed=minectlrocks
view-distance=10
enable-jmx-monitoring=false
server-ip=
resource-pack-prompt=
gamemode=survival
allow-nether=true
enable-command-block=false
sync-chunk-writes=true
enable-query=false
op-permission-level=4
prevent-proxy-connections=false
resource-pack=
entity-broadcast-range-percentage=100
level-name=world
player-idle-timeout=0
motd=\u00A76AWS \u00A7rMinecraft --- \u00A76Java \u00A7redition
query.port=25565
force-gamemode=false
rate-limit=0
hardcore=false
white-list=false
broadcast-console-to-ops=true
pvp=true
spawn-npcs=true
spawn-animals=true
snooper-enabled=true
difficulty=easy
function-permission-level=2
network-compression-threshold=256
text-filtering-config=
require-resource-pack=false
spawn-monsters=true
max-tick-time=60000
enforce-whitelist=false
use-native-transport=true
max-players=100
resource-pack-sha1=
spawn-protection=16
online-mode=true
enable-status=true
allow-flight=false
max-world-size=29999984
74 changes: 74 additions & 0 deletions config/papermc/server-aws-arm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
apiVersion: minectl.ediri.io/v1alpha1
kind: MinecraftServer
metadata:
name: minecraft-server-arm
spec:
server:
cloud: aws
region: eu-central-1
size: c6g.xlarge
ssh:
port: 22
keyfolder: "/Users/dirien/Tools/repos/stackit-minecraft/minecraft/ssh/minecraft"
fail2ban:
bantime: 1000
maxretry: 3
port: 25565
arm: true
minecraft:
java:
openjdk: 17
xmx: 2G
xms: 2G
rcon:
password: test
port: 25575
enabled: true
broadcast: true
edition: papermc
version: 1.19-29
eula: true
properties: |
level-seed=minectlrocks
view-distance=10
enable-jmx-monitoring=false
server-ip=
resource-pack-prompt=
gamemode=survival
allow-nether=true
enable-command-block=false
sync-chunk-writes=true
enable-query=false
op-permission-level=4
prevent-proxy-connections=false
resource-pack=
entity-broadcast-range-percentage=100
level-name=world
player-idle-timeout=0
motd=\u00A76AWS \u00A7rMinecraft Graviton --- \u00A76PaperMC \u00A7redition
query.port=25565
force-gamemode=false
rate-limit=0
hardcore=false
white-list=false
broadcast-console-to-ops=true
pvp=true
spawn-npcs=true
spawn-animals=true
snooper-enabled=true
difficulty=easy
function-permission-level=2
network-compression-threshold=256
text-filtering-config=
require-resource-pack=false
spawn-monsters=true
max-tick-time=60000
enforce-whitelist=false
use-native-transport=true
max-players=100
resource-pack-sha1=
spawn-protection=16
online-mode=true
enable-status=true
allow-flight=false
max-world-size=
44 changes: 35 additions & 9 deletions internal/cloud/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path/filepath"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -202,14 +203,22 @@ func addTagSpecifications(args automation.ServerArgs, resourceType string) []*ec
func (a *Aws) CreateServer(args automation.ServerArgs) (*automation.ResourceResults, error) { // nolint: gocyclo
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
defer cancel()
image, err := a.lookupAMI("ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20220420")
pubKeyFile, err := os.ReadFile(fmt.Sprintf("%s.pub", args.MinecraftResource.GetSSHKeyFolder()))
if err != nil {
return nil, err
}

pubKeyFile, err := os.ReadFile(fmt.Sprintf("%s.pub", args.MinecraftResource.GetSSHKeyFolder()))
if err != nil {
return nil, err
var imageAMI *string
if args.MinecraftResource.IsArm() {
imageAMI, err = a.lookupAMI("ubuntu-minimal/images/hvm-ssd/ubuntu-jammy-22.04*", "arm64")
if err != nil {
return nil, err
}
} else {
imageAMI, err = a.lookupAMI("ubuntu-minimal/images/hvm-ssd/ubuntu-jammy-22.04*", "x86_64")
if err != nil {
return nil, err
}
}

key, err := a.client.ImportKeyPair(&ec2.ImportKeyPairInput{
Expand Down Expand Up @@ -280,7 +289,7 @@ func (a *Aws) CreateServer(args automation.ServerArgs) (*automation.ResourceResu
spotInstance := ec2.RequestSpotInstancesInput{
InstanceCount: aws.Int64(1),
LaunchSpecification: &ec2.RequestSpotLaunchSpecification{
ImageId: image,
ImageId: imageAMI,
KeyName: key.KeyName,
InstanceType: aws.String(args.MinecraftResource.GetSize()),
BlockDeviceMappings: addBlockDevice(args.MinecraftResource.GetVolumeSize()),
Expand Down Expand Up @@ -361,7 +370,7 @@ func (a *Aws) CreateServer(args automation.ServerArgs) (*automation.ResourceResu
} else {
zap.S().Infow("Creating instance", "name", args.MinecraftResource.GetName())
instanceInput := &ec2.RunInstancesInput{
ImageId: image,
ImageId: imageAMI,
KeyName: key.KeyName,
InstanceType: aws.String(args.MinecraftResource.GetSize()),
MinCount: aws.Int64(1),
Expand Down Expand Up @@ -664,7 +673,7 @@ func (a *Aws) createEC2SecurityGroupRule(groupID, protocol string, fromPort, toP
}

// lookupAMI gets the AMI ID that the exit node will use
func (a *Aws) lookupAMI(name string) (*string, error) {
func (a *Aws) lookupAMI(name, architecture string) (*string, error) {
images, err := a.client.DescribeImages(&ec2.DescribeImagesInput{
Filters: []*ec2.Filter{
{
Expand All @@ -673,15 +682,32 @@ func (a *Aws) lookupAMI(name string) (*string, error) {
aws.String(name),
},
},
{
Name: aws.String("architecture"),
Values: []*string{
aws.String(architecture),
},
},
{
Name: aws.String("owner-id"),
Values: []*string{
aws.String("099720109477"),
},
},
},
})
if err != nil {
return nil, err
}

if len(images.Images) == 0 {
return nil, fmt.Errorf("image not found")
}

sort.SliceStable(images.Images, func(i, j int) bool {
before := *images.Images[i].CreationDate
after := *images.Images[j].CreationDate
beforeTime, _ := time.Parse(time.RFC3339, before)
afterTime, _ := time.Parse(time.RFC3339, after)
return beforeTime.After(afterTime)
})
return images.Images[0].ImageId, nil
}