Skip to content
Open
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: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/go-delve/delve v1.25.2
github.com/go-git/go-billy/v5 v5.6.1
github.com/go-git/go-git/v5 v5.13.1
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/golangci/golangci-lint v1.64.8
github.com/google/uuid v1.6.0
github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef
Expand All @@ -38,6 +39,7 @@ require (
github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.18.1
github.com/pulumi/pulumi-mongodbatlas/sdk/v3 v3.30.0
github.com/pulumi/pulumi-random/sdk/v4 v4.17.0
github.com/pulumi/pulumi-yandex/sdk v0.13.0
github.com/pulumi/pulumi/pkg/v3 v3.184.0
github.com/pulumi/pulumi/sdk/v3 v3.184.0
github.com/samber/lo v1.38.1
Expand Down Expand Up @@ -209,7 +211,6 @@ require (
github.com/gofrs/flock v0.12.1 // indirect
github.com/gofrs/uuid v4.2.0+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
github.com/golang/glog v1.2.4 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
Expand Down
119 changes: 119 additions & 0 deletions go.sum

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions pkg/api/tests/refapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/simple-container-com/api/pkg/clouds/k8s"
"github.com/simple-container-com/api/pkg/clouds/mongodb"
"github.com/simple-container-com/api/pkg/clouds/pulumi"
"github.com/simple-container-com/api/pkg/clouds/yandex"
)

var CommonGcpCredentials = gcloud.Credentials{
Expand Down Expand Up @@ -551,6 +552,15 @@ var CommonSecretsDescriptor = &api.SecretsDescriptor{
Kubeconfig: "<kube-config>",
}},
},
"yandex": {
Type: yandex.AuthTypeYandex,
Config: api.Config{Config: &yandex.AccountConfig{
CloudId: "000",
Credentials: api.Credentials{
Credentials: "<yandex-creds>",
},
}},
},
},
Values: map[string]string{
"CLOUDFLARE_API_TOKEN": "<encrypted-secret>",
Expand Down
8 changes: 8 additions & 0 deletions pkg/api/tests/refapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func TestReadServerDescriptor(t *testing.T) {
path: "testdata/stacks/refapp-kubernetes/server.yaml",
want: RefappKubernetesServerDescriptor,
},
{
path: "testdata/stacks/refapp-yandex-serverless-container/server.yaml",
want: RefappYandexServerlessContainerServerDescriptor,
},
}
for _, tt := range tests {
t.Run(tt.path, func(t *testing.T) {
Expand Down Expand Up @@ -106,6 +110,10 @@ func TestReadClientDescriptor(t *testing.T) {
path: "testdata/stacks/refapp-gke-autopilot/client.yaml",
want: RefappGkeAutopilotClientDescriptor,
},
{
path: "testdata/stacks/refapp-yandex-serverless-container/client.yaml",
want: RefappYandexServerlessContainerClientDescriptor,
},
}
for _, tt := range tests {
t.Run(tt.path, func(t *testing.T) {
Expand Down
130 changes: 130 additions & 0 deletions pkg/api/tests/refapp_yandex.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package tests

import (
"github.com/simple-container-com/api/pkg/api"
"github.com/simple-container-com/api/pkg/clouds/yandex"
)

var RefappYandexServerlessContainerServerDescriptor = &api.ServerDescriptor{
SchemaVersion: api.ServerSchemaVersion,
Provisioner: api.ProvisionerDescriptor{
Inherit: api.Inherit{Inherit: "common"},
},
Secrets: api.SecretsConfigDescriptor{
Inherit: api.Inherit{Inherit: "common"},
},
CiCd: api.CiCdDescriptor{
Inherit: api.Inherit{Inherit: "common"},
},
Templates: map[string]api.StackDescriptor{
"func-per-app": {
Type: yandex.TemplateTypeYandexServerlessContainer,
Config: api.Config{Config: &yandex.TemplateConfig{
AccountConfig: yandex.AccountConfig{
CloudId: "${auth:yandex.projectId}",
Credentials: api.Credentials{
Credentials: "${auth:yandex}",
},
},
}},
},
},
Resources: api.PerStackResourcesDescriptor{
Registrar: api.RegistrarDescriptor{
Inherit: api.Inherit{Inherit: "common"},
},
Resources: map[string]api.PerEnvResourcesDescriptor{
"staging": {
Template: "func-per-app",
},
"prod": {
Template: "func-per-app",
},
},
},
}

var RefappYandexServerlessContainerClientDescriptor = &api.ClientDescriptor{
SchemaVersion: api.ClientSchemaVersion,
Stacks: map[string]api.StackClientDescriptor{
"staging": {
Type: api.ClientTypeSingleImage,
ParentStack: "refapp-yandex-serverless-container",
Config: api.Config{
Config: &api.StackConfigSingleImage{
Domain: "staging.sc-refapp.org",
Image: &api.ContainerImage{
Dockerfile: "Dockerfile",
},
Env: map[string]string{
"ENV": "staging",
},
},
},
},
"prod": {
Type: api.ClientTypeSingleImage,
ParentStack: "refapp-yandex-serverless-container",
Config: api.Config{
Config: &api.StackConfigSingleImage{
Domain: "prod.sc-refapp.org",
Image: &api.ContainerImage{
Dockerfile: "Dockerfile",
},
Env: map[string]string{
"ENV": "prod",
},
},
},
},
},
}

var resolvedYandexAccountConfig = yandex.AccountConfig{
CloudId: "000",
Credentials: api.Credentials{
Credentials: `<yandex-creds>`,
},
}

var ResolvedRefappYandexServerlessContainerServerDescriptor = &api.ServerDescriptor{
SchemaVersion: api.ServerSchemaVersion,
Provisioner: ResolvedCommonServerDescriptor.Provisioner,
Secrets: ResolvedCommonServerDescriptor.Secrets,
CiCd: ResolvedCommonServerDescriptor.CiCd,
Templates: map[string]api.StackDescriptor{
"func-per-app": {
Type: yandex.TemplateTypeYandexServerlessContainer,
Config: api.Config{Config: &yandex.TemplateConfig{
AccountConfig: resolvedYandexAccountConfig,
}},
},
},
Variables: map[string]api.VariableDescriptor{},
Resources: api.PerStackResourcesDescriptor{
Registrar: ResolvedCommonServerDescriptor.Resources.Registrar,
Resources: map[string]api.PerEnvResourcesDescriptor{
"staging": {
Template: "func-per-app",
Resources: map[string]api.ResourceDescriptor{},
},
"prod": {
Template: "func-per-app",
Resources: map[string]api.ResourceDescriptor{},
},
},
},
}

func ResolvedRefappYandexServerlessContainerClientDescriptor() *api.ClientDescriptor {
res := RefappYandexServerlessContainerClientDescriptor.Copy()
for name := range res.Stacks {
stackCfg := res.Stacks[name]
singleImage := stackCfg.Config.Config.(*api.StackConfigSingleImage)
singleImage.Uses = []string{}
singleImage.Secrets = map[string]string{}
res.Stacks[name] = stackCfg
}

return &res
}
5 changes: 5 additions & 0 deletions pkg/api/tests/testdata/stacks/common/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ auth:
type: kubernetes
config:
kubeconfig: <kube-config>
yandex:
type: yandex
config:
cloudId: '000'
credentials: <yandex-creds>
values:
CLOUDFLARE_API_TOKEN: <encrypted-secret>
GITHUB_TOKEN: <encrypted-secret>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by sc CLI when initially setting up
schemaVersion: 1.0
stacks:
staging: &staging
type: single-image
parent: refapp-yandex-serverless-container
config: &config
domain: staging.sc-refapp.org
image:
dockerfile: Dockerfile
env:
ENV: staging
prod:
<<: *staging
config:
<<: *config
domain: prod.sc-refapp.org
env:
ENV: prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
schemaVersion: 1.0
provisioner:
inherit: common
secrets:
inherit: common
cicd:
inherit: common
templates:
func-per-app:
type: yandex-serverless-container
config:
credentials: "${auth:yandex}"
cloudId: "${auth:yandex.projectId}"
resources:
registrar:
inherit: common
resources:
staging:
template: func-per-app
resources: &resources
prod:
template: func-per-app
resources: *resources
15 changes: 11 additions & 4 deletions pkg/clouds/pulumi/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/pulumi/pulumi/sdk/v3/go/auto"
sdk "github.com/pulumi/pulumi/sdk/v3/go/pulumi"

"github.com/simple-container-com/api/pkg/api"
"github.com/simple-container-com/api/pkg/api/logger/color"
Expand All @@ -17,15 +18,21 @@ func (p *pulumi) CancelStack(ctx context.Context, cfg *api.ConfigFile, stack api
if err != nil {
return err
}
return p.cancelStack(ctx, cfg)
return p.cancelStack(ctx, cfg, stack, params)
}

func (p *pulumi) cancelStack(ctx context.Context, cfg *api.ConfigFile) error {
func (p *pulumi) cancelStack(ctx context.Context, cfg *api.ConfigFile, stack api.Stack, params api.StackParams) error {
s, err := p.validateStateAndGetStack(ctx)
if err != nil {
return err
}
stackSource, err := p.prepareStackForOperations(ctx, s.Ref(), cfg, nil)
var program func(ctx *sdk.Context) error
if params.Environment != "" && params.StackName != "" {
program = p.deployStackProgram(stack, params, stack.Name, s.Ref().FullyQualifiedName().String())
} else {
program = p.provisionProgram(stack, cfg)
}
stackSource, err := p.prepareStackForOperations(ctx, s.Ref(), cfg, program)
if err != nil {
return err
}
Expand All @@ -38,7 +45,7 @@ func (p *pulumi) cancelStack(ctx context.Context, cfg *api.ConfigFile) error {

if p.secretsStackRef != nil {
defer p.withPulumiPassphrase(ctx)()
ssSource, err := auto.UpsertStackInlineSource(ctx, p.secretsStackRef.FullyQualifiedName().String(), cfg.ProjectName, nil)
ssSource, err := auto.UpsertStackInlineSource(ctx, p.secretsStackRef.FullyQualifiedName().String(), cfg.ProjectName, p.provisionProgram(stack, cfg))
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/clouds/pulumi/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
_ "github.com/simple-container-com/api/pkg/clouds/pulumi/cloudflare"
_ "github.com/simple-container-com/api/pkg/clouds/pulumi/gcp"
_ "github.com/simple-container-com/api/pkg/clouds/pulumi/mongodb"
_ "github.com/simple-container-com/api/pkg/clouds/pulumi/yandex"
)

func init() {
Expand Down
Loading