Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ description: >

`SCRIPT_RUN` stage is one stage in the pipeline and you can execute any commands.

> Note: This feature is at the alpha status.
> Note: This feature is at the alpha status and only for the application kind of KubernetesApp.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> Note: This feature is at the alpha status and only for the application kind of KubernetesApp.
> Note: This feature is at the alpha status and currently only for the application kind of KubernetesApp.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khanhtc1202
Thank you! Forgot to add it 🙏
Added :) 3714161


## How to configure SCRIPT_RUN stage

Add a `SCRIPT_RUN` to your pipeline and write commands.
The commands run in the directory where this application configuration file exists.

```yaml
apiVersion: pipecd.dev/v1beta1
Expand Down Expand Up @@ -49,19 +48,77 @@ spec:
sleep 10
```

You can define the command as `run`.
Also, if you want to some values as variables, you can define them as `env`.

The commands run in the directory where this application configuration file exists.

![](/images/script-run.png)

Note:
1. You can use `SCRIPT_RUN` stage with any current supporting application kind.
# When to rollback

You can define the command as `onRollback` to execute when to rollback similar to `run`.
Execute the command to rollback SCRIPT_RUN to the point where the deployment was canceled or failed.

```yaml
apiVersion: pipecd.dev/v1beta1
kind: KubernetesApp
spec:
name: canary-with-script-run
labels:
env: example
team: product
pipeline:
stages:
- name: K8S_CANARY_ROLLOUT
with:
replicas: 10%
- name: WAIT
with:
duration: 10s
- name: SCRIPT_RUN
with:
env:
MSG: "execute script1"
R_MSG: "rollback script1"
run: |
echo $MSG
sleep 10
onRollback: |
echo $R_MSG
sleep 10
- name: K8S_PRIMARY_ROLLOUT
- name: K8S_CANARY_CLEAN
```

![](/images/script-run-onRollback.png)

The command defined as `onRollback` is executed as `SCRIPT_RUN_ROLLBACK` stage after each `ROLLBACK` stage.

When there are multiple SCRIPT_RUN stages, they are executed in the same order as SCRIPT_RUN on the pipeline.
Also, only for the executed SCRIPT_RUNs are rollbacked.

For example, consider when deployment proceeds in the following order from 1 to 7.
```
1. K8S_CANARY_ROLLOUT
2. WAIT
3. SCRIPT_RUN
4. K8S_PRIMARY_ROLLOUT
5. SCRIPT_RUN
6. K8S_CANARY_CLEAN
7. SCRIPT_RUN
```

Then
- If 3 is canceled or fails while running, only SCRIPT_RUN of 3 will be rollbacked.
- If 4 is canceled or fails while running, only SCRIPT_RUN of 3 will be rollbacked.
- If 6 is canceled or fails while running, only SCRIPT_RUNs 3 and 5 will be rollbacked. The order of executing is 3 -> 5.

# Note
1. You can use `SCRIPT_RUN` stage with only the application kind of `KubernetesApp`. Soon we will implement it. for other application kinds.

2. The public piped image available in PipeCD main repo (ref: [Dockerfile](https://github.com/pipe-cd/pipecd/blob/master/cmd/piped/Dockerfile)) is based on [alpine](https://hub.docker.com/_/alpine/) and only has a few UNIX command available (ref: [piped-base Dockerfile](https://github.com/pipe-cd/pipecd/blob/master/tool/piped-base/Dockerfile)). If you want to use your commands, you can:

- Prepare your own environment container image then add [piped binary](https://github.com/pipe-cd/pipecd/releases) to it.
- Build your own container image based on `ghcr.io/pipe-cd/piped` image.
- Manually update your running piped container (not recommended).

# When to rollback

Even if a rollback occurs, the command will not be executed again.
In the near future, we are considering the ability to run this command also on rollback.
Binary file added docs/static/images/script-run-onRollback.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions examples/kubernetes/script-run/app.pipecd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: pipecd.dev/v1beta1
kind: KubernetesApp
spec:
name: script-run
labels:
env: example
team: product
pipeline:
stages:
- name: K8S_CANARY_ROLLOUT
with:
replicas: 10%
- name: WAIT
with:
duration: 10s
- name: SCRIPT_RUN
with:
env:
MSG: "execute script1"
R_MSG: "rollback script1"
run: |
echo $MSG
sleep 10
onRollback: |
echo $R_MSG
sleep 10
- name: K8S_PRIMARY_ROLLOUT
- name: K8S_CANARY_CLEAN
26 changes: 26 additions & 0 deletions examples/kubernetes/script-run/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: script-run
labels:
app: script-run
spec:
replicas: 2
revisionHistoryLimit: 2
selector:
matchLabels:
app: script-run
pipecd.dev/variant: primary
template:
metadata:
labels:
app: script-run
pipecd.dev/variant: primary
spec:
containers:
- name: helloworld
image: gcr.io/pipecd/helloworld:v0.45.0
args:
- server
ports:
- containerPort: 9085
11 changes: 11 additions & 0 deletions examples/kubernetes/script-run/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: script-run
spec:
selector:
app: script-run
ports:
- protocol: TCP
port: 9085
targetPort: 9085