Skip to content

Commit

Permalink
Added "docker outside of docker" devcontainer (#2316)
Browse files Browse the repository at this point in the history
* added dood devcontainer

* use file paths

* mandatorize clab version during the build and add runargs

* added tag munching step

* fucking actions

* bring back config

* run devcontainer build on beta tags as well

* try lowercase

* output tag

* move outputs

* a day when you hate gh actions

* change name

* remove test

* added needs deps

* trying slim dockerfile for devcontainer

* use slim zshrc

* use explicit suffixes

* change devcontainer base name

* bring back moby for version matching

* try 26.1.4

* try 25.0.5

* try 24

* switch to 26.1.5 and wait for better times

moby/moby#48987

* try moby 27.3.1

* try 26.1.3

* try 23.0.7

* try 26.1.4 docker

* do not install docker-compose plugin

* installDockerComposeSwitch false

* bring back 23.0.7
fucking containers man

* remove utm docs and finish dind/dood docs

* added a video

* test fira code embedded and zsh term settings

* remove font download and set multiple fonts

* added devcontainer requirements

* do not require icons in the fonts

* added windows install doc

* fix bg color in animation

* note about the reboot
  • Loading branch information
hellt authored Dec 1, 2024
1 parent fa09e4f commit 3dbe819
Show file tree
Hide file tree
Showing 16 changed files with 686 additions and 105 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ RUN mkdir -p /home/vscode/.docker && echo "{}" > /home/vscode/.docker/config.jso
COPY ./.devcontainer/zsh/.zshrc /home/vscode/.zshrc
COPY ./.devcontainer/zsh/.p10k.zsh /home/vscode/.p10k.zsh
COPY ./.devcontainer/zsh/install-zsh-plugins.sh /tmp/install-zsh-plugins.sh
RUN bash -c "/tmp/install-zsh-plugins.sh"
COPY ./.devcontainer/zsh/install-tools-completions.sh /tmp/install-tools-completions.sh
RUN bash -c "/tmp/install-zsh-plugins.sh && /tmp/install-tools-completions.sh"

# Setup pyenv virtual environment for clab tests
COPY tests/requirements.txt /tmp/requirements.txt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
// For format details, see https://aka.ms/devcontainer.json.
{
"build": {
"dockerfile": "./Dockerfile",
"context": "..",
"dockerfile": "../Dockerfile",
"context": "../..",
"args": {
"CLAB_VERSION": "${localEnv:CLAB_VERSION}"
}
},
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "26.1.4",
// docker/moby version is that old because newer ones failed to install under emulation
// see https://github.com/moby/moby/issues/48987#issuecomment-2507267417
// and https://github.com/moby/moby/issues/47895#issuecomment-2507528678
"version": "23.0.7",
"dockerDashComposeVersion": "none",
"moby": "false"
"installDockerComposeSwitch": "false"
},
// Add sshd to support gh cli codespace cp.
"ghcr.io/devcontainers/features/sshd:1": {
Expand All @@ -24,6 +27,15 @@
"remoteUser": "vscode",
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/bin/zsh"
}
},
"terminal.integrated.fontFamily": "FiraCode Nerd Font, Menlo, Monaco, Cascadia Code, Consolas, Courier New, monospace"
},
"extensions": [
// go
"golang.go",
Expand Down
48 changes: 48 additions & 0 deletions .devcontainer/docker-in-docker_slim/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// For format details, see https://aka.ms/devcontainer.json.
{
"build": {
"dockerfile": "../slim.Dockerfile",
"context": "../..",
"args": {
"CLAB_VERSION": "${localEnv:CLAB_VERSION}"
}
},
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "23.0.7",
"dockerDashComposeVersion": "none",
"installDockerComposeSwitch": "false"
},
// Add sshd to support gh cli codespace cp.
"ghcr.io/devcontainers/features/sshd:1": {
"version": "latest"
}
},
"remoteUser": "vscode",
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/bin/zsh"
}
},
"terminal.integrated.fontFamily": "FiraCode Nerd Font, Menlo, Monaco, Cascadia Code, Consolas, Courier New, monospace"
},
"extensions": [
"ms-azuretools.vscode-docker",
// Python.
"ms-python.python",
// Errors and highlighters.
"mechatroner.rainbow-csv",
"redhat.vscode-yaml",
// markdown
"yzhang.markdown-all-in-one",
"davidanson.vscode-markdownlint"
]
}
},
"workspaceMount": "source=${localWorkspaceFolder},target=/${containerWorkspaceFolder},type=bind",
"workspaceFolder": "/clab"
}
68 changes: 68 additions & 0 deletions .devcontainer/docker-outside-of-docker/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// For format details, see https://aka.ms/devcontainer.json.
{
"build": {
"dockerfile": "../Dockerfile",
"context": "../..",
"args": {
"CLAB_VERSION": "${localEnv:CLAB_VERSION}"
}
},
"runArgs": [
"--network=host",
"--pid=host",
"--privileged"
],
"mounts": [
"type=bind,src=/run/docker/netns,dst=/run/docker/netns",
"type=bind,src=/var/lib/docker,dst=/var/lib/docker",
"type=bind,src=/lib/modules,dst=/lib/modules"
],
"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
"version": "23.0.7",
"dockerDashComposeVersion": "none",
"installDockerComposeSwitch": "false"
},
// Add sshd to support gh cli codespaces cp.
"ghcr.io/devcontainers/features/sshd:1": {
"version": "latest"
},
"ghcr.io/devcontainers/features/go:1": {
"version": "1.22"
}
},
"remoteUser": "vscode",
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/bin/zsh"
}
},
"terminal.integrated.fontFamily": "FiraCode Nerd Font, Menlo, Monaco, Cascadia Code, Consolas, Courier New, monospace"
},
"extensions": [
// go
"golang.go",
"mhutchie.git-graph",
"ms-azuretools.vscode-docker",
// Python.
"ms-python.python",
"ms-python.vscode-pylance",
// Errors and highlighters.
"mechatroner.rainbow-csv",
"redhat.vscode-yaml",
"jinliming2.vscode-go-template",
// markdown
"yzhang.markdown-all-in-one",
"davidanson.vscode-markdownlint",
// proto
"zxh404.vscode-proto3"
]
}
},
"workspaceFolder": "${localWorkspaceFolder}",
"workspaceMount": "source=${localWorkspaceFolder},target=${localWorkspaceFolder},type=bind"
}
58 changes: 58 additions & 0 deletions .devcontainer/docker-outside-of-docker_slim/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// For format details, see https://aka.ms/devcontainer.json.
{
"build": {
"dockerfile": "../slim.Dockerfile",
"context": "../..",
"args": {
"CLAB_VERSION": "${localEnv:CLAB_VERSION}"
}
},
"runArgs": [
"--network=host",
"--pid=host",
"--privileged"
],
"mounts": [
"type=bind,src=/run/docker/netns,dst=/run/docker/netns",
"type=bind,src=/var/lib/docker,dst=/var/lib/docker",
"type=bind,src=/lib/modules,dst=/lib/modules"
],
"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
"version": "23.0.7",
"dockerDashComposeVersion": "none",
"installDockerComposeSwitch": "false"
},
// Add sshd to support gh cli codespaces cp.
"ghcr.io/devcontainers/features/sshd:1": {
"version": "latest"
}
},
"remoteUser": "vscode",
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/bin/zsh"
}
},
"terminal.integrated.fontFamily": "FiraCode Nerd Font, Menlo, Monaco, Cascadia Code, Consolas, Courier New, monospace"
},
"extensions": [
"ms-azuretools.vscode-docker",
// Python.
"ms-python.python",
// Errors and highlighters.
"mechatroner.rainbow-csv",
"redhat.vscode-yaml",
// markdown
"yzhang.markdown-all-in-one",
"davidanson.vscode-markdownlint"
]
}
},
"workspaceFolder": "${localWorkspaceFolder}",
"workspaceMount": "source=${localWorkspaceFolder},target=${localWorkspaceFolder},type=bind"
}
57 changes: 57 additions & 0 deletions .devcontainer/slim.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM mcr.microsoft.com/devcontainers/python:3.11-bookworm

ARG CLAB_VERSION

# Add the netdevops repository
RUN echo "deb [trusted=yes] https://netdevops.fury.site/apt/ /" | \
tee -a /etc/apt/sources.list.d/netdevops.list

# Install necessary packages, including curl
RUN apt-get update && apt-get install -y --no-install-recommends \
direnv \
btop \
iputils-ping \
tcpdump \
iproute2 \
qemu-kvm \
dnsutils \
telnet \
curl

# Install Containerlab
RUN bash -c "$(curl -sL https://get.containerlab.dev)" -- -v ${CLAB_VERSION}

# Install GitHub CLI directly from the latest release
RUN bash -c 'ARCH=$(uname -m | sed "s/x86_64/amd64/" | sed "s/aarch64/arm64/") && \
VERSION=$(curl -s https://api.github.com/repos/cli/cli/releases/latest | \
grep -oP "\"tag_name\": \"\K[^\"]+") && \
CLEAN_VERSION=${VERSION#v} && \
DOWNLOAD_URL="https://github.com/cli/cli/releases/download/${VERSION}/gh_${CLEAN_VERSION}_linux_${ARCH}.tar.gz" && \
curl -L "$DOWNLOAD_URL" | tar xz -C /tmp && \
mv /tmp/gh_${CLEAN_VERSION}_linux_${ARCH}/bin/gh /usr/local/bin/ && \
chmod +x /usr/local/bin/gh && \
rm -rf /tmp/gh_${CLEAN_VERSION}_linux_${ARCH}'

# Add empty docker config files to avoid clab warnings for root user
RUN mkdir -p /root/.docker && echo "{}" > /root/.docker/config.json

# Maintain SSH_AUTH_SOCK env var when using sudo
RUN mkdir -p /etc/sudoers.d && echo 'Defaults env_keep += "SSH_AUTH_SOCK"' > /etc/sudoers.d/ssh_auth_sock

# Switch to the vscode user provided by the base image
USER vscode

# Copy dclab script used to run the local containerlab build after `make build`
COPY ./.devcontainer/dclab /usr/local/bin/dclab

# Create SSH key for vscode user to enable passwordless SSH to devices
RUN ssh-keygen -t ecdsa -b 256 -N "" -f ~/.ssh/id_ecdsa

# Add empty docker config files to avoid clab warnings for vscode user
RUN mkdir -p /home/vscode/.docker && echo "{}" > /home/vscode/.docker/config.json

# Setup Zsh and plugins
COPY ./.devcontainer/zsh/.zshrc-slim /home/vscode/.zshrc
COPY ./.devcontainer/zsh/.p10k.zsh /home/vscode/.p10k.zsh
COPY ./.devcontainer/zsh/install-zsh-plugins.sh /tmp/install-zsh-plugins.sh
RUN bash -c "/tmp/install-zsh-plugins.sh"
33 changes: 19 additions & 14 deletions .devcontainer/zsh/.p10k.zsh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Powerlevel10k configuration wizard on 2024-04-03 at 12:04 EEST.
# Based on romkatv/powerlevel10k/config/p10k-pure.zsh, checksum 35142.
# Wizard options: nerdfont-complete + powerline, small icons, pure, 2 lines, sparse,
# instant_prompt=verbose.
# Generated by Powerlevel10k configuration wizard on 2024-10-17 at 19:28 CEST.
# Based on romkatv/powerlevel10k/config/p10k-pure.zsh, checksum 07533.
# Wizard options: nerdfont-v3 + powerline, large icons, pure, snazzy, 24h time, 2 lines,
# sparse, instant_prompt=verbose.
# Type `p10k configure` to generate another config.
#
# Config file for Powerlevel10k with the style of Pure (https://github.com/sindresorhus/pure).
Expand Down Expand Up @@ -39,22 +39,28 @@

# Prompt colors.
local grey='242'
# local red='#FF5C57'
# local yellow='#F3F99D'
# local blue='#57C7FF'
# local magenta='#FF6AC1'
# local cyan='#9AEDFE'
# local white='#F1F1F0'
local red='1'
local yellow='3'
local blue='4'
local magenta='5'
local cyan='6'
local white='7'
local darkgreen='#386641'

# Left prompt segments.
typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(
# =========================[ Line #1 ]=========================
context # user@host
dir # current directory
vcs # git status
command_execution_time # previous command duration
virtualenv # python virtual environment
time # current time
command_execution_time # previous command duration
# =========================[ Line #2 ]=========================
newline # \n
prompt_char # prompt symbol
Expand All @@ -66,7 +72,7 @@
# command_execution_time # previous command duration
# virtualenv # python virtual environment
# context # user@host

time # current time
# =========================[ Line #2 ]=========================
newline # \n
)
Expand Down Expand Up @@ -96,11 +102,10 @@
typeset -g POWERLEVEL9K_PROMPT_CHAR_OVERWRITE_STATE=false

# Grey Python Virtual Environment.
typeset -g POWERLEVEL9K_VIRTUALENV_FOREGROUND=$grey
typeset -g POWERLEVEL9K_VIRTUALENV_FOREGROUND=$darkgreen
# Don't show Python version.
typeset -g POWERLEVEL9K_VIRTUALENV_SHOW_PYTHON_VERSION=false
typeset -g POWERLEVEL9K_VIRTUALENV_{LEFT,RIGHT}_DELIMITER=
typeset -g POWERLEVEL9K_VIRTUALENV_LEFT_DELIMITER='\ue73c·'

# Blue current directory.
typeset -g POWERLEVEL9K_DIR_FOREGROUND=$blue
Expand Down Expand Up @@ -136,14 +141,14 @@
typeset -g POWERLEVEL9K_VCS_{INCOMING,OUTGOING}_CHANGESFORMAT_FOREGROUND=$cyan
# Don't show remote branch, current tag or stashes.
typeset -g POWERLEVEL9K_VCS_GIT_HOOKS=(vcs-detect-changes git-untracked git-aheadbehind)
# The branch icon.
typeset -g POWERLEVEL9K_VCS_BRANCH_ICON='\uf418·'
# Don't show the branch icon.
typeset -g POWERLEVEL9K_VCS_BRANCH_ICON=
# When in detached HEAD state, show @commit where branch normally goes.
typeset -g POWERLEVEL9K_VCS_COMMIT_ICON='@'
# Don't show staged, unstaged, untracked indicators.
typeset -g POWERLEVEL9K_VCS_{STAGED,UNSTAGED,UNTRACKED}_ICON=
# Show '*' when there are staged, unstaged or untracked files.
typeset -g POWERLEVEL9K_VCS_DIRTY_ICON='*'
# typeset -g POWERLEVEL9K_VCS_DIRTY_ICON='*'
# Show '⇣' if local branch is behind remote.
typeset -g POWERLEVEL9K_VCS_INCOMING_CHANGES_ICON=':⇣'
# Show '⇡' if local branch is ahead of remote.
Expand Down Expand Up @@ -177,7 +182,7 @@
# it incompatible with your zsh configuration files.
# - quiet: Enable instant prompt and don't print warnings when detecting console output
# during zsh initialization. Choose this if you've read and understood
# https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt.
# https://github.com/romkatv/powerlevel10k#instant-prompt.
# - verbose: Enable instant prompt and print a warning when detecting console output during
# zsh initialization. Choose this if you've never tried instant prompt, haven't
# seen the warning, or if you are unsure what this all means.
Expand All @@ -198,4 +203,4 @@
typeset -g POWERLEVEL9K_CONFIG_FILE=${${(%):-%x}:a}

(( ${#p10k_config_opts} )) && setopt ${p10k_config_opts[@]}
'builtin' 'unset' 'p10k_config_opts'
'builtin' 'unset' 'p10k_config_opts'
Loading

0 comments on commit 3dbe819

Please sign in to comment.