Skip to content

Commit

Permalink
feat(private-containers): private registries
Browse files Browse the repository at this point in the history
refs akash-network/support#54

Signed-off-by: Adam Bozanich <[email protected]>
  • Loading branch information
boz committed Apr 13, 2024
1 parent 76204ef commit 6248ff5
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/akash-network/node
go 1.21

require (
github.com/akash-network/akash-api v0.0.61
github.com/akash-network/akash-api v0.0.62
github.com/blang/semver/v4 v4.0.0
github.com/boz/go-lifecycle v0.1.1
github.com/cosmos/cosmos-sdk v0.45.16
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBA
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/akash-network/akash-api v0.0.61 h1:Hj/IBr9cFMsFs4VjymLZCoX/5dNfZSFd4iFwUSqhBtQ=
github.com/akash-network/akash-api v0.0.61/go.mod h1:pNr61L4+0sheol7ZK0HjgK3rxpIAbYBGq1w1oH4B0+M=
github.com/akash-network/akash-api v0.0.62 h1:o/V/iwlrel++5xo1UTlGO8aASKWTXm3to5+Z3IyYZUw=
github.com/akash-network/akash-api v0.0.62/go.mod h1:pNr61L4+0sheol7ZK0HjgK3rxpIAbYBGq1w1oH4B0+M=
github.com/akash-network/cometbft v0.34.27-akash h1:V1dApDOr8Ee7BJzYyQ7Z9VBtrAul4+baMeA6C49dje0=
github.com/akash-network/cometbft v0.34.27-akash/go.mod h1:BcCbhKv7ieM0KEddnYXvQZR+pZykTKReJJYf7YC7qhw=
github.com/akash-network/ledger-go v0.14.3 h1:LCEFkTfgGA2xFMN2CtiKvXKE7dh0QSM77PJHCpSkaAo=
Expand Down
48 changes: 48 additions & 0 deletions sdl/_testdata/v2.1-credentials-error.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
version: "2.1"
services:
web:
image: nginx
expose:
- port: 80
accept:
- ahostname.com
to:
- global: true
- port: 12345
to:
- global: true
proto: udp
credentials:
username: "foo"
password: "foo"
profiles:
compute:
web:
resources:
cpu:
units: "100m"
memory:
size: "128Mi"
storage:
size: "1Gi"
placement:
westcoast:
attributes:
region: us-west
signedBy:
anyOf:
- 1
- 2
allOf:
- 3
- 4
pricing:
web:
denom: uakt
amount: 50
deployment:
web:
westcoast:
profile: web
count: 2
49 changes: 49 additions & 0 deletions sdl/_testdata/v2.1-credentials.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
version: "2.1"
services:
web:
image: nginx
expose:
- port: 80
accept:
- ahostname.com
to:
- global: true
- port: 12345
to:
- global: true
proto: udp
credentials:
host: "https://test.com/v1"
username: "foo"
password: "foo"
profiles:
compute:
web:
resources:
cpu:
units: "100m"
memory:
size: "128Mi"
storage:
size: "1Gi"
placement:
westcoast:
attributes:
region: us-west
signedBy:
anyOf:
- 1
- 2
allOf:
- 3
- 4
pricing:
web:
denom: uakt
amount: 50
deployment:
web:
westcoast:
profile: web
count: 2
8 changes: 8 additions & 0 deletions sdl/groupBuilder_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ func (sdl *v2) buildGroups() error {
msvc.Params = params
}

if svc.Credentials != nil {
msvc.Credentials = &manifest.ServiceImageCredentials{
Host: svc.Credentials.Host,
Username: svc.Credentials.Username,
Password: svc.Credentials.Password,
}
}

group.mgroup.Services = append(group.mgroup.Services, msvc)
}
}
Expand Down
10 changes: 10 additions & 0 deletions sdl/groupBuilder_v2_1.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sdl

import (
"sort"
"strings"

manifest "github.com/akash-network/akash-api/go/manifest/v2beta2"
dtypes "github.com/akash-network/akash-api/go/node/deployment/v1beta3"
Expand Down Expand Up @@ -123,6 +124,15 @@ func (sdl *v2_1) buildGroups() error {
msvc.Params = params
}

if svc.Credentials != nil {
msvc.Credentials = &manifest.ServiceImageCredentials{
Host: strings.TrimSpace(svc.Credentials.Host),
Email: strings.TrimSpace(svc.Credentials.Email),
Username: strings.TrimSpace(svc.Credentials.Username),
Password: strings.TrimSpace(svc.Credentials.Password),
}
}

group.mgroup.Services = append(group.mgroup.Services, msvc)
}
}
Expand Down
49 changes: 43 additions & 6 deletions sdl/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"regexp"
"sort"
"strconv"
"strings"

"gopkg.in/yaml.v3"

Expand Down Expand Up @@ -42,6 +43,9 @@ var (
errUnknownNextCase = errors.New("next case is unknown")
errHTTPOptionNotAllowed = errors.New("http option not allowed")
errSDLInvalid = errors.New("SDL invalid")
errCredentialNoHost = errors.New("Service Credentials missing Host")
errCredentialNoUsername = errors.New("Service Credentials missing Username")
errCredentialNoPassword = errors.New("Service Credentials missing Password")
)

var endpointNameValidationRegex = regexp.MustCompile(`^[[:lower:]]+[[:lower:]-_\d]+$`)
Expand Down Expand Up @@ -167,12 +171,33 @@ type v2ServiceParams struct {

type v2Service struct {
Image string
Command []string `yaml:",omitempty"`
Args []string `yaml:",omitempty"`
Env []string `yaml:",omitempty"`
Expose v2Exposes `yaml:",omitempty"`
Dependencies []v2Dependency `yaml:",omitempty"`
Params *v2ServiceParams `yaml:",omitempty"`
Command []string `yaml:",omitempty"`
Args []string `yaml:",omitempty"`
Env []string `yaml:",omitempty"`
Expose v2Exposes `yaml:",omitempty"`
Dependencies []v2Dependency `yaml:",omitempty"`
Params *v2ServiceParams `yaml:",omitempty"`
Credentials *v2ServiceCredentials `yaml:",omitempty"`
}

type v2ServiceCredentials struct {
Host string `yaml:",omitempty"`
Email string `yaml:",omitempty"`
Username string `yaml:",omitempty"`
Password string `yaml:",omitempty"`
}

func (c v2ServiceCredentials) validate() error {
if strings.TrimSpace(c.Host) == "" {
return errCredentialNoHost
}
if strings.TrimSpace(c.Username) == "" {
return errCredentialNoUsername
}
if strings.TrimSpace(c.Password) == "" {
return errCredentialNoPassword
}
return nil
}

type v2ServiceDeployment struct {
Expand Down Expand Up @@ -328,6 +353,18 @@ func (sdl *v2) validate() error {
)
}

if svc.Credentials != nil {
if err := svc.Credentials.validate(); err != nil {
return fmt.Errorf(
"%w: %v.%v: %v",
errSDLInvalid,
svcName,
placementName,
err,
)
}
}

for _, serviceExpose := range svc.Expose {
for _, to := range serviceExpose.To {
// Check to see if an IP endpoint is also specified
Expand Down
12 changes: 12 additions & 0 deletions sdl/v2_1.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ func (sdl *v2_1) validate() error {
)
}

if svc.Credentials != nil {
if err := svc.Credentials.validate(); err != nil {
return fmt.Errorf(
"%w: %v.%v: %v",
errSDLInvalid,
svcName,
placementName,
err,
)
}
}

for _, serviceExpose := range svc.Expose {
for _, to := range serviceExpose.To {
// Check to see if an IP endpoint is also specified
Expand Down
32 changes: 32 additions & 0 deletions sdl/v2_1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,38 @@ func Test_V2_1_Parse_simple(t *testing.T) {
},
},
}, mani.GetGroups()[0])

assert.Nil(t, mani.GetGroups()[0].Services[0].Credentials)

}

func Test_V2_1_Parse_credentials(t *testing.T) {
sdl, err := ReadFile("./_testdata/v2.1-credentials.yaml")
require.NoError(t, err)

mani, err := sdl.Manifest()
require.NoError(t, err)

assert.Len(t, mani.GetGroups(), 1)

grp := mani.GetGroups()[0]
assert.Len(t, grp.Services, 1)

svc := grp.Services[0]

assert.NotNil(t, svc)

creds := svc.Credentials
assert.NotNil(t, creds)

assert.Equal(t, "https://test.com/v1", creds.Host)
assert.Equal(t, "foo", creds.Username)
assert.Equal(t, "foo", creds.Password)
}

func Test_V2_1_Parse_credentials_error(t *testing.T) {
_, err := ReadFile("./_testdata/v2.1-credentials-error.yaml")
require.Error(t, err)
}

func Test_v2_1_Parse_ProfileNameNotServiceName(t *testing.T) {
Expand Down

0 comments on commit 6248ff5

Please sign in to comment.