Skip to content

Commit dd0ebb7

Browse files
committed
docs: add pipeline examples
1 parent 6b49676 commit dd0ebb7

2 files changed

Lines changed: 182 additions & 3 deletions

File tree

docs/pages/configuration/pipelines/README.mdx

Lines changed: 176 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Pipelines
33
sidebar_label: pipelines
44
---
55

6+
import Tabs from '@theme/Tabs';
7+
import TabItem from '@theme/TabItem';
68
import ConfigPartialPipeline from '../_partials/v2beta1/pipelines.mdx'
79
import PipelineFunctionRef from '../_partials/functions/reference_pipeline.mdx'
810
import GlobalFunctionRef from '../_partials/functions/reference_global.mdx'
@@ -11,6 +13,179 @@ Pipelines allow you to fully customize the execution logic in DevSpace, i.e. the
1113

1214
Pipelines are defined in POSIX shell syntax and a DevSpace pipeline reads as a regular POSIX script. However, DevSpace implements certain special commands that can be used inside the POSIX script to tell DevSpace when to build, deploy or start developing. For a complete function reference, please take a look below.
1315

16+
17+
Some example pipelines:
18+
<Tabs
19+
defaultValue="configoverride"
20+
values={[
21+
{ label: 'Dynamic Config', value: 'configoverride' },
22+
{ label: 'Execution Order', value: 'executionorder' },
23+
{ label: 'Rerun Pipeline', value: 'rerun' },
24+
{ label: 'Deploy / Sync / Open', value: 'deploywaitsync', },
25+
{ label: 'Dockerfile Flag', value: 'dockerfile', },
26+
]
27+
}>
28+
<TabItem value="configoverride">
29+
30+
```yaml
31+
deployments:
32+
test:
33+
helm:
34+
values:
35+
containers:
36+
- image: nginx
37+
38+
pipelines:
39+
deploy: |-
40+
# You can use the --set, --set-string, --from and --from-file
41+
# arguments to dynamically change the config of the images,
42+
# deployments or dev configurations you want to use inside the
43+
# pipeline.
44+
45+
# Exchange the image in our deployment
46+
if is_equal ${DEVSPACE_NAMESPACE} "test"; then
47+
create_deployments test --set "helm.values.containers[0].image=bitnami/nginx"
48+
fi
49+
50+
# Create a new deployment based on another deployment and change the image.
51+
# This will copy over the values from the test deployment and then change the image
52+
create_deployments nginx --from test \
53+
--set helm.values.containers[0].image=mysql
54+
55+
# Create a new deployment from a file. ${DEVSPACE_TMPDIR} is always cleaned up
56+
# after each run
57+
echo """
58+
helm:
59+
values:
60+
containers:
61+
- image: nginx
62+
""" > ${DEVSPACE_TMPDIR}/my-deployment.yaml
63+
create_deployments nginx-from-file --from-file ${DEVSPACE_TMPDIR}/my-deployment.yaml
64+
65+
# Force the container name to be a string (true) as DevSpace will otherwise convert
66+
# those automatically.
67+
create_deployments nginx-string-annotation --from test \
68+
--set-string "helm.values.containers[0].name=true"
69+
```
70+
71+
</TabItem>
72+
<TabItem value="executionorder">
73+
74+
```yaml
75+
pipelines:
76+
deploy: |-
77+
# Pipelines are a great tool to define your custom execution order of
78+
# building, deploying and starting dev configurations. This works for
79+
# all special commands such as: build_images, create_deployments, start_dev
80+
# run_dependencies and run_pipelines.
81+
82+
# Run two pipelines in parallel
83+
run_pipelines other-pipeline-1 other-pipeline-2
84+
85+
# Wait until all 4 deployments were deployed
86+
echo "All deployments are deployed"
87+
88+
other-pipeline-1: |-
89+
# Deploys deployments deploy-a and deploy-b in parallel
90+
create_deployments deploy-a deploy-b
91+
echo "Deployment deploy-a and deploy-b are deployed"
92+
93+
other-pipeline-2: |-
94+
# Deploys deployments deploy-c and then deploy-d
95+
create_deployments deploy-c
96+
echo "Deployment deploy-c is deployed"
97+
create_deployments deploy-d
98+
echo "Deployment deploy-d is deployed"
99+
100+
101+
deployments:
102+
deploy-a: ...
103+
deploy-b: ...
104+
deploy-c: ...
105+
deploy-d: ...
106+
```
107+
108+
</TabItem>
109+
<TabItem value="rerun">
110+
111+
```yaml
112+
pipelines:
113+
deploy: |-
114+
# This pipeline watches a secret and applies it as well as deploys the application
115+
# Start two pipelines in parallel
116+
run_pipelines watch-secret default-deploy
117+
118+
watch-secret:
119+
# Rerun the pipeline as soon as the secret.yaml changes
120+
run_watch -p secret.yaml -- kubectl apply -n ${DEVSPACE_NAMESPACE} -f secret.yaml
121+
122+
default-deploy: |-
123+
# Run regular deploy pipeline to start the application
124+
run_default_pipeline deploy
125+
126+
deployments: ...
127+
dev: ...
128+
```
129+
130+
</TabItem>
131+
<TabItem value="deploywaitsync">
132+
133+
```yaml
134+
pipelines:
135+
# Run with devspace run-pipeline custom-pipeline
136+
custom-pipeline: |-
137+
# Deploy simple nginx pod with the default DevSpace component chart
138+
create_deployments nginx --set helm.values.containers[0].image=nginx
139+
140+
# Create a file we want to sync to the nginx pod
141+
echo "Hello World!" > ${DEVSPACE_TMPDIR}/index.html
142+
143+
# Sync the file into the nginx pod via DevSpace sync
144+
start_dev nginx --set imageSelector=nginx \
145+
--set "sync[0].path=${DEVSPACE_TMPDIR}:/usr/share/nginx/html" \
146+
--set "sync[0].noWatch=true"
147+
148+
# Print contents within the nginx pod
149+
exec_container --image-selector=nginx -- cat /usr/share/nginx/html/index.html
150+
151+
# Start port-forwarding and open the url
152+
start_dev nginx --set imageSelector=nginx \
153+
--set 'ports[0].port=8080:80' \
154+
--set 'open[0].url=http://localhost:8080'
155+
```
156+
157+
</TabItem>
158+
<TabItem value="dockerfile">
159+
160+
```yaml
161+
images:
162+
my-image:
163+
dockerfile: ./Dockerfile
164+
165+
pipelines:
166+
# Executed on 'devspace deploy'
167+
deploy:
168+
flags:
169+
- name: dockerfile
170+
description: If enabled, will build the image with the given dockerfile
171+
type: string
172+
run: |-
173+
if ! is_empty $(get_flag dockerfile); then
174+
echo "Building the image with the overriden dockerfile $(get_flag dockerfile)"
175+
run_default_pipeline deploy --set "images.my-image.dockerfile=$(get_flag dockerfile)"
176+
else
177+
run_default_pipeline deploy
178+
fi
179+
```
180+
181+
</TabItem>
182+
</Tabs>
183+
184+
185+
186+
187+
188+
14189
## Using Pipelines
15190
16191
### 1. Define Pipelines
@@ -53,7 +228,7 @@ Write all pipeline scrips in `bash` fashion. DevSpace is using a library to make
53228

54229

55230
## Default Pipelines
56-
DevSpace provides default pipeline scripts for the following top-level commands:
231+
Internally DevSpace uses pipelines for the following commands that can be overriden according to your preferences. DevSpace provides default pipeline scripts for the following top-level commands:
57232
- [`devspace dev`](#dev)
58233
- [`devspace deploy`](#deploy)
59234
- [`devspace build`](#build)

docs/pages/configuration/variables.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,19 @@ A common use case for the `.env` file is to set default flags for the `devspace`
164164
- `DEVSPACE_[COMMAND]_FLAGS` to add default flags for single commands (e.g. `DEVSPACE_DEV_FLAGS=-s --verbose-dependencies`)
165165

166166
```bash title="File: .env"
167-
DEVSPACE_FLAGS=-s -p dev
167+
DEVSPACE_FLAGS=-s -n default-namespace
168168
DEVSPACE_DEV_FLAGS=-s --verbose-dependencies
169169
```
170170

171171
:::note Overwrite Default Flags
172172
Specifying flags for a command will overwrite the default flags, e.g. if `DEVSPACE_FLAGS=-s -p dev` is configured and you run `devspace dev -p production`, the following command would be executed: `devspace dev -s -p production`
173173
:::
174174

175-
175+
You can also use these default flags without a specialized `.env` file in a regular `devspace.yaml`:
176+
```
177+
vars:
178+
DEVSPACE_FLAGS: '-n my-default-namespace'
179+
```
176180

177181
## Useful Commands
178182

0 commit comments

Comments
 (0)