Skip to content

Commit

Permalink
docs: Update Docker documentation to use tabs instead of separate pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pauiii committed Oct 15, 2024
1 parent df522bd commit 0e9a09d
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 211 deletions.
4 changes: 2 additions & 2 deletions docs/docs/development/local-toolchain/build-flash.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ board addon.
From here on the process for building and flashing varies based on the method
you're using:

- **[VS Code](setup/docker/vscode.md)/[Native](setup/native.mdx)**:
- **[VS Code](setup/docker.mdx)/[Native](setup/native.mdx)**:
Execute the commands from within the `app/` subdirectory of the ZMK checkout.
- **[Devcontainer CLI](setup/docker/cli.md)**:
- **[Dev Container CLI](setup/docker.mdx)**:
Add `-s /absolute/path/to/zmk/app` to the `west` command.

If this is not done, you will encounter errors such as: `ERROR: source directory
Expand Down
190 changes: 190 additions & 0 deletions docs/docs/development/local-toolchain/setup/docker.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
---
title: Docker
sidebar_label: Docker
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

### Source Code

First, you'll need to clone the ZMK source repository if you haven't already.
Open a terminal and navigate to the folder you would like to place your `zmk`
directory in, then run the following command:

```sh
git clone https://github.com/zmkfirmware/zmk.git
```

### Docker Setup

<Tabs defaultValue="vsCode"
values={[
{label: 'VS Code', value: 'vsCode'},
{label: 'Dev Container CLI', value: 'cli'}
]}>
<TabItem value="vsCode">
:::note
This approach is documented for
[VS Code](https://github.com/microsoft/vscode) not
[Code OSS](https://github.com/microsoft/vscode/wiki/Differences-between-the-repository-and-Visual-Studio-Code).
:::

#### Installing Development Tools

1. Install [Docker Desktop](https://www.docker.com/products/docker-desktop) for
your operating system.
2. Install [VS Code](https://code.visualstudio.com/).
3. Install the [Remote - Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers).

#### Initialize & Update Zephyr Workspace

Open the `zmk` checkout directory in VS Code. The repository includes a
configuration for containerized development. Therefore, an alert will pop up:

![VS Code Dev Container Configuration Alert](../../../assets/dev-setup/vscode_devcontainer.png)

Click `Reopen in Container` to reopen the VS Code with the running container. If
the alert fails to pop up or you accidentally close it, you can perform the same
action by pressing the following keys based on your operating system and
selecting `Remote: Show Remote Menu`:

- **Windows/Linux**: `Ctrl + Shift + P`
- **MacOs**: `Cmd + Shift + P`

The first time you do this on your machine, it will pull down the Docker image
from the registry and build the container. **Subsequent launches are much
faster!**

:::caution
The following step and any future [build commands](../build-flash.mdx) must be
executed from the VS Code terminal _inside_ the container.
:::

Initialize the application and update modules, including Zephyr:

```sh
west init -l app/
west update
```

:::tip
This step pulls down quite a bit of tooling, be patient!
:::

:::info
You must restart the container at this point. The easiest way to do this is to
close the VS Code window, verify that the container has stopped in the Docker
Dashboard, and reopen the container with VS Code.

Your setup is complete once your container has restarted.
:::

</TabItem>
<TabItem value="cli">
#### Installing Development Tools

1. Install [Docker Desktop](https://www.docker.com/products/docker-desktop)
for your operating system.
2. Install the [Dev Container CLI](https://github.com/devcontainers/cli).

#### Initialize & Update Zephyr Workspace

Open up your Terminal and make sure that the
[Dev Container CLI](https://github.com/devcontainers/cli) is installed by
running:

```sh
devcontainer --version
```

To be able to execute commands, the
[Dev Container CLI](https://github.com/devcontainers/cli) has to know where the
`devcontainer.json` is located. This can be done using the `--workspace-folder`
option, which is available for all commands and will automatically look up the
file relative to the path. Therefore, the container can be started by executing:

```sh
devcontainer up --workspace-folder "/absolute/path/to/zmk"
```

The first time you do this on your machine, it will pull down the Docker image
from the registry and build the container. **Subsequent launches are much
faster!**

Once the command is finished, the development environment is available.
Furthermore, the path is mounted under `/workspaces/zmk/`. It can then be used
to initialize the application and update modules, including Zephyr.

```sh
devcontainer exec --workspace-folder "/absolute/path/to/zmk" \
west init -l "/workspaces/zmk/app"
devcontainer exec --workspace-folder "/absolute/path/to/zmk" \
west update
```

:::tip
This step pulls down quite a bit of tooling, be patient!
:::

:::info
You must restart the container at this point. This can be done by using:

```sh
docker container ps # List active containers
docker container stop "<container-id>" # Stop the container
```

Your setup is complete once your container has been restarted.
:::

</TabItem>
</Tabs>

### Volume Setup

In case you have a `zmk-config` or want to build with additional modules, it is
necessary to first make those available to the Docker container. This can be
done by mounting them as volumes.

But before you do so, first check that neither ZMK related containers nor the
`zmk-config` and `zmk-modules` volumes exist. This can be done with:

```sh
docker container ps # List active containers
docker container stop "<container-id>" # Stop the container
docker container rm "<container-id>" # Remove the container

docker volume ls # List volumes
docker volume rm "<volume-name>" # Remove volume
```

:::note
You can also use `docker container prune` to remove all containers if no others
are running.
:::

<Tabs
defaultValue="config"
values={[
{ label: "Zmk-Config", value: "config" },
{ label: "Modules", value: "modules" },
]}
>
<TabItem value="config">
```sh docker volume create --driver local -o o=bind -o type=none \ -o
device="/absolute/path/to/zmk-config/" zmk-config ```
</TabItem>
<TabItem value="modules">
```sh docker volume create --driver local -o o=bind -o type=none -o \
device="/absolute/path/to/zmk-modules/parent/" zmk-modules ```
</TabItem>
</Tabs>
:::tip
Once this is done, you can refer to the `zmk-config` with
`/workspace/zmk-config` and `/workspace/zmk-modules` to the modules instead of
using their full path like it is shown in the
[build commands](../build-flash.mdx), since these are the locations they were
mounted to in the container.
:::
58 changes: 0 additions & 58 deletions docs/docs/development/local-toolchain/setup/docker/cli.md

This file was deleted.

77 changes: 0 additions & 77 deletions docs/docs/development/local-toolchain/setup/docker/index.md

This file was deleted.

59 changes: 0 additions & 59 deletions docs/docs/development/local-toolchain/setup/docker/vscode.md

This file was deleted.

Loading

0 comments on commit 0e9a09d

Please sign in to comment.