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
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/GoCodeAlone/workflow-plugin-digitalocean
go 1.26.0

require (
github.com/GoCodeAlone/workflow v0.17.0
github.com/GoCodeAlone/workflow v0.18.2
github.com/aws/aws-sdk-go-v2 v1.41.5
github.com/aws/aws-sdk-go-v2/credentials v1.19.12
github.com/aws/aws-sdk-go-v2/service/s3 v1.97.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ github.com/GoCodeAlone/modular/modules/jsonschema v1.15.0 h1:xb1mI4NZkzvNKQ2F6nk
github.com/GoCodeAlone/modular/modules/jsonschema v1.15.0/go.mod h1:hhGouwAVsonmJ4Lain4jINZ9nZCoc9l9eF3BHbmR8eE=
github.com/GoCodeAlone/modular/modules/reverseproxy/v2 v2.8.0 h1:cvdLHbM/vzvygQTcAWSJsy+dAPzzwWyjzKMmTBFcFIo=
github.com/GoCodeAlone/modular/modules/reverseproxy/v2 v2.8.0/go.mod h1:/9ipMG4qM2CHQ14BfXKdVlYRJelef6M8MFI5TbZv67M=
github.com/GoCodeAlone/workflow v0.17.0 h1:Fp4eOdaZKNnIsBvLJT4PcxSmv+++M3X9McKjKMEMz3g=
github.com/GoCodeAlone/workflow v0.17.0/go.mod h1:MGC8lxQzA1TLRIK09mGEN5JNpRzFUcTWgqk3M0/H5FI=
github.com/GoCodeAlone/workflow v0.18.2 h1:Vbm+NvhWMcHHl1zE6aQzNh3MSJzQhmunFO6DA3x9qh8=
github.com/GoCodeAlone/workflow v0.18.2/go.mod h1:ypkCqXTwnIPqNjS8h38KZfwzdVsgwgkS1d6Dq0lXyQQ=
github.com/GoCodeAlone/yaegi v0.17.2 h1:WK6Y6e0t1a6U7r+S2dN3CGWW1PizYD3zO0zneToZPxM=
github.com/GoCodeAlone/yaegi v0.17.2/go.mod h1:z5Pr6Wse6QJcQvpgxTxzMAevFarH0N37TG88Y9dprx0=
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.32.0 h1:rIkQfkCOVKc1OiRCNcSDD8ml5RJlZbH/Xsq7lbpynwc=
Expand Down
66 changes: 19 additions & 47 deletions internal/drivers/app_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,16 @@ func NewAppPlatformDriverWithClient(c AppPlatformClient, region string) *AppPlat
}

func (d *AppPlatformDriver) Create(ctx context.Context, spec interfaces.ResourceSpec) (*interfaces.ResourceOutput, error) {
imgSpec, err := imageSpecFromConfig(spec.Config)
if err != nil {
return nil, fmt.Errorf("app platform image config: %w", err)
}
region, _ := spec.Config["region"].(string)
if region == "" {
region = d.region
}
httpPort, _ := intFromConfig(spec.Config, "http_port", 8080)
instanceCount, _ := intFromConfig(spec.Config, "instance_count", 1)

req := &godo.AppCreateRequest{
Spec: &godo.AppSpec{
Name: spec.Name,
Region: region,
Services: []*godo.AppServiceSpec{
{
Name: spec.Name,
InstanceCount: int64(instanceCount),
HTTPPort: int64(httpPort),
Envs: envVarsFromConfig(spec.Config),
Image: imgSpec,
},
},
},
appSpec, err := buildAppSpec(spec.Name, spec.Config, region)
if err != nil {
return nil, fmt.Errorf("app platform build spec: %w", err)
}

app, _, err := d.client.Create(ctx, req)
app, _, err := d.client.Create(ctx, &godo.AppCreateRequest{Spec: appSpec})
if err != nil {
return nil, fmt.Errorf("app platform create %q: %w", spec.Name, WrapGodoError(err))
}
Expand Down Expand Up @@ -110,34 +92,16 @@ func (d *AppPlatformDriver) findAppByName(ctx context.Context, name string) (*in
}

func (d *AppPlatformDriver) Update(ctx context.Context, ref interfaces.ResourceRef, spec interfaces.ResourceSpec) (*interfaces.ResourceOutput, error) {
imgSpec, err := imageSpecFromConfig(spec.Config)
if err != nil {
return nil, fmt.Errorf("app platform image config: %w", err)
}
region, _ := spec.Config["region"].(string)
if region == "" {
region = d.region
}
httpPort, _ := intFromConfig(spec.Config, "http_port", 8080)
instanceCount, _ := intFromConfig(spec.Config, "instance_count", 1)

req := &godo.AppUpdateRequest{
Spec: &godo.AppSpec{
Name: spec.Name,
Region: region,
Services: []*godo.AppServiceSpec{
{
Name: spec.Name,
InstanceCount: int64(instanceCount),
HTTPPort: int64(httpPort),
Envs: envVarsFromConfig(spec.Config),
Image: imgSpec,
},
},
},
appSpec, err := buildAppSpec(spec.Name, spec.Config, region)
if err != nil {
return nil, fmt.Errorf("app platform build spec: %w", err)
}

app, _, err := d.client.Update(ctx, ref.ProviderID, req)
app, _, err := d.client.Update(ctx, ref.ProviderID, &godo.AppUpdateRequest{Spec: appSpec})
if err != nil {
return nil, fmt.Errorf("app platform update %q: %w", ref.Name, WrapGodoError(err))
}
Expand Down Expand Up @@ -376,11 +340,19 @@ func imageSpecFromMap(m map[string]any) (*godo.ImageSourceSpec, error) {
}

// envVarsFromConfig converts the "env_vars" map in spec config to App Platform
// environment variable definitions. Values listed under "secret_env_vars" are
// marked as SECRET so DigitalOcean stores them encrypted.
// environment variable definitions. Secret vars use "env_vars_secret" (canonical key).
// "secret_env_vars" is a legacy alias: it is used only when "env_vars_secret" is
// absent from the config entirely (key-presence check, not length check).
func envVarsFromConfig(cfg map[string]any) []*godo.AppVariableDefinition {
raw, _ := cfg["env_vars"].(map[string]any)
secrets, _ := cfg["secret_env_vars"].(map[string]any)
// Prefer the canonical key; fall back to the legacy alias only when the
// canonical key is not present at all (not just empty).
var secrets map[string]any
if v, ok := cfg["env_vars_secret"]; ok {
secrets, _ = v.(map[string]any)
} else {
secrets, _ = cfg["secret_env_vars"].(map[string]any)
}
if len(raw) == 0 && len(secrets) == 0 {
return nil
}
Expand Down
Loading
Loading