2022-02-14 16:09:53 +01:00
---
2022-03-31 15:53:25 +02:00
slug: /1200/local-dev
2022-04-13 15:58:51 +02:00
displayed_sidebar: '0.2'
2022-02-14 16:09:53 +01:00
---
# CI/CD in your local dev
2022-03-28 11:54:12 +02:00
Everyone should be able to develop, test and run their CI/CD pipeline locally.
Having to commit & push in order to test a change slows down iteration.
2022-02-14 16:09:53 +01:00
This guide shows you the Dagger way.
2022-03-09 16:23:29 +01:00
Within 5 minutes, you will have a local CI/CD loop and run your first test & build pipeline.
2022-02-14 16:09:53 +01:00
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
2022-03-24 19:55:24 +01:00
import BrowserOnly from '@docusaurus/BrowserOnly';
2022-02-14 16:09:53 +01:00
2022-03-24 19:55:24 +01:00
< BrowserOnly >
{() =>
2022-03-23 17:59:39 +01:00
< Tabs defaultValue = {
2022-03-23 19:32:08 +01:00
window.navigator.userAgent.indexOf('Linux') != -1 ? 'linux':
window.navigator.userAgent.indexOf('Win') != -1 ? 'windows':
'macos'}
2022-02-14 16:09:53 +01:00
groupId="os"
values={[
{label: 'macOS', value: 'macos'}, {label: 'Linux', value: 'linux'}, {label: 'Windows', value: 'windows'},
]}>
< TabItem value = "macos" >
We assume that you have [Homebrew ](https://brew.sh/ ) installed.
If you do, you can install `dagger` with a single command:
```shell
brew install dagger/tap/dagger
```
2022-04-13 19:46:00 +02:00
This installs `dagger` in:
2022-02-14 16:09:53 +01:00
```shell
type dagger
2022-04-13 19:46:00 +02:00
# macOS ARM:
2022-02-14 16:09:53 +01:00
dagger is /opt/homebrew/bin/dagger
2022-04-13 19:46:00 +02:00
# macOS Intel:
dagger is /usr/local/bin/dagger
2022-02-14 16:09:53 +01:00
```
2022-03-17 20:45:26 +01:00
If you do not have Homebrew installed, or you want to install a specific version of `dagger` , you can run:
```shell
2022-03-29 20:41:59 +02:00
curl -L https://dl.dagger.io/dagger/install.sh | DAGGER_VERSION=0.2.4 sh
2022-03-17 20:45:26 +01:00
./bin/dagger version
2022-03-29 20:41:59 +02:00
dagger 0.2.4 (GIT_SHA) darwin/arm64
2022-03-17 20:45:26 +01:00
```
2022-03-09 16:23:29 +01:00
Before we can build & test our example app with `dagger` , we need to have Docker running.
2022-02-14 16:09:53 +01:00
You most likely already have Docker set up.
If not, [Docker Desktop ](https://www.docker.com/products/docker-desktop ) makes this easy.
2022-03-17 20:45:26 +01:00
With Docker running, we are ready to download our example app and run its CI/CD pipeline locally:
2022-02-14 16:09:53 +01:00
```shell
2022-03-09 16:23:29 +01:00
git clone https://github.com/dagger/dagger
cd dagger
2022-03-29 20:41:59 +02:00
git checkout v0.2.4
2022-03-09 16:23:29 +01:00
cd pkg/universe.dagger.io/examples/todoapp
dagger do build
2022-02-14 16:09:53 +01:00
```
2022-03-09 16:23:29 +01:00
With an empty cache, installing all dependencies, then testing & generating a build for this example app completes in just under 3 minutes:
2022-02-14 16:09:53 +01:00
```shell
2022-03-25 17:55:23 +01:00
[✔] client.filesystem."./".read 0.1s
2022-03-09 16:23:29 +01:00
[✔] actions.deps 118.8s
[✔] actions.test.script 0.1s
[✔] actions.test 6.3s
[✔] actions.build.run.script 0.0s
[✔] actions.build.run 43.7s
[✔] actions.build.contents 0.4s
2022-03-25 17:55:23 +01:00
[✔] client.filesystem."./_build".write 0.1s
2022-02-14 16:09:53 +01:00
```
2022-03-09 16:23:29 +01:00
Since this is a static application, we can open the files which are generated in `actions.build.contents` in a browser.
2022-03-25 17:55:23 +01:00
The last step - `client.filesystem.build.write` - copies the build result into the `_build` directory on the host.
2022-03-17 20:45:26 +01:00
2022-03-25 17:55:23 +01:00
On macOS, we run `open _build/index.html` in our terminal and see the following app preview:
2022-02-14 16:09:53 +01:00
2022-03-17 20:45:26 +01:00
![todoapp preview ](/img/getting-started/todoapp.macos.png )
2022-02-14 16:09:53 +01:00
2022-03-09 16:23:29 +01:00
One of the big advantages to this approach is that we did not have to install any dependencies specific to this application.
Dagger managed all the intermediary steps, and we ended up with the end-result on our host, without any of the transient dependencies.
2022-02-14 16:09:53 +01:00
Now that we have everything running locally, let us make a change and get a feel for our local CI/CD loop.
The quicker we can close this loop, the quicker we can learn what actually works.
2022-03-09 16:23:29 +01:00
With Dagger, we can close this loop locally, without committing and pushing our changes.
And since every action is cached, subsequent runs will be quicker.
2022-02-14 16:09:53 +01:00
2022-03-09 16:23:29 +01:00
In the todoapp directory, edit line `25` of `src/components/Form.js` and save the file.
2022-02-14 16:09:53 +01:00
2022-03-09 16:23:29 +01:00
I change this line to `What must be done today?` and run the build locally again:
2022-02-14 16:09:53 +01:00
```shell
2022-03-09 16:23:29 +01:00
dagger do build
2022-03-25 17:55:23 +01:00
[✔] client.filesystem."./".read 0.0s
2022-03-22 21:24:48 +01:00
[✔] actions.deps 7.5s
2022-03-09 16:23:29 +01:00
[✔] actions.test.script 0.0s
2022-03-22 21:24:48 +01:00
[✔] actions.test 6.0s
2022-03-09 16:23:29 +01:00
[✔] actions.build.run.script 0.0s
2022-03-22 21:24:48 +01:00
[✔] actions.build.run 29.2s
[✔] actions.build.contents 0.0s
2022-03-25 17:55:23 +01:00
[✔] client.filesystem."./_build".write 0.1s
2022-02-14 16:09:53 +01:00
```
2022-03-22 21:24:48 +01:00
The total `42.8` time is macOS specific, since the Linux alternative is more than 8x quicker.
2022-03-09 16:23:29 +01:00
Either way, this local test & build loop is likely to change our approach to iterating on changes.
2022-02-14 16:09:53 +01:00
It becomes even more obvious when the change is not as straightforward as knowing _exactly_ which line to edit.
< / TabItem >
< TabItem value = "linux" >
2022-03-17 20:45:26 +01:00
The quickest way of installing `dagger` on Linux is to run the following command:
```shell
cd /usr/local
curl -L https://dl.dagger.io/dagger/install.sh | sh
```
2022-02-14 16:09:53 +01:00
2022-03-17 20:45:26 +01:00
This installs `dagger` in `/usr/local/bin` :
2022-02-14 16:09:53 +01:00
```shell
type dagger
dagger is /usr/local/bin/dagger
```
2022-03-17 20:45:26 +01:00
If you want to install dagger to a different location, `cd` where you want `./bin/dagger` in.
If you want to install a specific version of `dagger` , you can run:
```shell
2022-03-29 20:41:59 +02:00
curl -L https://dl.dagger.io/dagger/install.sh | DAGGER_VERSION=0.2.4 sh
2022-03-17 20:45:26 +01:00
./bin/dagger version
2022-03-29 20:41:59 +02:00
dagger 0.2.4 (GIT_SHA) linux/amd64
2022-03-17 20:45:26 +01:00
```
2022-02-14 16:09:53 +01:00
Before we can build, test & deploy our example app with `dagger` , we need to have Docker Engine running.
You most likely already have Docker Engine set up.
2022-03-17 20:45:26 +01:00
If not, [install Docker Engine on Linux ](https://docs.docker.com/engine/install/#server ) makes this easy.
2022-03-09 16:23:29 +01:00
With Docker Engine running, we are ready to download our example app and run its CI/CD pipeline:
2022-02-14 16:09:53 +01:00
```shell
2022-03-09 16:23:29 +01:00
git clone https://github.com/dagger/dagger
cd dagger
2022-03-29 20:41:59 +02:00
git checkout v0.2.4
2022-03-09 16:23:29 +01:00
cd pkg/universe.dagger.io/examples/todoapp
dagger do build
2022-02-14 16:09:53 +01:00
```
2022-03-09 16:23:29 +01:00
With an empty cache, installing all dependencies, then testing & generating a build for this example app completes in just under 1 minute:
2022-02-14 16:09:53 +01:00
```shell
2022-03-25 17:55:23 +01:00
[✔] client.filesystem."./".read 0.3s
2022-03-09 16:23:29 +01:00
[✔] actions.deps 39.7s
[✔] actions.test.script 0.2s
[✔] actions.test 1.9s
[✔] actions.build.run.script 0.1s
[✔] actions.build.run 10.0s
[✔] actions.build.contents 0.6s
2022-03-25 17:55:23 +01:00
[✔] client.filesystem."./_build".write 0.1s
2022-02-14 16:09:53 +01:00
```
2022-03-09 16:23:29 +01:00
Since this is a static application, we can open the files which are generated in `actions.build.contents` in a browser.
2022-03-25 17:55:23 +01:00
The last step - `client.filesystem.build.write` - copies the build result into the `_build` directory on the host.
2022-03-17 20:45:26 +01:00
2022-03-25 17:55:23 +01:00
On Linux, we run `xdg-open _build/index.html` in our terminal and see the following app preview:
2022-02-14 16:09:53 +01:00
2022-03-17 20:45:26 +01:00
![todoapp preview ](/img/getting-started/todoapp.linux.png )
2022-02-14 16:09:53 +01:00
2022-03-09 16:23:29 +01:00
One of the big advantages to this approach is that we did not have to install any dependencies specific to this application.
Dagger managed all the intermediary steps, and we ended up with the end-result on our host, without any of the transient dependencies.
2022-02-14 16:09:53 +01:00
Now that we have everything running locally, let us make a change and get a feel for our local CI/CD loop.
The quicker we can close this loop, the quicker we can learn what actually works.
2022-03-09 16:23:29 +01:00
With Dagger, we can close this loop locally, without committing and pushing our changes.
And since every action is cached, subsequent runs will be quicker.
2022-02-14 16:09:53 +01:00
2022-03-09 16:23:29 +01:00
In the todoapp directory, edit line `25` of `src/components/Form.js` and save the file.
2022-02-14 16:09:53 +01:00
2022-03-09 16:23:29 +01:00
I change this line to `What must be done today?` and run the build locally again:
2022-02-14 16:09:53 +01:00
```shell
2022-03-09 16:23:29 +01:00
dagger do build
2022-03-25 17:55:23 +01:00
[✔] client.filesystem."./".read 0.0s
2022-03-22 20:47:01 +01:00
[✔] actions.deps 1.1s
2022-03-09 16:23:29 +01:00
[✔] actions.test.script 0.0s
2022-03-22 20:47:01 +01:00
[✔] actions.test 0.0s
[✔] actions.build.run.script 0.8s
[✔] actions.build.run 2.9s
[✔] actions.build.contents 0.0s
2022-03-25 17:55:23 +01:00
[✔] client.filesystem."./_build".write 0.0s
2022-02-14 16:09:53 +01:00
```
2022-03-22 20:47:01 +01:00
Being able to re-run the test & build loop locally in `4.8s` , at the same speed as running `yarn` scripts locally and without adding any extra dependencies to our host, is likely to change our approach to iterating on changes.
2022-02-14 16:09:53 +01:00
It becomes even more obvious when the change is not as straightforward as knowing _exactly_ which line to edit.
< / TabItem >
< TabItem value = "windows" >
2022-04-01 01:39:39 +02:00
From a powershell terminal, run:
2022-02-14 16:09:53 +01:00
```shell
2022-04-01 01:39:39 +02:00
Invoke-WebRequest -UseBasicParsing -Uri https://dl.dagger.io/dagger/install.ps1 | Invoke-Expression
2022-02-14 16:09:53 +01:00
```
2022-04-13 15:58:51 +02:00
We'll save everything under `<your home folder>/dagger`
2022-02-14 16:09:53 +01:00
2022-03-11 01:51:41 +01:00
Check that `dagger` is installed correctly by opening a `Command Prompt` terminal and run:
2022-02-14 16:09:53 +01:00
```shell
where dagger
C:\<your home folder>\dagger.exe
```
2022-03-11 01:51:41 +01:00
Before we can build & test our example app with `dagger` , we need to have Docker running.
You most likely already have Docker set up.
If not, [Docker Desktop ](https://www.docker.com/products/docker-desktop ) makes this easy.
With Docker running, we are ready to download our example app and run its CI/CD pipeline.
Still in your `Command Prompt` terminal:
```shell
2022-04-05 00:16:29 +02:00
git clone -c core.symlinks=true https://github.com/dagger/dagger
2022-03-11 01:51:41 +01:00
cd dagger
2022-03-29 20:41:59 +02:00
git checkout v0.2.4
2022-03-11 01:51:41 +01:00
cd pkg/universe.dagger.io/examples/todoapp
dagger do build
```
2022-04-05 00:16:29 +02:00
:::tip
By default, git on Windows does not automatically convert posix symbolic links, which explains the extra option `core.symlinks=true` while cloning the repository.
But you can also enable this once and for all in your git configuration, by running the following command from a Powershell terminal: `git config --global core.symlinks true` .
:::
2022-03-11 01:51:41 +01:00
With an empty cache, installing all dependencies, then testing & generating a build for this example app completes in just under a minute:
```shell
2022-03-24 16:52:17 +01:00
[✔] actions.deps 62.1s
[✔] actions.build.run.script 0.4s
[✔] actions.test.script 0.5s
2022-03-25 17:55:23 +01:00
[✔] client.filesystem."./".read 0.6s
2022-03-24 16:52:17 +01:00
[✔] actions.test 2.0s
[✔] actions.build.run 12.4s
[✔] actions.build.contents 0.1s
2022-03-25 17:55:23 +01:00
[✔] client.filesystem."./_build".write 0.2s
2022-03-11 01:51:41 +01:00
```
Since this is a static application, we can open the files which are generated in `actions.build.contents` in a browser.
2022-03-25 17:55:23 +01:00
The last step - `client.filesystem.build.write` - copies the build result into the `_build` directory on the host.
2022-03-17 20:45:26 +01:00
2022-03-31 13:42:07 +02:00
On Windows, we run `start _build/index.html` in our `Command Prompt` terminal and see the following app preview:
2022-03-11 01:51:41 +01:00
2022-03-17 20:45:26 +01:00
![todoapp preview ](/img/getting-started/todoapp.macos.png )
2022-03-11 01:51:41 +01:00
One of the big advantages to this approach is that we did not have to install any dependencies specific to this application.
Dagger managed all the intermediary steps, and we ended up with the end-result on our host, without any of the transient dependencies.
Now that we have everything running locally, let us make a change and get a feel for our local CI/CD loop.
The quicker we can close this loop, the quicker we can learn what actually works.
With Dagger, we can close this loop locally, without committing and pushing our changes.
And since every action is cached, subsequent runs will be quicker.
In the todoapp directory, edit line `25` of `src/components/Form.js` and save the file.
I change this line to `What must be done today?` and run the build locally again:
```shell
dagger do build
2022-03-24 16:52:17 +01:00
[✔] actions.build.run.script 0.0s
[✔] actions.deps 3.4s
2022-03-25 17:55:23 +01:00
[✔] client.filesystem."./".read 0.1s
2022-03-11 01:51:41 +01:00
[✔] actions.test.script 0.0s
[✔] actions.test 1.8s
2022-03-24 16:52:17 +01:00
[✔] actions.build.run 7.7s
[✔] actions.build.contents 0.2s
2022-03-25 17:55:23 +01:00
[✔] client.filesystem."./_build".write 0.2s
2022-03-11 01:51:41 +01:00
```
2022-03-24 16:52:17 +01:00
Being able to re-run the test & build loop locally in `13.6s` , without adding any extra dependencies to our host, is likely to change our approach to iterating on changes.
2022-03-11 01:51:41 +01:00
It becomes even more obvious when the change is not as straightforward as knowing _exactly_ which line to edit.
2022-02-14 16:09:53 +01:00
< / TabItem >
2022-03-11 01:51:41 +01:00
2022-02-14 16:09:53 +01:00
< / Tabs >
2022-03-24 19:55:24 +01:00
}
< / BrowserOnly >
2022-02-14 16:09:53 +01:00
:::tip
Now that we are comfortable with our local CI/CD loop, let us configure a remote CI environment in the second part.
2022-03-09 16:23:29 +01:00
The difference is that we will also deploy the build output to Netlify.
2022-02-14 16:09:53 +01:00
Dagger makes this easy.
:::