Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from weaveworks/platform-registry
Browse files Browse the repository at this point in the history
Stub out platform and registry objects
  • Loading branch information
peterbourgon authored Jul 7, 2016
2 parents e70d1f9 + 0e8a9db commit 2f4dffe
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
21 changes: 21 additions & 0 deletions platform/platform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Package platform provides domain abstractions over orchestration platforms.
package platform

// Platform describes a runtime platform, like Swarm.
type Platform interface {
Services() []Service
}

// Service describes a single service as understood by a platform. This is an
// interface rather than a struct, because we want to allow platforms to define
// their own Service structs with all of their specific implementation details.
type Service interface {
Name() string
Instances() []Instance
}

// Instance describes a single physical instance as understood by a platform.
// The same caveats re: interface apply as to the service.
type Instance interface {
ID() string
}
44 changes: 44 additions & 0 deletions platform/swarm/swarm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Package swarm provides Swarm-flavored platform objects.
package swarm

import "github.com/weaveworks/fluxy/platform"

// Platform represents a single Swarm cluster, as understood by a fluxd daemon
// deployed within it. That means something like a connection to the API server,
// so state may be queried.
type Platform struct{}

// Services implements platform.Platform.
func (p *Platform) Services() []platform.Service {
return []platform.Service{}
}

// Service represents a single Swarm service as yielded by a platform.
type Service struct {
name string
instances []Instance
}

// Name implements platform.Service.
func (s *Service) Name() string {
return s.name
}

// Instances implements platform.Service.
func (s *Service) Instances() []platform.Instance {
res := make([]platform.Instance, len(s.instances))
for i := range s.instances {
res[i] = &s.instances[i]
}
return res
}

// Instance represents a single container, or task, in a Swarm service.
type Instance struct {
id string
}

// ID implements platform.Instance.
func (i *Instance) ID() string {
return i.id
}
37 changes: 37 additions & 0 deletions registry/quay/quay.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Package quay provides Quay.io-flavored registry objects.
package quay

import (
"github.com/weaveworks/fluxy/registry"
)

// Registry represents a single Quay registry.
type Registry struct {
// Some Quay auth details stored here
}

// NewRegistry returns a new Quay-flavored Registry.
func NewRegistry(username, password string) *Registry {
return &Registry{}
}

// Repositories implements registry.Registry.
func (r *Registry) Repositories() []registry.Repository {
return []registry.Repository{}
}

// Repository represents a single Quay repository, yielded by a Quay Registry.
type Repository struct {
name string
images []registry.Image
}

// Name implements registry.Repository.
func (r *Repository) Name() string {
return r.name
}

// Images implements registry.Repository.
func (r *Repository) Images() []registry.Image {
return r.images
}
25 changes: 25 additions & 0 deletions registry/registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Package registry provides domain abstractions over container registries.
package registry

import "time"

// Registry represents a container registry from the perspective of a specific,
// logged-in user or organization.
type Registry interface {
Repositories() []Repository
}

// Repository is a collection of related (i.e. identical) images.
type Repository interface {
Name() string // "weaveworks/helloworld"
Images() []Image
}

// Image represents a specific container image available in a repository. It's a
// struct because I think we can safely assume the data here is pretty
// universal across different registries and repositories.
type Image struct {
Name string // "weaveworks/helloworld"
Tag string // "master-59f0001"
CreatedAt time.Time // Always UTC
}

0 comments on commit 2f4dffe

Please sign in to comment.