Refactor environment handling logic to separate a server from the environment handler itself
This change makes the environment handling logic execute independent of the server itself and should make it much easier for people to contribute changes and additional environment handlers down the road without polluting the server object even more. There is still a lot of work to do on this front to make things easier to work with, and there are some questionable design decisions at play I'm sure. Welcome to additional modifications and cleanup to make this code easier to reason about and work with.
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/api"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
"github.com/pterodactyl/wings/server"
|
||||
"os"
|
||||
"path"
|
||||
@@ -33,7 +34,7 @@ func New(data []byte) (*Installer, error) {
|
||||
Uuid: getString(data, "uuid"),
|
||||
Suspended: false,
|
||||
Invocation: getString(data, "invocation"),
|
||||
Build: server.BuildSettings{
|
||||
Build: environment.Limits{
|
||||
MemoryLimit: getInt(data, "build", "memory"),
|
||||
Swap: getInt(data, "build", "swap"),
|
||||
IoWeight: uint16(getInt(data, "build", "io")),
|
||||
@@ -51,7 +52,7 @@ func New(data []byte) (*Installer, error) {
|
||||
if b, _, _, err := jsonparser.Get(data, "environment"); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
} else {
|
||||
cfg.EnvVars = make(server.EnvironmentVariables)
|
||||
cfg.EnvVars = make(environment.Variables)
|
||||
if err := json.Unmarshal(b, &cfg.EnvVars); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
@@ -116,6 +117,7 @@ func (i *Installer) Execute() {
|
||||
}
|
||||
|
||||
l.Debug("creating required environment for server instance")
|
||||
// TODO: ensure data directory exists.
|
||||
if err := i.server.Environment.Create(); err != nil {
|
||||
l.WithField("error", err).Error("failed to create environment for server")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user