db

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2026 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package db provides a simple JSON file-backed database.

Index

Constants

View Source
const CurrentDataVersion = 5

Variables

This section is empty.

Functions

This section is empty.

Types

type Artifact

type Artifact struct {
	Refs map[ArtifactRef]string // path on disk
}

func (*Artifact) Clone

func (src *Artifact) Clone() *Artifact

Clone makes a deep copy of Artifact. The result aliases no memory with the original.

func (*Artifact) View

func (p *Artifact) View() ArtifactView

View returns a read-only view of Artifact.

type ArtifactName

type ArtifactName string
const (
	ArtifactBinary  ArtifactName = "binary"
	ArtifactEnvFile ArtifactName = "env"

	ArtifactDockerComposeFile    ArtifactName = "compose.yml"
	ArtifactDockerComposeNetwork ArtifactName = "compose.network"
	ArtifactTypeScriptFile       ArtifactName = "main.ts"
	ArtifactPythonFile           ArtifactName = "main.py"
	ArtifactSystemdUnit          ArtifactName = "systemd.service"
	ArtifactSystemdTimerFile     ArtifactName = "systemd.timer"

	ArtifactNetNSService ArtifactName = "netns.service"
	ArtifactNetNSEnv     ArtifactName = "netns.env"
	ArtifactTSService    ArtifactName = "tailscale.service"
	ArtifactTSEnv        ArtifactName = "tailscale.env"
	ArtifactTSBinary     ArtifactName = "tailscaled"
	ArtifactTSConfig     ArtifactName = "tailscaled.json"
	ArtifactNetNSResolv  ArtifactName = "resolv.conf"
)

type ArtifactRef

type ArtifactRef string

ArtifactRef is a reference to an artifact.

It's either "latest", "staged", or a generation number like "gen-23".

func Gen

func Gen(gen int) ArtifactRef

type ArtifactStore

type ArtifactStore map[ArtifactName]*Artifact

func (ArtifactStore) Gen

func (as ArtifactStore) Gen(name ArtifactName, gen int) (string, bool)

func (ArtifactStore) Latest

func (as ArtifactStore) Latest(name ArtifactName) (string, bool)

func (ArtifactStore) Staged

func (as ArtifactStore) Staged(name ArtifactName) (string, bool)

type ArtifactView

type ArtifactView struct {
	// contains filtered or unexported fields
}

ArtifactView provides a read-only view over Artifact.

Its methods should only be called if `Valid()` returns true.

func (ArtifactView) AsStruct

func (v ArtifactView) AsStruct() *Artifact

AsStruct returns a clone of the underlying value which aliases no memory with the original.

func (ArtifactView) MarshalJSON

func (v ArtifactView) MarshalJSON() ([]byte, error)

func (ArtifactView) Refs

func (*ArtifactView) UnmarshalJSON

func (v *ArtifactView) UnmarshalJSON(b []byte) error

func (ArtifactView) Valid

func (v ArtifactView) Valid() bool

Valid reports whether v's underlying value is non-nil.

type Data

type Data struct {
	// DataVersion is the version of the data format. This is used to determine
	// how to parse the data.
	DataVersion int `json:",omitempty"`

	Services map[string]*Service

	Images map[ImageRepoName]*ImageRepo

	Volumes map[string]*Volume

	DockerNetworks map[string]*DockerNetwork
}

Data is the full JSON structure of the database.

func (*Data) Clone

func (src *Data) Clone() *Data

Clone makes a deep copy of Data. The result aliases no memory with the original.

func (*Data) View

func (p *Data) View() DataView

View returns a read-only view of Data.

type DataView

type DataView struct {
	// contains filtered or unexported fields
}

DataView provides a read-only view over Data.

Its methods should only be called if `Valid()` returns true.

func (DataView) AsStruct

func (v DataView) AsStruct() *Data

AsStruct returns a clone of the underlying value which aliases no memory with the original.

func (DataView) DataVersion

func (v DataView) DataVersion() int

func (DataView) DockerNetworks

func (v DataView) DockerNetworks() views.MapFn[string, *DockerNetwork, DockerNetworkView]

func (DataView) Images

func (DataView) MarshalJSON

func (v DataView) MarshalJSON() ([]byte, error)

func (DataView) Services

func (v DataView) Services() views.MapFn[string, *Service, ServiceView]

func (*DataView) UnmarshalJSON

func (v *DataView) UnmarshalJSON(b []byte) error

func (DataView) Valid

func (v DataView) Valid() bool

Valid reports whether v's underlying value is non-nil.

func (DataView) Volumes

func (v DataView) Volumes() views.MapFn[string, *Volume, VolumeView]

type DockerEndpoint

type DockerEndpoint struct {
	EndpointID string
	IPv4       netip.Prefix
}

func (*DockerEndpoint) Clone

func (src *DockerEndpoint) Clone() *DockerEndpoint

Clone makes a deep copy of DockerEndpoint. The result aliases no memory with the original.

func (*DockerEndpoint) View

View returns a read-only view of DockerEndpoint.

type DockerEndpointView

type DockerEndpointView struct {
	// contains filtered or unexported fields
}

DockerEndpointView provides a read-only view over DockerEndpoint.

Its methods should only be called if `Valid()` returns true.

func (DockerEndpointView) AsStruct

func (v DockerEndpointView) AsStruct() *DockerEndpoint

AsStruct returns a clone of the underlying value which aliases no memory with the original.

func (DockerEndpointView) EndpointID

func (v DockerEndpointView) EndpointID() string

func (DockerEndpointView) IPv4

func (v DockerEndpointView) IPv4() netip.Prefix

func (DockerEndpointView) MarshalJSON

func (v DockerEndpointView) MarshalJSON() ([]byte, error)

func (*DockerEndpointView) UnmarshalJSON

func (v *DockerEndpointView) UnmarshalJSON(b []byte) error

func (DockerEndpointView) Valid

func (v DockerEndpointView) Valid() bool

Valid reports whether v's underlying value is non-nil.

type DockerNetwork

type DockerNetwork struct {
	NetworkID string
	NetNS     string

	IPv4Gateway netip.Prefix
	IPv4Range   netip.Prefix

	Endpoints map[string]*DockerEndpoint

	// Deprecated: use Endpoints instead.
	EndpointAddrs map[string]netip.Prefix

	PortMap map[string]*EndpointPort // key is "proto/hostport"
}

func (*DockerNetwork) Clone

func (src *DockerNetwork) Clone() *DockerNetwork

Clone makes a deep copy of DockerNetwork. The result aliases no memory with the original.

func (*DockerNetwork) View

func (p *DockerNetwork) View() DockerNetworkView

View returns a read-only view of DockerNetwork.

type DockerNetworkView

type DockerNetworkView struct {
	// contains filtered or unexported fields
}

DockerNetworkView provides a read-only view over DockerNetwork.

Its methods should only be called if `Valid()` returns true.

func (DockerNetworkView) AsStruct

func (v DockerNetworkView) AsStruct() *DockerNetwork

AsStruct returns a clone of the underlying value which aliases no memory with the original.

func (DockerNetworkView) EndpointAddrs

func (v DockerNetworkView) EndpointAddrs() views.Map[string, netip.Prefix]

func (DockerNetworkView) Endpoints

func (DockerNetworkView) IPv4Gateway

func (v DockerNetworkView) IPv4Gateway() netip.Prefix

func (DockerNetworkView) IPv4Range

func (v DockerNetworkView) IPv4Range() netip.Prefix

func (DockerNetworkView) MarshalJSON

func (v DockerNetworkView) MarshalJSON() ([]byte, error)

func (DockerNetworkView) NetNS

func (v DockerNetworkView) NetNS() string

func (DockerNetworkView) NetworkID

func (v DockerNetworkView) NetworkID() string

func (DockerNetworkView) PortMap

func (*DockerNetworkView) UnmarshalJSON

func (v *DockerNetworkView) UnmarshalJSON(b []byte) error

func (DockerNetworkView) Valid

func (v DockerNetworkView) Valid() bool

Valid reports whether v's underlying value is non-nil.

type EndpointPort

type EndpointPort struct {
	EndpointID string
	Port       uint16
}

func (*EndpointPort) Clone

func (src *EndpointPort) Clone() *EndpointPort

Clone makes a deep copy of EndpointPort. The result aliases no memory with the original.

func (*EndpointPort) View

func (p *EndpointPort) View() EndpointPortView

View returns a read-only view of EndpointPort.

type EndpointPortView

type EndpointPortView struct {
	// contains filtered or unexported fields
}

EndpointPortView provides a read-only view over EndpointPort.

Its methods should only be called if `Valid()` returns true.

func (EndpointPortView) AsStruct

func (v EndpointPortView) AsStruct() *EndpointPort

AsStruct returns a clone of the underlying value which aliases no memory with the original.

func (EndpointPortView) EndpointID

func (v EndpointPortView) EndpointID() string

func (EndpointPortView) MarshalJSON

func (v EndpointPortView) MarshalJSON() ([]byte, error)

func (EndpointPortView) Port

func (v EndpointPortView) Port() uint16

func (*EndpointPortView) UnmarshalJSON

func (v *EndpointPortView) UnmarshalJSON(b []byte) error

func (EndpointPortView) Valid

func (v EndpointPortView) Valid() bool

Valid reports whether v's underlying value is non-nil.

type ImageManifest

type ImageManifest struct {
	ContentType string
	BlobHash    string
}

type ImageRef

type ImageRef string

Tag or digest.

type ImageRepo

type ImageRepo struct {
	Refs map[ImageRef]ImageManifest `json:",omitempty"`
}

func (*ImageRepo) Clone

func (src *ImageRepo) Clone() *ImageRepo

Clone makes a deep copy of ImageRepo. The result aliases no memory with the original.

func (*ImageRepo) View

func (p *ImageRepo) View() ImageRepoView

View returns a read-only view of ImageRepo.

type ImageRepoName

type ImageRepoName string

type ImageRepoView

type ImageRepoView struct {
	// contains filtered or unexported fields
}

ImageRepoView provides a read-only view over ImageRepo.

Its methods should only be called if `Valid()` returns true.

func (ImageRepoView) AsStruct

func (v ImageRepoView) AsStruct() *ImageRepo

AsStruct returns a clone of the underlying value which aliases no memory with the original.

func (ImageRepoView) MarshalJSON

func (v ImageRepoView) MarshalJSON() ([]byte, error)

func (ImageRepoView) Refs

func (*ImageRepoView) UnmarshalJSON

func (v *ImageRepoView) UnmarshalJSON(b []byte) error

func (ImageRepoView) Valid

func (v ImageRepoView) Valid() bool

Valid reports whether v's underlying value is non-nil.

type MacvlanNetwork

type MacvlanNetwork struct {
	Interface string
	Mac       string
	Parent    string
	VLAN      int
}

type ProtoPort

type ProtoPort struct {
	Proto int
	Port  uint16
}

func (*ProtoPort) Parse

func (p *ProtoPort) Parse(data string) error

func (ProtoPort) String

func (p ProtoPort) String() string

type Service

type Service struct {
	// Name is the name of the service.
	Name string

	ServiceType ServiceType

	// Generation is the current generation of the service.
	Generation int `json:",omitempty"`

	// LatestGeneration is the latest generation of the service.
	LatestGeneration int `json:",omitempty"`

	// Artifacts are the artifacts generated for this service.
	Artifacts ArtifactStore

	SvcNetwork *SvcNetwork
	Macvlan    *MacvlanNetwork
	TSNet      *TailscaleNetwork
}

Service is the configuration for one service.

func (*Service) Clone

func (src *Service) Clone() *Service

Clone makes a deep copy of Service. The result aliases no memory with the original.

func (*Service) View

func (p *Service) View() ServiceView

View returns a read-only view of Service.

type ServiceType

type ServiceType string
const (
	ServiceTypeDockerCompose ServiceType = "docker-compose"
	ServiceTypeSystemd       ServiceType = "systemd"
)

type ServiceView

type ServiceView struct {
	// contains filtered or unexported fields
}

ServiceView provides a read-only view over Service.

Its methods should only be called if `Valid()` returns true.

func (ServiceView) Artifacts

func (ServiceView) AsStruct

func (v ServiceView) AsStruct() *Service

AsStruct returns a clone of the underlying value which aliases no memory with the original.

func (ServiceView) Generation

func (v ServiceView) Generation() int

func (ServiceView) LatestGeneration

func (v ServiceView) LatestGeneration() int

func (ServiceView) Macvlan

func (ServiceView) MarshalJSON

func (v ServiceView) MarshalJSON() ([]byte, error)

func (ServiceView) Name

func (v ServiceView) Name() string

func (ServiceView) ServiceType

func (v ServiceView) ServiceType() ServiceType

func (ServiceView) SvcNetwork

func (v ServiceView) SvcNetwork() views.ValuePointer[SvcNetwork]

func (ServiceView) TSNet

func (*ServiceView) UnmarshalJSON

func (v *ServiceView) UnmarshalJSON(b []byte) error

func (ServiceView) Valid

func (v ServiceView) Valid() bool

Valid reports whether v's underlying value is non-nil.

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore(file, serviceRoot string) *Store

NewStore returns a new Store with the given file.

func (*Store) Get

func (s *Store) Get() (DataView, error)

Get returns a DataView of s.d. If s.d is nil, it reads s.file into s.d.

func (*Store) MutateData

func (s *Store) MutateData(f func(*Data) error) (*Data, error)

func (*Store) MutateService

func (s *Store) MutateService(name string, f func(*Data, *Service) error) (*Data, *Service, error)

func (*Store) Set

func (s *Store) Set(d *Data) error

Set sets s.d to a clone of d.

type SvcNetwork

type SvcNetwork struct {
	IPv4 netip.Addr
}

type TailscaleNetwork

type TailscaleNetwork struct {
	Interface string
	Version   string
	ExitNode  string `json:",omitempty"`
	Tags      []string
	StableID  tailcfg.StableNodeID
}

func (*TailscaleNetwork) Clone

func (src *TailscaleNetwork) Clone() *TailscaleNetwork

Clone makes a deep copy of TailscaleNetwork. The result aliases no memory with the original.

func (*TailscaleNetwork) View

View returns a read-only view of TailscaleNetwork.

type TailscaleNetworkView

type TailscaleNetworkView struct {
	// contains filtered or unexported fields
}

TailscaleNetworkView provides a read-only view over TailscaleNetwork.

Its methods should only be called if `Valid()` returns true.

func (TailscaleNetworkView) AsStruct

func (v TailscaleNetworkView) AsStruct() *TailscaleNetwork

AsStruct returns a clone of the underlying value which aliases no memory with the original.

func (TailscaleNetworkView) ExitNode

func (v TailscaleNetworkView) ExitNode() string

func (TailscaleNetworkView) Interface

func (v TailscaleNetworkView) Interface() string

func (TailscaleNetworkView) MarshalJSON

func (v TailscaleNetworkView) MarshalJSON() ([]byte, error)

func (TailscaleNetworkView) StableID

func (TailscaleNetworkView) Tags

func (*TailscaleNetworkView) UnmarshalJSON

func (v *TailscaleNetworkView) UnmarshalJSON(b []byte) error

func (TailscaleNetworkView) Valid

func (v TailscaleNetworkView) Valid() bool

Valid reports whether v's underlying value is non-nil.

func (TailscaleNetworkView) Version

func (v TailscaleNetworkView) Version() string

type Volume

type Volume struct {
	Name string

	Src  string
	Path string
	Type string
	Opts string
	Deps string
}

func (*Volume) Clone

func (src *Volume) Clone() *Volume

Clone makes a deep copy of Volume. The result aliases no memory with the original.

func (*Volume) View

func (p *Volume) View() VolumeView

View returns a read-only view of Volume.

type VolumeView

type VolumeView struct {
	// contains filtered or unexported fields
}

VolumeView provides a read-only view over Volume.

Its methods should only be called if `Valid()` returns true.

func (VolumeView) AsStruct

func (v VolumeView) AsStruct() *Volume

AsStruct returns a clone of the underlying value which aliases no memory with the original.

func (VolumeView) Deps

func (v VolumeView) Deps() string

func (VolumeView) MarshalJSON

func (v VolumeView) MarshalJSON() ([]byte, error)

func (VolumeView) Name

func (v VolumeView) Name() string

func (VolumeView) Opts

func (v VolumeView) Opts() string

func (VolumeView) Path

func (v VolumeView) Path() string

func (VolumeView) Src

func (v VolumeView) Src() string

func (VolumeView) Type

func (v VolumeView) Type() string

func (*VolumeView) UnmarshalJSON

func (v *VolumeView) UnmarshalJSON(b []byte) error

func (VolumeView) Valid

func (v VolumeView) Valid() bool

Valid reports whether v's underlying value is non-nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL