Skip to content

Commit

Permalink
Add doc for exec command to command refernce deploy
Browse files Browse the repository at this point in the history
Signed-off-by: Parthvi Vala <pvala@redhat.com>
  • Loading branch information
valaparthvi committed Mar 23, 2023
1 parent d0e4348 commit 37214f0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
26 changes: 19 additions & 7 deletions docs/website/docs/command-reference/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ necessary to deploy the components.
When running the command `odo deploy`, `odo` searches for the default command of kind `deploy` in the devfile, and executes this command.
The kind `deploy` is supported by the devfile format starting from version 2.2.0.

The `deploy` command is typically a *composite* command, composed of several *apply* commands:
- a command referencing an `image` component that, when applied, will build the image of the container to deploy, and push it to its registry,
- a command referencing a [`kubernetes` component](https://devfile.io/docs/2.2.0/defining-kubernetes-resources) that, when applied, will create a Kubernetes resource in the cluster.
The `deploy` command is typically a *composite* command, composed of several *apply* and *exec* commands:
- an `apply` command referencing an `image` component that, when applied, will build the image of the container to deploy, and push it to its registry,
- an `apply` command referencing a [`kubernetes` component](https://devfile.io/docs/2.2.0/defining-kubernetes-resources) that, when applied, will create a Kubernetes resource in the cluster.
- an `exec` command referencing a container component that, when applied, will run the command defined by `commandLine` inside a container started by a Kubernetes Job; read more about it [here](../development/devfile#how-odo-runs-exec-commands-in-deploy-mode).

With the following example `devfile.yaml` file, a container image will be built by using the `Dockerfile` present in the directory,
- With the following example `devfile.yaml` file, a container image will be built by using the `Dockerfile` present in the directory,
the image will be pushed to its registry and a Kubernetes Deployment will be created in the cluster, using this freshly built image.

```
Expand All @@ -28,11 +29,16 @@ commands:
- id: deployk8s
apply:
component: outerloop-deploy
- id: deploy-db
exec:
commandLine: helm repo add bitnami https://charts.bitnami.com/bitnami && helm install my-db bitnami/postgresql
component: tools
- id: deploy
composite:
commands:
- build-image
- deployk8s
- deploy-db
group:
kind: deploy
isDefault: true
Expand Down Expand Up @@ -63,6 +69,9 @@ components:
containers:
- name: main
image: {{CONTAINER_IMAGE}}
- name: tools
container:
image: quay.io/tkral/devbox-demo-devbox
```

:::note
Expand All @@ -88,7 +97,7 @@ $ odo deploy
/ \__/ odo version: v3.0.0-rc1
\__/

↪ Building & Pushing Container: quay.io/pvala18/myimage
↪ Building & Pushing Container: quay.io/phmartin/myimage
• Building image locally ...
STEP 1/7: FROM quay.io/phmartin/node:17
STEP 2/7: WORKDIR /usr/src/app
Expand All @@ -105,9 +114,9 @@ STEP 5/7: COPY . .
STEP 6/7: EXPOSE 8080
--> 9892b562a8a
STEP 7/7: CMD [ "node", "server.js" ]
COMMIT quay.io/pvala18/myimage
COMMIT quay.io/phmartin/myimage
--> 7578e3e3667
Successfully tagged quay.io/pvala18/myimage:latest
Successfully tagged quay.io/phmartin/myimage:latest
7578e3e36676418853c579063dd190c9d736114ca414e28c8646880b446a1618
✓ Building image locally [2s]
• Pushing image to container registry ...
Expand All @@ -125,6 +134,9 @@ Storing signatures
↪ Deploying Kubernetes Component: my-component
✓ Creating kind Deployment

↪ Executing command:
✓ Executing command in container (command: deploy-db) [12s]

Your Devfile has been successfully deployed

```
Expand Down
11 changes: 5 additions & 6 deletions docs/website/docs/development/devfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ The order in which the commands are ran for `odo dev` are:

When `odo deploy` is executed, we use: `deploy`.

These commands are typically tied to Kubernetes or OpenShift inline resources. They are defined as a component. However, you can use `container` or `image` components as well under the deploy group.
These commands are typically tied to Kubernetes or OpenShift inline resources. They are defined as a component. However, you can use `container` or `image` components as well under the `deploy` group.

The most common deploy scenario is the following:
1. Use the `image` component to build a container
Expand All @@ -93,19 +93,16 @@ The most common deploy scenario is the following:
### How odo runs exec commands in Deploy mode
```yaml
commands:
- exec:
- id: deploy-db
exec:
commandLine: |
helm repo add bitnami https://charts.bitnami.com/bitnami && \
helm install my-db bitnami/postgresql
component: runtime
id: deploy-db
- id: deploy
composite:
commands:
- app-image
- deploy-pvc
- deploy-service
- deploy-route
- deploy-app
- deploy-db
group:
Expand All @@ -125,7 +122,9 @@ components:
```

In the example above, `exec` command is a part of the composite deploy command.

Every `exec` command must correspond to a container component command.

`exec` command can be used to execute any command, which makes it possible to use tools such as [Helm](https://helm.sh/), [Kustomize](https://kustomize.io/), etc. in the development workflow with odo, given that the binary is made available by the image of the container component that is referenced by the command.

Commands defined by the `exec` command are run inside a container started by a [Kubernetes Job](https://kubernetes.io/docs/concepts/workloads/controllers/job/). Every `exec` command references a Devfile container component. `odo` makes use of this container component definition to define the Kubernetes Job.
Expand Down

0 comments on commit 37214f0

Please sign in to comment.