Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a VS Code devcontainer configuration #788

Merged
merged 19 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from 17 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
57 changes: 57 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM docker.io/rust:1.56.0-bullseye

ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && apt upgrade -y
RUN apt install -y \
clang \
cmake \
jq \
lldb \
lsb-release \
sudo \
time

ARG USER=code
ARG USER_UID=1000
ARG USER_GID=1000
RUN groupadd --gid=$USER_GID $USER \
&& useradd --uid=$USER_UID --gid=$USER_GID -m $USER \
&& echo "$USER ALL=(root) NOPASSWD:ALL" >/etc/sudoers.d/$USER \
&& chmod 0440 /etc/sudoers.d/$USER

COPY scurl /usr/local/bin/scurl

# Install a Docker client that uses the parent host's Docker daemon
ARG USE_MOBY=false
ENV DOCKER_BUILDKIT=1
RUN scurl https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/script-library/docker-debian.sh \
| bash -s -- true /var/run/docker-host.sock /var/run/docker.sock "${USER}" "${USE_MOBY}" latest

USER $USER
ENV HOME=/home/$USER
RUN mkdir -p $HOME/bin
ENV PATH=$HOME/bin:$PATH

# Install `kubectl`
RUN export K8S_VERSION="$(scurl https://dl.k8s.io/release/stable.txt)" \
&& scurl -o $HOME/bin/kubectl "https://dl.k8s.io/release/${K8S_VERSION}/bin/linux/amd64/kubectl" \
&& chmod 755 $HOME/bin/kubectl

# Install `k3d`
RUN scurl https://raw.githubusercontent.com/rancher/k3d/main/install.sh \
| USE_SUDO=false K3D_INSTALL_DIR=$HOME/bin bash

RUN rustup component add clippy rls rust-src rustfmt

# Install cargo-deny
ARG CARGO_DENY_VERSION=0.11.0
RUN scurl "https://github.com/EmbarkStudios/cargo-deny/releases/download/${CARGO_DENY_VERSION}/cargo-deny-${CARGO_DENY_VERSION}-x86_64-unknown-linux-musl.tar.gz" \
| tar zvxf - --strip-components=1 -C $HOME/bin "cargo-deny-${CARGO_DENY_VERSION}-x86_64-unknown-linux-musl/cargo-deny"

# Install cargo-tarpaulin
ARG CARGO_TARPAULIN_VERSION=0.18.5
RUN scurl "https://github.com/xd009642/tarpaulin/releases/download/${CARGO_TARPAULIN_VERSION}/cargo-tarpaulin-${CARGO_TARPAULIN_VERSION}-travis.tar.gz" \
| tar xzvf - -C $HOME/bin

ENTRYPOINT ["/usr/local/share/docker-init.sh"]
CMD ["sleep", "infinity"]
47 changes: 47 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# `kube-rs` Development container

This directory provides a [_devcontainer_][dc] configuration that configures a
reproducible development environment for this project. This base image should
contain only the bare necessities to get up and running with `kube-rs`.
Customizations should be made in per-user configuration.
olix0r marked this conversation as resolved.
Show resolved Hide resolved

olix0r marked this conversation as resolved.
Show resolved Hide resolved
## Usage

Install the VS Code [Remote Development extension pack][remote-exts] after which
VS Code should build (first use) then run the container in the background.

## Docker

This configuration currently uses the parent host's Docker daemon (rather than
running a separate docker daemon within in the container). It creates
devcontainers on the host network so it's easy to use k3d clusters hosted in the
parent host's docker daemon.

## Personalizing

This configuration is supposed to provide a minimal setup without catering to
any one developer's personal tastes. Devcontainers can be extended with per-user
configuration.

To add your own extensions to the devcontainer, configure default extensions in
your VS Code settings:

```jsonc
"remote.containers.defaultExtensions": [
"eamodio.gitlens",
"GitHub.copilot",
"GitHub.vscode-pull-request-github",
"mutantdino.resourcemonitor",
],
```

Furthermore, you can configure a [_dotfiles_ repository][df] to perform
customizations with a VS Code setting like:

```jsonc
"dotfiles.repository": "https://github.com/olix0r/dotfiles.git",
```

[dc]: https://code.visualstudio.com/docs/remote/containers
[df]: https://dotfiles.github.io/
[remote-exts]: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack
46 changes: 46 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "kube-dev",

// TODO publish a version of this image to the organization's package registry and then comment
// out the `dockerFile` configuration.
//"image": "ghcr.io/kube-rs/dev:v1",
"dockerFile": "./Dockerfile",
clux marked this conversation as resolved.
Show resolved Hide resolved

// These extensions are loaded for all users by default.
"extensions": [
"DavidAnson.vscode-markdownlint",
"matklad.rust-analyzer",
"NathanRidley.autotrim",
"samverschueren.final-newline",
"tamasfe.even-better-toml",
"vadimcn.vscode-lldb",
// "zxh404.vscode-proto3"
],

// Set project-specific VS Code settings here.
"settings": {
// Prevent conflicting versions of the Kubernetes API from being loaded.
"rust-analyzer.cargo.allFeatures": false,
},

// // `make clippy` and `make lint` require the nightly toolchain, so install
// // it as the container is created.
// "postCreateCommand": "rustup toolcahin add nightly && rustup default nightly",

// Configure docker.
"runArgs": [
"--init",
// Use the host network so we can access k3d, etc.
"--net=host",
// For lldb
"--cap-add=SYS_PTRACE",
"--security-opt=seccomp=unconfined"
],
"overrideCommand": false,
"remoteUser": "code",

// Mount the parent host's docker socket into the container.
"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker-host.sock,type=bind"
]
clux marked this conversation as resolved.
Show resolved Hide resolved
}
5 changes: 5 additions & 0 deletions .devcontainer/scurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
#
# Run `curl` with flags to ensure transport security.`

exec curl --proto '=https' --tlsv1.3 -vsSfL $@
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ jobs:
command: check
args: --all

- name: Check devcontainer matches MSRV
run: |
versions=$(sed -nE 's|^FROM (.*/)?rust:([^ ]+)|\2|p' .devcontainer/Dockerfile)
echo "Versions: $versions"
mismatches=$(echo "$versions" | grep -v '^${{ steps.msrv.outputs.msrv }}' || true)
echo "Mismatches: $mismatches"
if [ -n "$mismatches" ]; then
echo "::error ::Devcontainer includes incorrect rust version(s): $mismatches"
exit 1
fi

clux marked this conversation as resolved.
Show resolved Hide resolved
e2e:
# e2e tests are docker on linux
runs-on: ubuntu-latest
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/devcontainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Devcontainer

# When a pull request is opened that changes the Devcontainer configuration,
# ensure that the container continues to build properly.
on:
pull_request:
paths:
- .devcontainer/**
paths-ignore:
# The devcontainer.json isn't actually tested at the moment.
- .devcontainer/devcontainer.json

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: docker build .devcontainer
clux marked this conversation as resolved.
Show resolved Hide resolved