-
-
Notifications
You must be signed in to change notification settings - Fork 644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specify publish dependencies on deployments #21576
Open
lilatomic
wants to merge
8
commits into
pantsbuild:main
Choose a base branch
from
lilatomic:feature/deployment-publish-dependencies
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
76e4012
add field for specifying dependencies that need to be published
lilatomic 65efc6e
fix test
lilatomic 9a328dd
add tests for depoyment processing publishable dependencies
lilatomic f2a31d2
wire in for providers
lilatomic d3a945a
document using `publish_dependencies` and add release notes
lilatomic 1c84857
document creating a deployable target
lilatomic 2f47e88
directly use DeploymentPublishDependencies
lilatomic f371525
add doc on creating deployable targets
lilatomic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
docs/docs/writing-plugins/common-plugin-tasks/adding-a-deployment.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
--- | ||
title: Adding a Deployment | ||
sidebar_position: 11 | ||
--- | ||
|
||
How to create a custom deployment that is deployed with the `experimental-deploy` goal | ||
|
||
--- | ||
|
||
The `experimental-deploy` goal is experimental. Changes may be sudden, frequent, and breaking. | ||
|
||
This guide will walk you through implementing a target that supports being deployed. The advantage of this over implementing a `run` goal are sandboxed execution and the pre-publishing dependent targets. | ||
|
||
## 1. Create target and fieldsets for the target | ||
|
||
These allow for specifying the target in the BUILD file and referencing its contents | ||
|
||
```python tab={"label": "pants-plugins/my_deployment/target_types.py"} | ||
from dataclasses import dataclass | ||
|
||
from pants.core.goals.deploy import DeployFieldSet, DeploymentPublishDependencies | ||
from pants.engine.target import COMMON_TARGET_FIELDS, Dependencies, DescriptionField, Target | ||
|
||
|
||
# Example for fields your deployment might have | ||
class MyDeploymentDependenciesField(Dependencies): | ||
pass | ||
|
||
|
||
@dataclass(frozen=True) | ||
class MyDeploymentTarget(Target): | ||
alias = "my_deployment" | ||
core_fields = { | ||
*COMMON_TARGET_FIELDS, | ||
DeploymentPublishDependencies, # This enables manually specifying dependencies to publish before deploying | ||
MyDeploymentDependenciesField, | ||
} | ||
|
||
|
||
@dataclass(frozen=True) | ||
class MyDeploymentFieldSet(DeployFieldSet): | ||
required_fields = ( | ||
MyDeploymentDependenciesField, | ||
) | ||
description: DescriptionField | ||
dependencies: MyDeploymentDependenciesField | ||
``` | ||
|
||
## 2. Create a DeployFieldSet subclass | ||
|
||
A subclass of DeployFieldSet will ensure that it has the general fields of a deployment. | ||
|
||
```python tab={"label": "pants-plugins/my_deployment/deploy.py"} | ||
@dataclass(frozen=True) | ||
class DeployMyDeploymentFieldSet(MyDeploymentFieldSet, DeployFieldSet): | ||
pass | ||
``` | ||
|
||
|
||
## 3. Rules to deploy | ||
|
||
Create a rule from the `DeployFieldSet` subclass to `DeployProcess` to actually deploy | ||
|
||
```python tab={"label": "pants-plugins/my_deployment/deploy.py"} | ||
from pants.core.goals.deploy import DeployProcess, DeploySubsystem | ||
from pants.engine.process import InteractiveProcess, Process | ||
from pants.option.global_options import KeepSandboxes | ||
|
||
@rule(desc="Deploy my deployment") | ||
async def run_my_deploy( | ||
field_set: DeployMyDeploymentFieldSet, | ||
deploy_subsystem: DeploySubsystem, | ||
keep_sandboxes: KeepSandboxes, | ||
) -> DeployProcess: | ||
# If your deployment supports dry-run, you can hook into the flag here | ||
if deploy_subsystem.dry_run: | ||
... | ||
else: | ||
... | ||
|
||
deploy_process = InteractiveProcess.from_process( | ||
Process(...), # Implementation of the command invocation | ||
keep_sandboxes=keep_sandboxes | ||
) | ||
|
||
publish_dependencies = ... # you can infer dependencies that need to be published before the deployment | ||
|
||
return DeployProcess( | ||
name=field_set.address.spec, | ||
process=deploy_process, | ||
publish_dependencies=publish_dependencies, # these will be published before the deployment | ||
) | ||
``` | ||
|
||
## 4. Register rules | ||
|
||
At the bottom of the file, let Pants know what your rules and types do. Update your plugin's `register.py` to tell Pants about them. | ||
|
||
```python tab={"label": "pants-plugins/my_deployment/deploy.py"} | ||
from pants.core.goals.deploy import DeployFieldSet | ||
from pants.engine.rules import collect_rules | ||
from pants.engine.unions import UnionRule | ||
|
||
|
||
def rules(): | ||
return ( | ||
*collect_rules(), | ||
UnionRule(DeployFieldSet, DeployMyDeploymentFieldSet) | ||
) | ||
``` | ||
|
||
```python tab={"label": "pants-plugins/my_deployment/register.py"} | ||
from my_deployment import deploy | ||
|
||
def rules(): | ||
return [ | ||
..., | ||
*deploy.rules() | ||
] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't
publish_targets
here be the intersection set of these two other sets?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear how users should use these 2 options. Since every deployment now has it's own
publish_dependencies
, shouldn't we delete the goal'spublish_dependencies
option?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now we're using
--no-experimental-deploy-publish-dependencies
in CI, because we publish docker images in a separate step, so we don't need to do it again indeploy
step. So yes, if these 2 options are going to be used together, we would need the set intersectionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I've missed something. This is how I thought of it
inferred_publish_targets
: targets a backend infers should be published. For example, Helm can infer Docker images that need to be published before this deploymentspecified_publish_targets
: manually specified dependencies that should be published before this deploymentLike for normal dependencies, backends can infer dependencies and users can manually add some. The result should be both of these (set union).
I would think that
--no-experimental-deploy-publish-dependencies
would turn both of these off.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's very confusing because
deploy_subsystem.publish_dependencies
andtarget.publish_dependencies
have the same names but different meaning. It would be much better to change the field name todependencies_to_publish
orruntime_deploy_dependencies
(similar toruntime_package_dependencies
because these dependencies need to be deployed and present at runtime)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
off topic: Personally I don't like the name
runtime_package_dependencies
, and I would preferdependencies_to_package
anddependencies_to_publish
instead