Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
177 changes: 176 additions & 1 deletion docs/pages/configuration/pipelines/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ title: Pipelines
sidebar_label: pipelines
---

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

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.


Some example pipelines:
<Tabs
defaultValue="configoverride"
values={[
{ label: 'Dynamic Config', value: 'configoverride' },
{ label: 'Execution Order', value: 'executionorder' },
{ label: 'Rerun Pipeline', value: 'rerun' },
{ label: 'Deploy / Sync / Open', value: 'deploywaitsync', },
{ label: 'Dockerfile Flag', value: 'dockerfile', },
]
}>
<TabItem value="configoverride">

```yaml
deployments:
test:
helm:
values:
containers:
- image: nginx

pipelines:
deploy: |-
# You can use the --set, --set-string, --from and --from-file
# arguments to dynamically change the config of the images,
# deployments or dev configurations you want to use inside the
# pipeline.

# Exchange the image in our deployment
if is_equal ${DEVSPACE_NAMESPACE} "test"; then
create_deployments test --set "helm.values.containers[0].image=bitnami/nginx"
fi

# Create a new deployment based on another deployment and change the image.
# This will copy over the values from the test deployment and then change the image
create_deployments nginx --from test \
--set helm.values.containers[0].image=mysql

# Create a new deployment from a file. ${DEVSPACE_TMPDIR} is always cleaned up
# after each run
echo """
helm:
values:
containers:
- image: nginx
""" > ${DEVSPACE_TMPDIR}/my-deployment.yaml
create_deployments nginx-from-file --from-file ${DEVSPACE_TMPDIR}/my-deployment.yaml

# Force the container name to be a string (true) as DevSpace will otherwise convert
# those automatically.
create_deployments nginx-string-annotation --from test \
--set-string "helm.values.containers[0].name=true"
```

</TabItem>
<TabItem value="executionorder">

```yaml
pipelines:
deploy: |-
# Pipelines are a great tool to define your custom execution order of
# building, deploying and starting dev configurations. This works for
# all special commands such as: build_images, create_deployments, start_dev
# run_dependencies and run_pipelines.

# Run two pipelines in parallel
run_pipelines other-pipeline-1 other-pipeline-2

# Wait until all 4 deployments were deployed
echo "All deployments are deployed"

other-pipeline-1: |-
# Deploys deployments deploy-a and deploy-b in parallel
create_deployments deploy-a deploy-b
echo "Deployment deploy-a and deploy-b are deployed"

other-pipeline-2: |-
# Deploys deployments deploy-c and then deploy-d
create_deployments deploy-c
echo "Deployment deploy-c is deployed"
create_deployments deploy-d
echo "Deployment deploy-d is deployed"


deployments:
deploy-a: ...
deploy-b: ...
deploy-c: ...
deploy-d: ...
```

</TabItem>
<TabItem value="rerun">

```yaml
pipelines:
deploy: |-
# This pipeline watches a secret and applies it as well as deploys the application
# Start two pipelines in parallel
run_pipelines watch-secret default-deploy

watch-secret:
# Rerun the pipeline as soon as the secret.yaml changes
run_watch -p secret.yaml -- kubectl apply -n ${DEVSPACE_NAMESPACE} -f secret.yaml

default-deploy: |-
# Run regular deploy pipeline to start the application
run_default_pipeline deploy

deployments: ...
dev: ...
```

</TabItem>
<TabItem value="deploywaitsync">

```yaml
pipelines:
# Run with devspace run-pipeline custom-pipeline
custom-pipeline: |-
# Deploy simple nginx pod with the default DevSpace component chart
create_deployments nginx --set helm.values.containers[0].image=nginx

# Create a file we want to sync to the nginx pod
echo "Hello World!" > ${DEVSPACE_TMPDIR}/index.html

# Sync the file into the nginx pod via DevSpace sync
start_dev nginx --set imageSelector=nginx \
--set "sync[0].path=${DEVSPACE_TMPDIR}:/usr/share/nginx/html" \
--set "sync[0].noWatch=true"

# Print contents within the nginx pod
exec_container --image-selector=nginx -- cat /usr/share/nginx/html/index.html

# Start port-forwarding and open the url
start_dev nginx --set imageSelector=nginx \
--set 'ports[0].port=8080:80' \
--set 'open[0].url=http://localhost:8080'
```

</TabItem>
<TabItem value="dockerfile">

```yaml
images:
my-image:
dockerfile: ./Dockerfile

pipelines:
# Executed on 'devspace deploy'
deploy:
flags:
- name: dockerfile
description: If enabled, will build the image with the given dockerfile
type: string
run: |-
if ! is_empty $(get_flag dockerfile); then
echo "Building the image with the overriden dockerfile $(get_flag dockerfile)"
run_default_pipeline deploy --set "images.my-image.dockerfile=$(get_flag dockerfile)"
else
run_default_pipeline deploy
fi
```

</TabItem>
</Tabs>






## Using Pipelines

### 1. Define Pipelines
Expand Down Expand Up @@ -53,7 +228,7 @@ Write all pipeline scrips in `bash` fashion. DevSpace is using a library to make


## Default Pipelines
DevSpace provides default pipeline scripts for the following top-level commands:
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:
- [`devspace dev`](#dev)
- [`devspace deploy`](#deploy)
- [`devspace build`](#build)
Expand Down
8 changes: 6 additions & 2 deletions docs/pages/configuration/variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,19 @@ A common use case for the `.env` file is to set default flags for the `devspace`
- `DEVSPACE_[COMMAND]_FLAGS` to add default flags for single commands (e.g. `DEVSPACE_DEV_FLAGS=-s --verbose-dependencies`)

```bash title="File: .env"
DEVSPACE_FLAGS=-s -p dev
DEVSPACE_FLAGS=-s -n default-namespace
DEVSPACE_DEV_FLAGS=-s --verbose-dependencies
```

:::note Overwrite Default Flags
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`
:::


You can also use these default flags without a specialized `.env` file in a regular `devspace.yaml`:
```
vars:
DEVSPACE_FLAGS: '-n my-default-namespace'
```

## Useful Commands

Expand Down