From 13a761cee705ee1c567c14d75270a1f8280485f1 Mon Sep 17 00:00:00 2001 From: Oliver Gould Date: Tue, 25 Jan 2022 15:00:30 -0800 Subject: [PATCH] devcontainer: Fix kubectl path (#1441) * Adds `jq`. * Adds a _devcontainer_ CI workflow Signed-off-by: Oliver Gould (cherry picked from commit 8f38eb31aa8374941e3b82182ba33b5604ad368e) Signed-off-by: Oliver Gould --- .devcontainer/Dockerfile | 17 +++++----- .devcontainer/devcontainer.json | 4 +-- .github/workflows/devcontainer.yml | 51 ++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/devcontainer.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index cc130e7f5a..21ccdb0577 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -2,10 +2,11 @@ FROM docker.io/rust:1.56.1-bullseye ENV DEBIAN_FRONTEND=noninteractive RUN apt update && apt upgrade -y -RUN apt install -y \ +RUN apt install -y --no-install-recommends \ clang \ cmake \ golang \ + jq \ lldb \ lsb-release \ sudo \ @@ -30,17 +31,17 @@ ENV HOME=/home/$USER RUN mkdir -p $HOME/bin ENV PATH=$HOME/bin:$PATH -RUN curl --proto '=https' --tlsv1.3 -vsSfLo $HOME/kubectl "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" \ - && chmod 755 $HOME/kubectl +ARG KUBECTL_VERSION=v1.23.2 +RUN curl --proto '=https' --tlsv1.3 -vsSfLo $HOME/bin/kubectl "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl" \ + && chmod 755 $HOME/bin/kubectl RUN curl --proto '=https' --tlsv1.3 -vsSfL https://raw.githubusercontent.com/rancher/k3d/main/install.sh \ | USE_SUDO=false K3D_INSTALL_DIR=$HOME/bin bash RUN rustup component add clippy rustfmt -RUN mkdir /tmp/cargo-deny && cd /tmp/cargo-deny && \ - curl --proto '=https' --tlsv1.3 -vsSfL https://github.com/EmbarkStudios/cargo-deny/releases/download/0.11.0/cargo-deny-0.11.0-x86_64-unknown-linux-musl.tar.gz \ - | tar zxf - \ - && mv cargo-deny-0.11.0-x86_64-unknown-linux-musl/cargo-deny $HOME/bin \ - && cd .. && rm -rf /tmp/cargo-deny + +ARG CARGO_DENY_VERSION=0.11.0 +RUN curl --proto '=https' --tlsv1.3 -vsSfL "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" RUN curl --proto '=https' --tlsv1.3 -vsSfL https://run.linkerd.io/install-edge | sh \ && ln -s $(readlink ~/.linkerd2/bin/linkerd) ~/bin/linkerd diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 28bda0ad41..63b9a2a847 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,7 +1,7 @@ { "name": "linkerd2-proxy", - "image": "ghcr.io/linkerd/dev-proxy:v3", - //"dockerFile": "./Dockerfile", + "image": "ghcr.io/linkerd/dev-proxy:v5", + // "dockerFile": "./Dockerfile", "extensions": [ "DavidAnson.vscode-markdownlint", "matklad.rust-analyzer", diff --git a/.github/workflows/devcontainer.yml b/.github/workflows/devcontainer.yml new file mode 100644 index 0000000000..02045fab89 --- /dev/null +++ b/.github/workflows/devcontainer.yml @@ -0,0 +1,51 @@ +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: + - rust-toolchain + - .devcontainer/** + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 + - run: docker build .devcontainer + + rust-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 + - run: | + versions=$(sed -nE 's|^FROM (.*/)?rust:([^ -]+)|\2|p' .devcontainer/Dockerfile) + ex=0 + for mismatch in $(echo "$versions" | grep -vF "$(cat rust-toolchain)" || true) ; do + echo "::error file=.devcontainer/Dockerfile::Devcontainer uses incorrect rust version(s): $mismatch" + ex=$((ex + 1)) + done + exit $ex + + devcontainer-image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 + - run: | + export DEBIAN_FRONTEND=noninteractive + sudo apt-get update + sudo apt-get -y --no-install-recommends install jq + - run: | + image=$(sed -E '/^\s*\/\/.*/d' .devcontainer/devcontainer.json |jq -Mr .image) + if [ "$image" == "null" ]; then + echo "::error file=.devcontainer/devcontainer.json::Missing image" + exit 1 + fi + if ! docker pull "$image" ; then + echo "::error file=.devcontainer/devcontainer.json::Unable to pull image: $image" + exit 1 + fi