From c4e7c5f854efe953d7db0fccdec31cfaf2761c7c Mon Sep 17 00:00:00 2001 From: Ved Ratan <82467006+VedRatan@users.noreply.github.com> Date: Tue, 6 Jun 2023 21:47:23 +0530 Subject: [PATCH] [Feature] Enhance devcontainer (#7175) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * added minikube and docker support Signed-off-by: Ved Ratan * added docs Signed-off-by: Ved Ratan --------- Signed-off-by: Ved Ratan Co-authored-by: Charles-Edouard Brétéché --- .devcontainer/Dockerfile | 31 ++++++++++++++++++++++++++----- .devcontainer/devcontainer.json | 14 ++++++++------ DEVELOPMENT.md | 7 +++---- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index da6b6c4ec8..37c64d168c 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,11 +1,32 @@ -FROM golang:1.20 - -RUN apt update && apt install -y sudo git +FROM ubuntu:latest +RUN apt-get update && apt-get install -y sudo git curl apt-transport-https ca-certificates gnupg-agent software-properties-common ARG USERNAME=root RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ && chmod 0440 /etc/sudoers.d/$USERNAME -ENV DEVCONTAINER=true +# Install Golang +RUN curl -LO https://dl.google.com/go/go1.20.linux-amd64.tar.gz \ + && tar -C /usr/local -xzf go1.20.linux-amd64.tar.gz \ + && rm go1.20.linux-amd64.tar.gz \ + && echo 'export PATH=$PATH:/usr/local/go/bin' >> /etc/profile -COPY . . +# Install Docker +# Install Docker +RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg +RUN echo \ + "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null +RUN apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io + +# Install kubectl and Minikube +RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl \ + && chmod +x kubectl && mv kubectl /usr/local/bin/ \ + && curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \ + && install minikube-linux-amd64 /usr/local/bin/minikube \ + && minikube config set driver docker + +# Expose ports for Minikube and Docker +EXPOSE 22 80 2375 8443 + +CMD ["/bin/bash"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 627a381051..bb232e55a3 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,8 +1,10 @@ // See https://containers.dev/implementors/json_reference/ for configuration reference { - "name": "Kyverno", - "build": { - "dockerfile": "Dockerfile" - }, - "remoteUser": "root" -} + "name": "Kyverno", + "build": { + "dockerfile": "Dockerfile" + }, + "remoteUser": "root", + "mounts": ["source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"], + "runArgs": ["--privileged", "--network=host", "-p", "22:22", "-p", "80:80", "-p", "2375:2375", "-p", "8443:8443"] +} \ No newline at end of file diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 6235315ad6..74ed6de4c6 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -32,16 +32,15 @@ It contains instructions to build, run, and test Kyverno. - Clone the project to your local machine. - Make sure that you have the Visual Studio Code editor installed on your system. -- Make sure that you have the Docker installed on your system. +- Make sure that you have wsl(Ubuntu preferred) and Docker installed on your system and on wsl too (docker.sock (UNIX socket) file is necessary to enable devcontainer to communicate with docker running in host machine). -- Open the project in Visual Studio Code. +- Open the project in Visual Studio Code, once the project is opened hit F1 and type wsl, now click on "Reopen in WSL". - If you haven't already done so, install the **Dev Containers** extension in Visual Studio Code. - Once the extension is installed, you should see a green icon in the bottom left corner of the window. -- After you have installed Dev Containers extension, it should automatically detect the .devcontainer folder inside the project, -and should suggest you to open the project in container. +- After you have installed Dev Containers extension, it should automatically detect the .devcontainer folder inside the project opened in wsl, and should suggest you to open the project in container. - If it doesn't suggest you, then press Ctrl + Shift + p and search "reopen in container" and click on it.