Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/test/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func ShoutrrrGotifyToken() (token string) {

var ArgusGitHubRepo = "release-argus/Argus"

// Amazon ECR Public Gallery Repo used for tests (AWS-owned, long-lived).
var ArgusDockerECRRepo = "docker/library/busybox"

// GHCR Repo for Argus.
var ArgusDockerGHCRRepo = "release-argus/argus"

Expand Down
146 changes: 146 additions & 0 deletions service/latest_version/filter/docker/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,102 @@ func TestApplyOverrides(t *testing.T) {
json: .*unmarshal.* number .*`,
),
},
{
name: "ecr -> ghcr",
format: "json",
data: test.TrimJSON(`{
"type": "ghcr",
"image": "test/app-ghcr",
"tag": "{{ version }}"
}`),
previous: &ECRRegistry{
CommonRegistry: CommonRegistry{
Type: "ecr",
ContainerDetail: ContainerDetail{
Image: "something",
Tag: "else",
},
},
},
errRegex: `^$`,
want: test.TrimYAML(`
type: ghcr
image: test/app-ghcr
tag: '{{ version }}'
`),
},
{
name: "ecr -> hub",
format: "json",
data: test.TrimJSON(`{
"type": "hub",
"image": "test/app-hub",
"tag": "{{ version }}"
}`),
previous: &ECRRegistry{
CommonRegistry: CommonRegistry{
Type: "ecr",
ContainerDetail: ContainerDetail{
Image: "something",
Tag: "else",
},
},
},
errRegex: `^$`,
want: test.TrimYAML(`
type: hub
image: test/app-hub
tag: '{{ version }}'
`),
},
{
name: "ecr -> quay",
format: "json",
data: test.TrimJSON(`{
"type": "quay",
"image": "test/app-quay",
"tag": "{{ version }}"
}`),
previous: &ECRRegistry{
CommonRegistry: CommonRegistry{
Type: "ecr",
ContainerDetail: ContainerDetail{
Image: "something",
Tag: "else",
},
},
},
errRegex: `^$`,
want: test.TrimYAML(`
type: quay
image: test/app-quay
tag: '{{ version }}'
`),
},
{
name: "ghcr -> ecr",
format: "json",
data: test.TrimJSON(`{
"type": "ecr",
"image": "test/app-ecr",
"tag": "{{ version }}"
}`),
previous: &GHCRRegistry{
CommonRegistry: CommonRegistry{
Type: "ghcr",
ContainerDetail: ContainerDetail{
Image: "something",
Tag: "else",
},
},
},
errRegex: `^$`,
want: test.TrimYAML(`
type: ecr
image: test/app-ecr
tag: '{{ version }}'
`),
},
{
name: "ghcr -> hub",
format: "json",
Expand Down Expand Up @@ -305,6 +401,30 @@ func TestApplyOverrides(t *testing.T) {
tag: '{{ version }}'
`),
},
{
name: "hub -> ecr",
format: "json",
data: test.TrimJSON(`{
"type": "ecr",
"image": "test/app-ecr",
"tag": "{{ version }}"
}`),
previous: &HubRegistry{
CommonRegistry: CommonRegistry{
Type: "hub",
ContainerDetail: ContainerDetail{
Image: "something",
Tag: "else",
},
},
},
errRegex: `^$`,
want: test.TrimYAML(`
type: ecr
image: test/app-ecr
tag: '{{ version }}'
`),
},
{
name: "hub -> ghcr",
format: "json",
Expand Down Expand Up @@ -347,6 +467,30 @@ func TestApplyOverrides(t *testing.T) {
image: test/app-quay
`),
},
{
name: "quay -> ecr",
format: "json",
data: test.TrimJSON(`{
"type": "ecr",
"image": "test/app-ecr",
"tag": "{{ version }}"
}`),
previous: &QuayRegistry{
CommonRegistry: CommonRegistry{
Type: "quay",
ContainerDetail: ContainerDetail{
Image: "something",
Tag: "else",
},
},
},
errRegex: `^$`,
want: test.TrimYAML(`
type: ecr
image: test/app-ecr
tag: '{{ version }}'
`),
},
{
name: "quay -> ghcr",
format: "json",
Expand Down Expand Up @@ -443,6 +587,8 @@ func TestApplyOverrides(t *testing.T) {

if tc.previous != nil {
switch v := tc.previous.(type) {
case *ECRRegistry:
v.Auth = RegistryMapInheritable["ecr"]().(Registry).GetAuth()
case *GHCRRegistry:
v.Auth = RegistryMapInheritable["ghcr"]().(Registry).GetAuth()
case *HubRegistry:
Expand Down
13 changes: 12 additions & 1 deletion service/latest_version/filter/docker/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Defaults struct {

// RegistryDefaultsSet holds per-registry default configuration.
type RegistryDefaultsSet struct {
ECR *ECRRegistryDefaults `json:"ecr,omitzero" yaml:"ecr,omitzero"` // Amazon ECR Public Gallery (anonymous: no serialisable config).
GHCR *GHCRRegistryDefaults `json:"ghcr,omitzero" yaml:"ghcr,omitzero"` // GitHub Container Registry.
Hub *HubRegistryDefaults `json:"hub,omitzero" yaml:"hub,omitzero"` // Docker Hub.
Quay *QuayRegistryDefaults `json:"quay,omitzero" yaml:"quay,omitzero"` // Quay.
Expand Down Expand Up @@ -88,7 +89,8 @@ func (r *RegistryDefaultsSet) IsZero() bool {
return true
}

return r.GHCR.IsZero() &&
return r.ECR.IsZero() &&
r.GHCR.IsZero() &&
r.Hub.IsZero() &&
r.Quay.IsZero()
}
Expand Down Expand Up @@ -123,6 +125,7 @@ func (d *Defaults) SetDefaults(defaults *Defaults) {
d.ContainerDetailDefaults.Defaults = &defaults.ContainerDetailDefaults

defaults.initRegistries()
setRegistryDefaults(d.Registry.ECR, defaults.Registry.ECR)
setRegistryDefaults(d.Registry.GHCR, defaults.Registry.GHCR)
setRegistryDefaults(d.Registry.Hub, defaults.Registry.Hub)
setRegistryDefaults(d.Registry.Quay, defaults.Registry.Quay)
Expand Down Expand Up @@ -170,6 +173,9 @@ func (d *Defaults) CheckValues() error {

// initRegistries ensures each registry-specific defaults slot is non-nil.
func (d *Defaults) initRegistries() {
if d.Registry.ECR == nil {
d.Registry.ECR = RegistryDefaultsMap["ecr"]().(*ECRRegistryDefaults)
}
if d.Registry.GHCR == nil {
d.Registry.GHCR = RegistryDefaultsMap["ghcr"]().(*GHCRRegistryDefaults)
}
Expand All @@ -184,6 +190,11 @@ func (d *Defaults) initRegistries() {
// getRegistryDefaults returns the defaults for dType from defaults, or nil if unset.
func getRegistryDefaults(dType string, defaults *Defaults) RegistryDefaults {
switch dType {
case "ecr":
if defaults.Registry.ECR == nil {
return nil
}
return defaults.Registry.ECR
case "ghcr":
if defaults.Registry.GHCR == nil {
return nil
Expand Down
20 changes: 18 additions & 2 deletions service/latest_version/filter/docker/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ func TestDecodeDefaults(t *testing.T) {
// THEN: The Defaults were passed over correctly.
fieldTests := []test.FieldAssertion{
{Name: "Defaults", Got: got.Defaults, Want: &defaults, Mode: test.CompareSamePointer},
{Name: "ECR.Auth.Defaults", Got: got.Registry.ECR.GetAuth().Defaults(), Want: defaults.Registry.ECR.GetAuth(), Mode: test.CompareSamePointer},
{Name: "GHCR.Auth.Defaults", Got: got.Registry.GHCR.GetAuth().Defaults(), Want: defaults.Registry.GHCR.GetAuth(), Mode: test.CompareSamePointer},
{Name: "Hub.Auth.Defaults", Got: got.Registry.Hub.GetAuth().Defaults(), Want: defaults.Registry.Hub.GetAuth(), Mode: test.CompareSamePointer},
{Name: "Quay.Auth.Defaults", Got: got.Registry.Quay.GetAuth().Defaults(), Want: defaults.Registry.Quay.GetAuth(), Mode: test.CompareSamePointer},
Expand Down Expand Up @@ -851,6 +852,7 @@ func TestDefaults_Defaults(t *testing.T) {
return
}
fieldTests := []test.FieldAssertion{
{Name: "ECR.Auth.Defaults", Got: defaults.Registry.ECR.GetAuth().Defaults(), Want: tc.defaults.Registry.ECR.GetAuth(), Mode: test.CompareSamePointer},
{Name: "GHCR.Auth.Defaults", Got: defaults.Registry.GHCR.GetAuth().Defaults(), Want: tc.defaults.Registry.GHCR.GetAuth(), Mode: test.CompareSamePointer},
{Name: "Hub.Auth.Defaults", Got: defaults.Registry.Hub.GetAuth().Defaults(), Want: tc.defaults.Registry.Hub.GetAuth(), Mode: test.CompareSamePointer},
{Name: "Quay.Auth.Defaults", Got: defaults.Registry.Quay.GetAuth().Defaults(), Want: tc.defaults.Registry.Quay.GetAuth(), Mode: test.CompareSamePointer},
Expand Down Expand Up @@ -999,7 +1001,8 @@ func TestDefaults_InitRegistries(t *testing.T) {
var d Defaults

// THEN: all registries are nil
if d.Registry.GHCR != nil ||
if d.Registry.ECR != nil ||
d.Registry.GHCR != nil ||
d.Registry.Hub != nil ||
d.Registry.Quay != nil {
t.Fatalf(
Expand All @@ -1012,7 +1015,8 @@ func TestDefaults_InitRegistries(t *testing.T) {
d.initRegistries()

// THEN: all registries are initialised
if d.Registry.GHCR == nil ||
if d.Registry.ECR == nil ||
d.Registry.GHCR == nil ||
d.Registry.Hub == nil ||
d.Registry.Quay == nil {
t.Fatalf(
Expand All @@ -1028,6 +1032,10 @@ func TestGetRegistryDefaults(t *testing.T) {
name string
dType string
}{
{
name: "known: ecr",
dType: "ecr",
},
{
name: "known: ghcr",
dType: "ghcr",
Expand Down Expand Up @@ -1055,6 +1063,8 @@ func TestGetRegistryDefaults(t *testing.T) {

var want RegistryDefaults
switch tc.dType {
case "ecr":
want = defaults.Registry.ECR
case "ghcr":
want = defaults.Registry.GHCR
case "hub":
Expand Down Expand Up @@ -1088,6 +1098,10 @@ func TestGetRegistryDefaults_NilDefaults(t *testing.T) {
name string
dType string
}{
{
name: "known: ecr",
dType: "ecr",
},
{
name: "known: ghcr",
dType: "ghcr",
Expand All @@ -1114,6 +1128,8 @@ func TestGetRegistryDefaults_NilDefaults(t *testing.T) {
_, defaults := plainDefaults(t)

switch tc.dType {
case "ecr":
defaults.Registry.ECR = nil
case "ghcr":
defaults.Registry.GHCR = nil
case "hub":
Expand Down
7 changes: 5 additions & 2 deletions service/latest_version/filter/docker/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ func plainDefaults(t *testing.T) (*Defaults, *Defaults) {
func getTokenData(t *testing.T, auth RegistryAuth) (token, queryToken string, validUntil time.Time) {
t.Helper()
switch a := auth.(type) {
case *QuayAuth:
token = a.GetToken()
case *ECRAuth:
queryToken = a.queryToken
validUntil = a.validUntil
case *GHCRAuth:
token = a.GetToken()
queryToken = a.queryToken
Expand All @@ -70,6 +71,8 @@ func getTokenData(t *testing.T, auth RegistryAuth) (token, queryToken string, va
token = a.GetToken()
queryToken = a.queryToken
validUntil = a.validUntil
case *QuayAuth:
token = a.GetToken()
}
return
}
4 changes: 2 additions & 2 deletions service/latest_version/filter/docker/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type RegistryAuth interface {
type RegistryDefaults interface {
yaml.IsZeroer

// GetType returns the fixed registry kind (e.g. "hub", "ghcr", "quay").
// GetType returns the fixed registry kind (e.g. "ecr", "ghcr", "hub", "quay").
GetType() string

GetAuth() RegistryAuthDefaults
Expand Down Expand Up @@ -103,7 +103,7 @@ type Registry interface {
Inherit(from Registry)

// GetTypeSelf returns the configured type field; GetType (from polymorphic.Inheritable)
// returns the fixed registry kind (e.g. "hub", "ghcr", "quay").
// returns the fixed registry kind (e.g. "ecr", "ghcr", "hub", "quay").
GetTypeSelf() string
GetImage() string
GetImageSelf() string
Expand Down
5 changes: 5 additions & 0 deletions service/latest_version/filter/docker/registry_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,11 @@ func TestCommonRegistry_Defaults(t *testing.T) {
// GIVEN: registryDefaults.
defaults := Defaults{
Registry: RegistryDefaultsSet{
ECR: &ECRRegistryDefaults{
CommonRegistryDefaults: CommonRegistryDefaults{
Auth: &ECRAuthDefaults{},
},
},
GHCR: &GHCRRegistryDefaults{
CommonRegistryDefaults: CommonRegistryDefaults{
Auth: &HubAuthDefaults{
Expand Down
Loading
Loading