Skip to content

Commit 525f607

Browse files
committed
hooks: update deploy docs
1 parent 1734f56 commit 525f607

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

docs/content/en/docs/pipeline-stages/lifecycle-hooks.md

+40-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,24 @@ build:
6464
```
6565
This config snippet defines that `hook.sh` (for `darwin` or `linux` OS) or `hook.bat` (for `windows` OS) will be executed `before` and `after` each file sync operation for artifact `hooks-example`.
6666

67-
### `before-deploy` and `after-deploy` (_to be implemented_)
67+
### `before-deploy` and `after-deploy` (only for `kubectl` deployer)
68+
69+
Example: _skaffold.yaml_ snippet
70+
```yaml
71+
deploy:
72+
kubectl:
73+
manifests:
74+
- deployment.yaml
75+
hooks:
76+
before:
77+
- host:
78+
command: ["sh", "-c", "echo pre-deploy host hook running on $(hostname)!"]
79+
os: [darwin, linux]
80+
after:
81+
- host:
82+
command: ["sh", "-c", "echo post-deploy host hook running on $(hostname)!"]
83+
```
84+
This config snippet defines a simple `echo` command to run before and after each `kubectl` deploy.
6885

6986
### Environment variables
7087

@@ -110,4 +127,25 @@ build:
110127
```
111128
This config snippet defines a command to run inside the container corresponding to the artifact `hooks-example` image, `before` and `after` each file sync operation.
112129

113-
### `before-deploy` and `after-deploy` (_to be implemented_)
130+
### `before-deploy` and `after-deploy` (only for `kubectl` deployer)
131+
132+
Example: _skaffold.yaml_ snippet
133+
```yaml
134+
deploy:
135+
kubectl:
136+
manifests:
137+
- deployment.yaml
138+
hooks:
139+
before:
140+
- container:
141+
# this will only run when there's a matching container from a previous deploy iteration like in `skaffold dev`
142+
command: ["sh", "-c", "echo pre-deploy container hook running on $(hostname)!"]
143+
containerName: hooks-example*
144+
podName: hooks-example-deployment*
145+
after:
146+
- container:
147+
command: ["sh", "-c", "echo post-deploy container hook running on $(hostname)!"]
148+
containerName: hooks-example* # use a glob pattern to prefix-match the container name and pod name for deployments, stateful-sets, etc.
149+
podName: hooks-example-deployment*
150+
```
151+
This config snippet defines a simple `echo` command to run inside the containers that match `podName` and `containerName`, before and after each `kubectl` deploy. The `after` container commands are only run post [healthchecks]({{< relref "/docs/workflows/ci-cd.md#waiting-for-skaffold-deployments-using-healthcheck" >}}) on the deployment are complete. Also, unlike the `sync` container hooks, skaffold cannot determine the target container from just the config definition, and needs the `podName` and `containerName`.

0 commit comments

Comments
 (0)