This commit is contained in:
parent
e71d177984
commit
e695278d0c
@ -1,29 +1,27 @@
|
|||||||
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Container resource
|
// Container resource
|
||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
_ "os"
|
"github.com/docker/docker/api/types"
|
||||||
_ "gopkg.in/yaml.v3"
|
|
||||||
_ "os/exec"
|
|
||||||
_ "strings"
|
|
||||||
"log/slog"
|
|
||||||
"github.com/docker/docker/api/types/strslice"
|
|
||||||
"github.com/docker/docker/api/types/mount"
|
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types/mount"
|
||||||
"github.com/docker/docker/client"
|
|
||||||
"github.com/docker/docker/api/types/network"
|
"github.com/docker/docker/api/types/network"
|
||||||
|
"github.com/docker/docker/api/types/strslice"
|
||||||
|
"github.com/docker/docker/client"
|
||||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
_ "gopkg.in/yaml.v3"
|
||||||
|
"log/slog"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
_ "os"
|
||||||
|
_ "os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
_ "strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ContainerClient interface {
|
type ContainerClient interface {
|
||||||
@ -220,7 +218,6 @@ func (c *Container) Read(ctx context.Context) ([]byte, error) {
|
|||||||
return yaml.Marshal(c)
|
return yaml.Marshal(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (c *Container) Delete(ctx context.Context) error {
|
func (c *Container) Delete(ctx context.Context) error {
|
||||||
err := c.apiClient.ContainerRemove(ctx, c.Id, types.ContainerRemoveOptions{
|
err := c.apiClient.ContainerRemove(ctx, c.Id, types.ContainerRemoveOptions{
|
||||||
RemoveVolumes: true,
|
RemoveVolumes: true,
|
||||||
|
@ -1,25 +1,24 @@
|
|||||||
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
||||||
|
|
||||||
//
|
|
||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "fmt"
|
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
|
||||||
_ "net/http"
|
|
||||||
_ "net/http/httptest"
|
|
||||||
_ "net/url"
|
|
||||||
_ "io"
|
|
||||||
_ "os"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
_ "encoding/json"
|
|
||||||
_ "strings"
|
|
||||||
"decl/tests/mocks"
|
"decl/tests/mocks"
|
||||||
|
_ "encoding/json"
|
||||||
|
_ "fmt"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/network"
|
"github.com/docker/docker/api/types/network"
|
||||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
_ "io"
|
||||||
|
_ "net/http"
|
||||||
|
_ "net/http/httptest"
|
||||||
|
_ "net/url"
|
||||||
|
_ "os"
|
||||||
|
_ "strings"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewContainerResource(t *testing.T) {
|
func TestNewContainerResource(t *testing.T) {
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
||||||
|
|
||||||
//
|
|
||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
"log/slog"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Declaration struct {
|
type Declaration struct {
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
_ "log"
|
||||||
_ "os"
|
_ "os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"fmt"
|
|
||||||
_ "log"
|
|
||||||
"testing"
|
"testing"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestYamlLoadDecl(t *testing.T) {
|
func TestYamlLoadDecl(t *testing.T) {
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
||||||
|
|
||||||
//
|
|
||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "fmt"
|
_ "fmt"
|
||||||
_ "log"
|
|
||||||
"io"
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
"io"
|
||||||
|
_ "log"
|
||||||
_ "net/url"
|
_ "net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -22,7 +21,7 @@ func NewDocument() *Document {
|
|||||||
func (d *Document) Load(r io.Reader) error {
|
func (d *Document) Load(r io.Reader) error {
|
||||||
yamlDecoder := yaml.NewDecoder(r)
|
yamlDecoder := yaml.NewDecoder(r)
|
||||||
yamlDecoder.Decode(d)
|
yamlDecoder.Decode(d)
|
||||||
for i := range(d.ResourceDecls) {
|
for i := range d.ResourceDecls {
|
||||||
if _, e := d.ResourceDecls[i].LoadResourceFromYaml(); e != nil {
|
if _, e := d.ResourceDecls[i].LoadResourceFromYaml(); e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
@ -35,7 +34,7 @@ func (d *Document) Resources() []Declaration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Document) Apply() error {
|
func (d *Document) Apply() error {
|
||||||
for i := range(d.ResourceDecls) {
|
for i := range d.ResourceDecls {
|
||||||
if e := d.ResourceDecls[i].Resource().Apply(); e != nil {
|
if e := d.ResourceDecls[i].Resource().Apply(); e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
@ -43,7 +42,7 @@ func (d *Document) Apply() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Document) Generate(w io.Writer) (error) {
|
func (d *Document) Generate(w io.Writer) error {
|
||||||
yamlEncoder := yaml.NewEncoder(w)
|
yamlEncoder := yaml.NewEncoder(w)
|
||||||
yamlEncoder.Encode(d)
|
yamlEncoder.Encode(d)
|
||||||
return yamlEncoder.Close()
|
return yamlEncoder.Close()
|
||||||
|
@ -3,15 +3,15 @@ package resource
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strings"
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"time"
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewDocumentLoader(t *testing.T) {
|
func TestNewDocumentLoader(t *testing.T) {
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
||||||
|
|
||||||
//
|
|
||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
_ "os"
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
_ "os/exec"
|
|
||||||
_ "strings"
|
|
||||||
_ "log"
|
_ "log"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
_ "os"
|
||||||
|
_ "os/exec"
|
||||||
|
_ "strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Exec struct {
|
type Exec struct {
|
||||||
@ -62,4 +61,3 @@ func (x *Exec) Type() string { return "exec" }
|
|||||||
func (x *Exec) Read(ctx context.Context) ([]byte, error) {
|
func (x *Exec) Read(ctx context.Context) ([]byte, error) {
|
||||||
return yaml.Marshal(x)
|
return yaml.Marshal(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
||||||
|
|
||||||
//
|
|
||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
"io"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"io"
|
|
||||||
"syscall"
|
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
"strconv"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"net/url"
|
"strconv"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -83,7 +82,8 @@ func (f *File) Apply() error {
|
|||||||
if removeErr != nil {
|
if removeErr != nil {
|
||||||
return removeErr
|
return removeErr
|
||||||
}
|
}
|
||||||
case "present": {
|
case "present":
|
||||||
|
{
|
||||||
uid, uidErr := LookupUID(f.Owner)
|
uid, uidErr := LookupUID(f.Owner)
|
||||||
if uidErr != nil {
|
if uidErr != nil {
|
||||||
return uidErr
|
return uidErr
|
||||||
|
@ -15,9 +15,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
_ "strings"
|
_ "strings"
|
||||||
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
"syscall"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewFileResource(t *testing.T) {
|
func TestNewFileResource(t *testing.T) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
||||||
|
|
||||||
//
|
|
||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -2,16 +2,16 @@
|
|||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "fmt"
|
|
||||||
_ "context"
|
_ "context"
|
||||||
"testing"
|
_ "encoding/json"
|
||||||
|
_ "fmt"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
_ "io"
|
||||||
_ "net/http"
|
_ "net/http"
|
||||||
_ "net/http/httptest"
|
_ "net/http/httptest"
|
||||||
_ "net/url"
|
_ "net/url"
|
||||||
_ "io"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
_ "encoding/json"
|
|
||||||
_ "strings"
|
_ "strings"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLookupUID(t *testing.T) {
|
func TestLookupUID(t *testing.T) {
|
||||||
|
@ -42,7 +42,6 @@ type ResourceDeleter interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ResourceDecoder struct {
|
type ResourceDecoder struct {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewResource(uri string) Resource {
|
func NewResource(uri string) Resource {
|
||||||
|
@ -3,12 +3,12 @@ package resource
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
_ "fmt"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
_ "fmt"
|
|
||||||
"log"
|
|
||||||
"testing"
|
"testing"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var TempDir string
|
var TempDir string
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
||||||
|
|
||||||
//
|
|
||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -3,10 +3,10 @@ package resource
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
_ "context"
|
_ "context"
|
||||||
"testing"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"decl/tests/mocks"
|
"decl/tests/mocks"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewResourceTypes(t *testing.T) {
|
func TestNewResourceTypes(t *testing.T) {
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
||||||
|
|
||||||
//
|
|
||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
_ "os"
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
_ "os"
|
||||||
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
@ -153,4 +152,3 @@ func (u *User) Read(ctx context.Context) ([]byte, error) {
|
|||||||
|
|
||||||
return yaml.Marshal(u)
|
return yaml.Marshal(u)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,17 +2,17 @@
|
|||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "fmt"
|
|
||||||
_ "context"
|
_ "context"
|
||||||
"testing"
|
_ "encoding/json"
|
||||||
|
_ "fmt"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
_ "io"
|
||||||
_ "net/http"
|
_ "net/http"
|
||||||
_ "net/http/httptest"
|
_ "net/http/httptest"
|
||||||
_ "net/url"
|
_ "net/url"
|
||||||
_ "io"
|
|
||||||
_ "os"
|
_ "os"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
_ "encoding/json"
|
|
||||||
_ "strings"
|
_ "strings"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewUserResource(t *testing.T) {
|
func TestNewUserResource(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user