Skip to content

Commit

Permalink
Merge branch 'develop' into more-system-info
Browse files Browse the repository at this point in the history
  • Loading branch information
chredeur authored Jan 18, 2025
2 parents ecedbd8 + c6c235d commit 1de2e93
Show file tree
Hide file tree
Showing 21 changed files with 295 additions and 249 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-22.04]
go: ["1.22.6", "1.23.0"]
go: ["1.22.10", "1.23.4"]
goos: [linux]
goarch: [amd64, arm64]

Expand Down Expand Up @@ -64,14 +64,14 @@ jobs:
- name: Upload Release Artifact
uses: actions/upload-artifact@v4
if: ${{ (github.ref == 'refs/heads/develop' || github.event_name == 'pull_request') && matrix.go == '1.22.6' }}
if: ${{ (github.ref == 'refs/heads/develop' || github.event_name == 'pull_request') && matrix.go == '1.22.10' }}
with:
name: wings_linux_${{ matrix.goarch }}
path: dist/wings

- name: Upload Debug Artifact
uses: actions/upload-artifact@v4
if: ${{ (github.ref == 'refs/heads/develop' || github.event_name == 'pull_request') && matrix.go == '1.22.6' }}
if: ${{ (github.ref == 'refs/heads/develop' || github.event_name == 'pull_request') && matrix.go == '1.22.10' }}
with:
name: wings_linux_${{ matrix.goarch }}_debug
path: dist/wings_debug
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.22.6"
go-version: "1.22.10"

- name: Build release binaries
env:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage 1 (Build)
FROM golang:1.22.6-alpine AS builder
FROM golang:1.22.10-alpine AS builder

ARG VERSION
RUN apk add --update --no-cache git make mailcap
Expand Down
9 changes: 5 additions & 4 deletions cmd/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/AlecAivazis/survey/v2/terminal"
"github.com/apex/log"
"github.com/docker/docker/api/types"
dockersystem "github.com/docker/docker/api/types/system"
"github.com/docker/docker/pkg/parsers/kernel"
"github.com/docker/docker/pkg/parsers/operatingsystem"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -206,18 +207,18 @@ func diagnosticsCmdRun(*cobra.Command, []string) {
}
}

func getDockerInfo() (types.Version, types.Info, error) {
func getDockerInfo() (types.Version, dockersystem.Info, error) {
client, err := environment.Docker()
if err != nil {
return types.Version{}, types.Info{}, err
return types.Version{}, dockersystem.Info{}, err
}
dockerVersion, err := client.ServerVersion(context.Background())
if err != nil {
return types.Version{}, types.Info{}, err
return types.Version{}, dockersystem.Info{}, err
}
dockerInfo, err := client.Info(context.Background())
if err != nil {
return types.Version{}, types.Info{}, err
return types.Version{}, dockersystem.Info{}, err
}
return dockerVersion, dockerInfo, nil
}
Expand Down
8 changes: 4 additions & 4 deletions environment/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"emperror.dev/errors"
"github.com/apex/log"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"

Expand Down Expand Up @@ -39,7 +38,7 @@ func ConfigureDocker(ctx context.Context) error {
}

nw := config.Get().Docker.Network
resource, err := cli.NetworkInspect(ctx, nw.Name, types.NetworkInspectOptions{})
resource, err := cli.NetworkInspect(ctx, nw.Name, network.InspectOptions{})
if err != nil {
if !client.IsErrNotFound(err) {
return err
Expand Down Expand Up @@ -72,9 +71,10 @@ func ConfigureDocker(ctx context.Context) error {
// Creates a new network on the machine if one does not exist already.
func createDockerNetwork(ctx context.Context, cli *client.Client) error {
nw := config.Get().Docker.Network
_, err := cli.NetworkCreate(ctx, nw.Name, types.NetworkCreate{
enableIPv6 := true
_, err := cli.NetworkCreate(ctx, nw.Name, network.CreateOptions{
Driver: nw.Driver,
EnableIPv6: true,
EnableIPv6: &enableIPv6,
Internal: nw.IsInternal,
IPAM: &network.IPAM{
Config: []network.IPAMConfig{{
Expand Down
47 changes: 24 additions & 23 deletions environment/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
"emperror.dev/errors"
"github.com/apex/log"
"github.com/buger/jsonparser"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"

"github.com/pterodactyl/wings/config"
Expand Down Expand Up @@ -199,14 +200,15 @@ func (e *Environment) Create() error {
networkName := "ip-" + strings.ReplaceAll(strings.ReplaceAll(a.DefaultMapping.Ip, ".", "-"), ":", "-")
networkMode = container.NetworkMode(networkName)

if _, err := e.client.NetworkInspect(ctx, networkName, types.NetworkInspectOptions{}); err != nil {
if _, err := e.client.NetworkInspect(ctx, networkName, network.InspectOptions{}); err != nil {
if !client.IsErrNotFound(err) {
return err
}

if _, err := e.client.NetworkCreate(ctx, networkName, types.NetworkCreate{
enableIPv6 := false
if _, err := e.client.NetworkCreate(ctx, networkName, network.CreateOptions{
Driver: "bridge",
EnableIPv6: false,
EnableIPv6: &enableIPv6,
Internal: false,
Attachable: false,
Ingress: false,
Expand Down Expand Up @@ -343,12 +345,12 @@ func (e *Environment) Readlog(lines int) ([]string, error) {
// late, and we don't need to block all the servers from booting just because
// of that. I'd imagine in a lot of cases an outage shouldn't affect users too
// badly. It'll at least keep existing servers working correctly if anything.
func (e *Environment) ensureImageExists(image string) error {
func (e *Environment) ensureImageExists(img string) error {
e.Events().Publish(environment.DockerImagePullStarted, "")
defer e.Events().Publish(environment.DockerImagePullCompleted, "")

// Images prefixed with a ~ are local images that we do not need to try and pull.
if strings.HasPrefix(image, "~") {
if strings.HasPrefix(img, "~") {
return nil
}

Expand All @@ -361,7 +363,7 @@ func (e *Environment) ensureImageExists(image string) error {
// Get a registry auth configuration from the config.
var registryAuth *config.RegistryConfiguration
for registry, c := range config.Get().Docker.Registries {
if !strings.HasPrefix(image, registry) {
if !strings.HasPrefix(img, registry) {
continue
}

Expand All @@ -371,7 +373,7 @@ func (e *Environment) ensureImageExists(image string) error {
}

// Get the ImagePullOptions.
imagePullOptions := types.ImagePullOptions{All: false}
imagePullOptions := image.PullOptions{All: false}
if registryAuth != nil {
b64, err := registryAuth.Base64()
if err != nil {
Expand All @@ -382,23 +384,23 @@ func (e *Environment) ensureImageExists(image string) error {
imagePullOptions.RegistryAuth = b64
}

out, err := e.client.ImagePull(ctx, image, imagePullOptions)
out, err := e.client.ImagePull(ctx, img, imagePullOptions)
if err != nil {
images, ierr := e.client.ImageList(ctx, types.ImageListOptions{})
images, ierr := e.client.ImageList(ctx, image.ListOptions{})
if ierr != nil {
// Well damn, something has gone really wrong here, just go ahead and abort there
// isn't much anything we can do to try and self-recover from this.
return errors.Wrap(ierr, "environment/docker: failed to list images")
}

for _, img := range images {
for _, t := range img.RepoTags {
if t != image {
for _, img2 := range images {
for _, t := range img2.RepoTags {
if t != img {
continue
}

log.WithFields(log.Fields{
"image": image,
"image": img,
"container_id": e.Id,
"err": err.Error(),
}).Warn("unable to pull requested image from remote source, however the image exists locally")
Expand All @@ -409,11 +411,11 @@ func (e *Environment) ensureImageExists(image string) error {
}
}

return errors.Wrapf(err, "environment/docker: failed to pull \"%s\" image for server", image)
return errors.Wrapf(err, "environment/docker: failed to pull \"%s\" image for server", img)
}
defer out.Close()

log.WithField("image", image).Debug("pulling docker image... this could take a bit of time")
log.WithField("image", img).Debug("pulling docker image... this could take a bit of time")

// I'm not sure what the best approach here is, but this will block execution until the image
// is done being pulled, which is what we need.
Expand All @@ -431,22 +433,21 @@ func (e *Environment) ensureImageExists(image string) error {
return err
}

log.WithField("image", image).Debug("completed docker image pull")
log.WithField("image", img).Debug("completed docker image pull")

return nil
}

func (e *Environment) convertMounts() []mount.Mount {
var out []mount.Mount

for _, m := range e.Configuration.Mounts() {
out = append(out, mount.Mount{
mounts := e.Configuration.Mounts()
out := make([]mount.Mount, len(mounts))
for i, m := range mounts {
out[i] = mount.Mount{
Type: mount.TypeBind,
Source: m.Source,
Target: m.Target,
ReadOnly: m.ReadOnly,
})
}
}

return out
}
10 changes: 5 additions & 5 deletions environment/docker/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"emperror.dev/errors"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"

"github.com/pterodactyl/wings/environment"
)
Expand Down Expand Up @@ -57,7 +57,7 @@ func (e *Environment) pollResources(ctx context.Context) error {
case <-ctx.Done():
return ctx.Err()
default:
var v types.StatsJSON
var v container.StatsResponse
if err := dec.Decode(&v); err != nil {
if err != io.EOF && !errors.Is(err, context.Canceled) {
e.log().WithField("error", err).Warn("error while processing Docker stats output for container")
Expand Down Expand Up @@ -95,15 +95,15 @@ func (e *Environment) pollResources(ctx context.Context) error {
}
}

// The "docker stats" CLI call does not return the same value as the types.MemoryStats.Usage
// The "docker stats" CLI call does not return the same value as the [container.MemoryStats].Usage
// value which can be rather confusing to people trying to compare panel usage to
// their stats output.
//
// This math is from their CLI repository in order to show the same values to avoid people
// bothering me about it. It should also reflect a slightly more correct memory value anyways.
//
// @see https://github.com/docker/cli/blob/96e1d1d6/cli/command/container/stats_helpers.go#L227-L249
func calculateDockerMemory(stats types.MemoryStats) uint64 {
func calculateDockerMemory(stats container.MemoryStats) uint64 {
if v, ok := stats.Stats["total_inactive_file"]; ok && v < stats.Usage {
return stats.Usage - v
}
Expand All @@ -119,7 +119,7 @@ func calculateDockerMemory(stats types.MemoryStats) uint64 {
// by the defined CPU limits on the container.
//
// @see https://github.com/docker/cli/blob/aa097cf1aa19099da70930460250797c8920b709/cli/command/container/stats_helpers.go#L166
func calculateDockerAbsoluteCpu(pStats types.CPUStats, stats types.CPUStats) float64 {
func calculateDockerAbsoluteCpu(pStats container.CPUStats, stats container.CPUStats) float64 {
// Calculate the change in CPU usage between the current and previous reading.
cpuDelta := float64(stats.CPUUsage.TotalUsage) - float64(pStats.CPUUsage.TotalUsage)

Expand Down
26 changes: 13 additions & 13 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

outputs = {...} @ inputs:
inputs.flake-parts.lib.mkFlake {inherit inputs;} {
systems = ["aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux"];
systems = inputs.nixpkgs.lib.systems.flakeExposed;

imports = [
inputs.treefmt-nix.flakeModule
Expand All @@ -27,7 +27,7 @@
go_1_22
gofumpt
golangci-lint
gotools
gotools
];
};

Expand Down
Loading

0 comments on commit 1de2e93

Please sign in to comment.