Skip to content

Commit

Permalink
[RELEASE STABLE] Use CCX33 and Volume.
Browse files Browse the repository at this point in the history
LineageOS builds needs decent amount of storage, also we
don't need poor 16vcpu, we only need 8 vcpu (dedicated) since
hetzner does not allow more than 32 gb for default users. We
cant use all 16 vcpu if we have less than 64 gb of RAM.

So we use CCX33 (8 vCPU, 32 GB RAM, 240 GB Storage), since 240gb
is not enough for a lineage os build, we use 400 GB volume and mount
it at /ham-build

We have taken measure to delete the volume when the build fails or
the build is finished.

Signed-off-by: Divya Antony J.R <[email protected]>
  • Loading branch information
antony-jr committed Nov 7, 2023
1 parent 536d026 commit fcb3bc2
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 78 deletions.
6 changes: 3 additions & 3 deletions internal/cmd/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func NewCommand() *cli.Command {
// Destroy server
// on close.
if !argv.KeepServer {
defer destroyCurrentServer(&client.Server, hf.SHA256Sum)
defer destroyCurrentServer(client, hf.SHA256Sum)
}

vars, err := helpers.ReadVarsJsonFile(argv.VarsPath)
Expand Down Expand Up @@ -388,11 +388,11 @@ func checkErrorStatus(state *statusT, err error) error {
return err
}

func destroyCurrentServer(sclient *hcloud.ServerClient, UniqueID string) {
func destroyCurrentServer(client *hcloud.Client, UniqueID string) {
serverName := helpers.ServerNameFromSHA256(UniqueID)
fmt.Println("Destroying ", serverName)

helpers.TryDeleteServer(sclient, serverName, 20, 5)
helpers.TryDeleteServer(client, serverName, 20, 5)
}

func statusServer(state *statusT) {
Expand Down
9 changes: 8 additions & 1 deletion internal/cmd/clean/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewCommand() *cli.Command {
}

fmt.Println("Destroying all HAM Dead Servers.")
err = helpers.DestroyAllDeadServers(&client.Server)
err = helpers.DestroyAllDeadServers(client)
if err != nil {
return err
}
Expand Down Expand Up @@ -86,6 +86,7 @@ func destroyHamServers(client *hcloud.Client) error {
continue
}

serverName := server.Name
fmt.Printf("Destroying... %s\n", server.Name)
result, _, err := client.Server.DeleteWithResult(
context.Background(),
Expand All @@ -102,6 +103,12 @@ func destroyHamServers(client *hcloud.Client) error {
if !ok {
return errors.New(errMsg)
}

// Delete Volumes too
err = helpers.DeleteVolume(&client.Volume, serverName)
if err != nil {
return err
}
}

return nil
Expand Down
52 changes: 42 additions & 10 deletions internal/cmd/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ Local Recipe:
// whenver we see them.
// This is highly unlikely that our ham leaves dead servers
// but this is just a precaution.
err = helpers.DestroyAllDeadServers(&client.Server)
err = helpers.DestroyAllDeadServers(client)
if err != nil {
return err
}
Expand Down Expand Up @@ -340,7 +340,7 @@ Local Recipe:

// This is a safety net.
destroyServer := !argv.KeepServer
defer deferDeleteServer(&client.Server, &destroyServer, serverName)
defer deferDeleteServer(client, &destroyServer, serverName)

// Hmm... My ISP and mostly a lot of dumb ISP's don't support IPv6
// and tunnel is a waste of time. Also IPv4 cost a little extra on
Expand Down Expand Up @@ -408,7 +408,8 @@ Local Recipe:
fmt.Printf(" %s Created Server\n", checkMark)
}

err = doInitialize(ipAddr, config.SSHPrivateKey, varsFilePath, fileUploads, usedGit, gitUrl, gitBranch, dir, argv.TestingBinary)
volDevice := currentBuildServer.Volumes[0].LinuxDevice
err = doInitialize(ipAddr, config.SSHPrivateKey, volDevice, varsFilePath, fileUploads, usedGit, gitUrl, gitBranch, dir, argv.TestingBinary)
if err != nil {
return err
}
Expand Down Expand Up @@ -510,7 +511,12 @@ Local Recipe:
tries = 0
defer os.Remove(varsFilePath)

err = doInitialize(ipAddr, config.SSHPrivateKey, varsFilePath, fileUploads, usedGit, gitUrl, gitBranch, dir, argv.TestingBinary)
volDevice := ""
if currentBuildServer != nil {
volDevice = currentBuildServer.Volumes[0].LinuxDevice
}

err = doInitialize(ipAddr, config.SSHPrivateKey, volDevice, varsFilePath, fileUploads, usedGit, gitUrl, gitBranch, dir, argv.TestingBinary)
if err != nil {
return err
}
Expand Down Expand Up @@ -556,7 +562,7 @@ Local Recipe:
"Cannot Get SSH Client (" + err.Error() + "), But Server is Kept and Still Running.")
}

delErr := helpers.TryDeleteServer(&client.Server, serverName, 20, 5)
delErr := helpers.TryDeleteServer(client, serverName, 20, 5)
if delErr != nil {
banner.GetConnectFailBanner(serverName)
return delErr
Expand All @@ -581,7 +587,7 @@ Local Recipe:
return errors.New("Malformed JSON from Build Server, But Server is Kept and Still Running.")
}

delErr := helpers.TryDeleteServer(&client.Server, serverName, 20, 5)
delErr := helpers.TryDeleteServer(client, serverName, 20, 5)
if delErr != nil {
banner.GetMalformedJSONBanner(serverName)
return delErr
Expand All @@ -596,7 +602,7 @@ Local Recipe:
return errors.New("Remote Build Failed, But Server is Kept and Still Running.")
}

delErr := helpers.TryDeleteServer(&client.Server, serverName, 20, 5)
delErr := helpers.TryDeleteServer(client, serverName, 20, 5)
if delErr != nil {
banner.GetBuildFailedBanner(serverName)
return delErr
Expand All @@ -607,7 +613,7 @@ Local Recipe:
} else {
tries++
if tries >= 3 {
delErr := helpers.TryDeleteServer(&client.Server, serverName, 20, 5)
delErr := helpers.TryDeleteServer(client, serverName, 20, 5)
if delErr != nil {
return delErr
}
Expand Down Expand Up @@ -678,14 +684,15 @@ Local Recipe:
// it can try to delete any created server. The state is checked if
// we have to delete the server since it may not be desired by the
// user.
func deferDeleteServer(sclient *hcloud.ServerClient, destroy *bool, serverName string) {
func deferDeleteServer(client *hcloud.Client, destroy *bool, serverName string) {
if destroy != nil && *destroy {
helpers.TryDeleteServer(sclient, serverName, 5, 5)
helpers.TryDeleteServer(client, serverName, 5, 5)
}
}

func doInitialize(ipAddr string,
privateKey string,
volumeLinuxDevice string,
varsFilePath string,
fileUploads map[string]string,
usedGit bool,
Expand Down Expand Up @@ -927,6 +934,31 @@ func doInitialize(ipAddr string,

_ = spinnerMsg.StopMessage()

if volumeLinuxDevice != "" {
spinnerMsg.ShowMessage("Mounting Volume... ")

mountStatus, err := tryExec("mountpoint /ham-build")
if err != nil {
return err
}

if strings.Contains(mountStatus, "not a mountpoint") {
_, err = tryExec(fmt.Sprintf("mkfs.ext4 %s", volumeLinuxDevice))
if err != nil {
return err
}

_, err = tryExec(fmt.Sprintf("mount -o discard,defaults %s /ham-build", volumeLinuxDevice))

if err != nil {
return err
}

}

_ = spinnerMsg.StopMessage()
}

_, err = tryExec("echo 'finished' > /tmp/ham.init.finished")
if err != nil {
return err
Expand Down
83 changes: 39 additions & 44 deletions internal/cmd/get/server_pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
)

func GrossServerPriceForServerWithHighestPerformance(client *hcloud.Client) (float64, *hcloud.ServerType, error) {
// CPX51
// vCPU: 16
// CCX33
// vCPU: 8
// Memory: 32 GB
// Disk: 360 GB
return GrossServerPriceForServerType(client, "cpx51" /*"cx11"*/)
// Disk: 240 GB
// Additional Volume: 400 GB for Lineage Build
return GrossServerPriceForServerType(client, "ccx33" /*"cpx51"*/)
}

func GrossServerPriceForServerType(client *hcloud.Client, serverType string) (float64, *hcloud.ServerType, error) {
Expand All @@ -34,51 +35,45 @@ func GrossServerPriceForServerType(client *hcloud.Client, serverType string) (fl
}

for _, server := range pricing.ServerTypes {
// CCX are Dedicated Servers which cost a lot
// of money, it's just better avoid them, maybe
// in the future we might have an option to use it
// for rich users xD.
if !strings.HasPrefix(strings.ToLower(server.ServerType.Name), "ccx") {
// fmt.Printf("Server Name: %s\n", server.ServerType.Name)
// fmt.Printf("Server Cores: %d\n", server.ServerType.Cores)
// fmt.Printf("Server Memory: %f\n", server.ServerType.Memory)
// fmt.Printf("Server Disk: %d\n", server.ServerType.Disk)
// fmt.Printf("Server Name: %s\n", server.ServerType.Name)
// fmt.Printf("Server Cores: %d\n", server.ServerType.Cores)
// fmt.Printf("Server Memory: %f\n", server.ServerType.Memory)
// fmt.Printf("Server Disk: %d\n", server.ServerType.Disk)

var hourlyPrice hcloud.Price
priceAvail := false
// fmt.Printf("Locations: ")
for _, entry := range server.Pricings {
// fmt.Printf("%s ", entry.Location.Name)
if strings.ToLower(entry.Location.Name) == TargetLocation {
hourlyPrice = entry.Hourly
priceAvail = true
break
}
var hourlyPrice hcloud.Price
priceAvail := false
// fmt.Printf("Locations: ")
for _, entry := range server.Pricings {
// fmt.Printf("%s ", entry.Location.Name)
if strings.ToLower(entry.Location.Name) == TargetLocation {
hourlyPrice = entry.Hourly
priceAvail = true
break
}
// fmt.Printf("\n\n")
}
// fmt.Printf("\n\n")

if !priceAvail {
continue
}
if !priceAvail {
continue
}

amount, err := strconv.ParseFloat(hourlyPrice.Gross, 64)
if err != nil {
return 0.0, nil, errors.New("Invalid Price Given")
}
amount, err := strconv.ParseFloat(hourlyPrice.Gross, 64)
if err != nil {
return 0.0, nil, errors.New("Invalid Price Given")
}

if len(serverType) != 0 {
if server.ServerType.Name == serverType {
return amount, server.ServerType, nil
}
} else {
// For Some Reason, These all returns Zero
// Maybe bug in the upstream library?
// TODO: Look into this.
if server.ServerType.Cores >= 16 &&
server.ServerType.Memory >= 32.0 &&
server.ServerType.Disk >= 320 {
return amount, server.ServerType, nil
}
if len(serverType) != 0 {
if server.ServerType.Name == serverType {
return amount, server.ServerType, nil
}
} else {
// For Some Reason, These all returns Zero
// Maybe bug in the upstream library?
// TODO: Look into this.
if server.ServerType.Cores >= 8 &&
server.ServerType.Memory >= 32.0 &&
server.ServerType.Disk >= 240 {
return amount, server.ServerType, nil
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/get/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package get

import (
"fmt"
"io"
"strings"
"time"
"io"

"golang.org/x/crypto/ssh"
)
Expand Down
Loading

0 comments on commit fcb3bc2

Please sign in to comment.