Skip to content

Commit 980b2d9

Browse files
dervoetiTechassi
andauthored
docs: extended Patchable readme (#1348)
* docs: extended patchable readme * Update rust/patchable/README.md Co-authored-by: Techassi <sascha.lautenschlaeger@stackable.tech> * Update rust/patchable/README.md Co-authored-by: Techassi <sascha.lautenschlaeger@stackable.tech> * Update rust/patchable/README.md Co-authored-by: Techassi <sascha.lautenschlaeger@stackable.tech> * Update rust/patchable/README.md Co-authored-by: Techassi <sascha.lautenschlaeger@stackable.tech> * chore: use commit hash with letters --------- Co-authored-by: Techassi <sascha.lautenschlaeger@stackable.tech>
1 parent ed77c62 commit 980b2d9

File tree

1 file changed

+99
-10
lines changed

1 file changed

+99
-10
lines changed

rust/patchable/README.md

Lines changed: 99 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,46 @@ cargo patchable export druid 26.0.0
5959
git status
6060
```
6161

62-
> ![CAUTION]
62+
> [!CAUTION]
6363
> `cargo patchable export` exports whatever is currently checked out (`HEAD`) in the worktree.
6464
> If you use `jj edit` (or `git switch`) then you _must_ go back to the tip before exporting, or
6565
> any patches after that point will be omitted from the export.
6666
67-
### Initialize a new product
67+
### Adding a new product
6868

69-
If you're adding a completely new product, you need to initialize the product-level config once
70-
using patchable:
69+
If you're adding a completely new product, start by creating the product directory with `mkdir product-name`.
70+
Note that you can also create dependencies in subdirectories, like `product-name/my-dependency` or `shared/my-dependency`.
71+
Next, create a `Dockerfile` and a `boil-config.toml` file in that directory.
72+
Then create a fork on GitHub (the default branch, like `main`, is fine - patchable ensures tags for configured versions are mirrored).
73+
74+
Initialize the product-level config by running:
7175

7276
```sh
73-
cargo patchable init product druid \
74-
--upstream https://github.com/apache/druid.git \
75-
--default-mirror https://github.com/stackabletech/druid.git
77+
cargo patchable init product product-name \
78+
--upstream https://github.com/upstream-org/product-name.git \
79+
--default-mirror https://github.com/stackabletech/product-name.git
7680
```
7781

78-
This will create the product-level configuration in `docker-images/druid/stackable/patches/patchable.toml`
79-
containing the following fields:
82+
This will create the product-level configuration in `docker-images/product-name/stackable/patches/patchable.toml` containing the following fields:
8083

8184
- `upstream` - the URL of the upstream repository (such as `https://github.com/apache/druid.git`)
8285
- `default_mirror` - optional: default URL of a mirror repository (such as `https://github.com/stackabletech/druid.git`)
8386

84-
### Initialize a new patch series
87+
Initialize the product version (`base` can be a branch, tag, or commit):
88+
89+
```sh
90+
cargo patchable init version product-name 1.2.3 --base=product-name-1.2.3 --mirror
91+
```
92+
93+
Checkout the source code and switch into the directory with `pushd $(cargo patchable checkout product-name 1.2.3)`.
94+
Create your patches and commit them, then export the patches as .patch files by running:
95+
96+
```sh
97+
popd
98+
cargo patchable export product-name 1.2.3
99+
```
100+
101+
### Adding a new version to an existing product
85102

86103
Patchable stores metadata about each patch series in its version-level config, and will not be able
87104
to check out a patch series that lacks one. It can be generated using the following command:
@@ -99,6 +116,51 @@ with the base commit hash and the default mirror URL from the product-level conf
99116

100117
You can optionally provide the `--ssh` flag to use SSH instead of HTTPS for Git operations.
101118

119+
### Creating a forked dependency
120+
121+
You can use the same patchable workflow for custom dependencies (e.g., Java libraries) as for regular products.
122+
123+
For example, to create a patched version of a Java dependency, start by creating a directory for the dependency with `mkdir -p shared/jackson-dataformat-xml`.
124+
Then create a `Dockerfile` with build instructions and a `boil-config.toml` file in that directory. Create a fork of the dependency on GitHub for mirroring the source code.
125+
126+
Initialize patchable product configuration:
127+
128+
```sh
129+
cargo patchable init product shared/jackson-dataformat-xml \
130+
--upstream https://github.com/FasterXML/jackson-dataformat-xml.git \
131+
--default-mirror https://github.com/stackabletech/jackson-dataformat-xml.git
132+
```
133+
134+
Initialize a specific version:
135+
136+
```sh
137+
cargo patchable init version shared/jackson-dataformat-xml 2.12.7 \
138+
--base=jackson-dataformat-xml-2.12.7 --mirror
139+
```
140+
141+
Create and export patches:
142+
143+
```sh
144+
pushd $(cargo patchable checkout shared/jackson-dataformat-xml 2.12.7)
145+
# Make your changes
146+
git commit -m "Apply security patch"
147+
popd
148+
cargo patchable export shared/jackson-dataformat-xml 2.12.7
149+
```
150+
151+
Use the dependency in other products. For a Java dependency for example it would look like this in the product's `Dockerfile`:
152+
153+
```dockerfile
154+
FROM local-image/shared/jackson-dataformat-xml AS patched-jackson-dataformat-xml
155+
COPY --chown=${STACKABLE_USER_UID}:0 --from=patched-jackson-dataformat-xml /stackable/.m2/repository /stackable/patched-jackson-dataformat-xml-libs
156+
157+
# Copy patched libs into local Maven repository
158+
mkdir -p /stackable/.m2/repository
159+
cp -r /stackable/patched-jackson-dataformat-xml-libs/* /stackable/.m2/repository
160+
```
161+
162+
Now the patched dependency will be used instead of pulling the original one.
163+
102164
### Importing patch series into Patchable
103165

104166
Patchable is stricter about applying invalid patches (both metadata and patches themselves) than Git is.
@@ -169,6 +231,33 @@ Druid 26.0.0 series:
169231
git cherry-pick patchable/26.0.0
170232
```
171233

234+
### Backporting a patch
235+
236+
To backport a specific upstream commit to a product version, first checkout the source code with:
237+
238+
```sh
239+
pushd $(cargo patchable checkout zookeeper 3.9.3)
240+
```
241+
242+
Fetch the upstream commit using:
243+
244+
```sh
245+
git fetch https://github.com/apache/zookeeper 3d6c0d1164dc9ec96a02de383e410b1b0ef64565
246+
```
247+
248+
Then cherry-pick it with:
249+
250+
```sh
251+
git cherry-pick 3d6c0d1
252+
```
253+
254+
Finally, export the patches as .patch files:
255+
256+
```sh
257+
popd
258+
cargo patchable export zookeeper 3.9.3
259+
```
260+
172261
## Notes
173262

174263
- patchable only supports linear patch series (no merges beyond the base commit)

0 commit comments

Comments
 (0)