Skip to content

Commit

Permalink
Add support for DeploymentSettings dependency CacheOptions (#436)
Browse files Browse the repository at this point in the history
Adds support for enabling dependency caching in deployment settings.
  • Loading branch information
nyobe authored Nov 7, 2024
1 parent 3445009 commit d07cf51
Show file tree
Hide file tree
Showing 24 changed files with 655 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### Improvements

- Allow force deleting agent pools. [#435](https://github.com/pulumi/pulumi-pulumiservice/pull/435)
- Add support for CacheOptions in DeploymentSettings to enable Dependency Caching [#436](https://github.com/pulumi/pulumi-pulumiservice/pull/436)

### Bug Fixes

Expand Down
4 changes: 4 additions & 0 deletions examples/py-deployment-settings/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
DeploymentSettingsOperationContextArgs,
DeploymentSettingsSourceContextArgs,
DeploymentSettingsGitSourceArgs,
DeploymentSettingsCacheOptionsArgs,
)

config = pulumi.Config()
Expand Down Expand Up @@ -35,4 +36,7 @@
)
),
agent_pool_id=agent_pool.agent_pool_id,
cache_options=DeploymentSettingsCacheOptionsArgs(
enable=True,
)
)
3 changes: 3 additions & 0 deletions examples/ts-deployment-settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,8 @@ const settings = new service.DeploymentSettings("deployment_settings", {
}
}
}
},
cacheOptions: {
enable: true,
}
});
2 changes: 2 additions & 0 deletions examples/yaml-deployment-settings/Pulumi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ resources:
TEST_VAR: "test-value"
options:
skipInstallDependencies: true
cacheOptions:
enable: true
19 changes: 19 additions & 0 deletions provider/cmd/pulumi-resource-pulumiservice/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,17 @@
}
]
},
"pulumiservice:index:DeploymentSettingsCacheOptions": {
"description": "Dependency cache settings for the deployment",
"properties": {
"enable": {
"type": "boolean",
"description": "Enable dependency caching",
"default": false
}
},
"type": "object"
},
"pulumiservice:index:EnvironmentPermission": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -1073,6 +1084,10 @@
"agentPoolId": {
"description": "The agent pool identifier to use for the deployment.",
"type": "string"
},
"cacheOptions": {
"$ref": "#/types/pulumiservice:index:DeploymentSettingsCacheOptions",
"description": "Dependency cache settings for the deployment"
}
},
"required": [
Expand Down Expand Up @@ -1112,6 +1127,10 @@
"agentPoolId": {
"description": "The agent pool identifier to use for the deployment.",
"type": "string"
},
"cacheOptions": {
"$ref": "#/types/pulumiservice:index:DeploymentSettingsCacheOptions",
"description": "Dependency cache settings for the deployment"
}
},
"requiredInputs": [
Expand Down
1 change: 1 addition & 0 deletions provider/pkg/internal/pulumiapi/deployment_setting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func TestCreateDeploymentSettings(t *testing.T) {
GitHub: &GitHubConfiguration{},
SourceContext: &SourceContext{},
ExecutorContext: &apitype.ExecutorContext{},
CacheOptions: &CacheOptions{},
}

c, cleanup := startTestServer(t, testServerConfig{
Expand Down
5 changes: 5 additions & 0 deletions provider/pkg/internal/pulumiapi/deployment_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type DeploymentSettings struct {
ExecutorContext *apitype.ExecutorContext `json:"executorContext,omitempty"`
AgentPoolId string `json:"agentPoolId,omitempty"`
Source *string `json:"source,omitempty"`
CacheOptions *CacheOptions `json:"cacheOptions,omitempty"`
}

type OperationContext struct {
Expand Down Expand Up @@ -109,6 +110,10 @@ type SecretValue struct {
Secret bool
}

type CacheOptions struct {
Enable bool `json:"enable"`
}

type secretCiphertextValue struct {
Ciphertext string `json:"ciphertext"`
}
Expand Down
14 changes: 14 additions & 0 deletions provider/pkg/provider/deployment_setting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,17 @@ func TestDeploymentSettings(t *testing.T) {
assert.Equal(t, resp.Id, "abc/def/123")
})
}

func TestDeploymentSettingsRoundtrip(t *testing.T) {
initial := PulumiServiceDeploymentSettingsInput{
DeploymentSettings: pulumiapi.DeploymentSettings{
CacheOptions: &pulumiapi.CacheOptions{
Enable: true,
},
}}

encoded := initial.ToPropertyMap(nil, nil, true)
decoded := (&PulumiServiceDeploymentSettingsResource{}).ToPulumiServiceDeploymentSettingsInput(encoded)

assert.EqualValues(t, initial, decoded)
}
23 changes: 23 additions & 0 deletions provider/pkg/provider/deployment_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ func (ds *PulumiServiceDeploymentSettingsInput) ToPropertyMap(plaintextInputSett
ecMap["executorImage"] = resource.NewPropertyValue(ds.ExecutorContext.ExecutorImage.Reference)
pm["executorContext"] = resource.PropertyValue{V: ecMap}
}

if ds.CacheOptions != nil {
coMap := resource.PropertyMap{}
coMap["enable"] = resource.NewPropertyValue(ds.CacheOptions.Enable)
pm["cacheOptions"] = resource.PropertyValue{coMap}
}

return pm
}

Expand Down Expand Up @@ -324,6 +331,7 @@ func (ds *PulumiServiceDeploymentSettingsResource) ToPulumiServiceDeploymentSett
input.GitHub = toGitHubConfig(inputMap)
input.SourceContext = toSourceContext(inputMap)
input.OperationContext = toOperationContext(inputMap)
input.CacheOptions = toCacheOptions(inputMap)

return input
}
Expand Down Expand Up @@ -591,6 +599,21 @@ func toOperationContext(inputMap resource.PropertyMap) *pulumiapi.OperationConte
return &oc
}

func toCacheOptions(inputMap resource.PropertyMap) *pulumiapi.CacheOptions {
if !inputMap["cacheOptions"].HasValue() || !inputMap["cacheOptions"].IsObject() {
return nil
}

coInput := inputMap["cacheOptions"].ObjectValue()
var co pulumiapi.CacheOptions

if coInput["enable"].HasValue() && coInput["enable"].IsBool() {
co.Enable = coInput["enable"].BoolValue()
}

return &co
}

func getSecretOrStringValue(prop resource.PropertyValue) string {
switch prop.V.(type) {
case *resource.Secret:
Expand Down
12 changes: 12 additions & 0 deletions sdk/dotnet/DeploymentSettings.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions sdk/dotnet/Inputs/DeploymentSettingsCacheOptionsArgs.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions sdk/dotnet/Outputs/DeploymentSettingsCacheOptions.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions sdk/go/pulumiservice/deploymentSettings.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d07cf51

Please sign in to comment.