diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index d4db1b3..1f572e1 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -3,7 +3,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -FROM golang:1.12.5 +FROM golang:1.12.5-stretch # Avoid warnings by switching to noninteractive ENV DEBIAN_FRONTEND=noninteractive @@ -47,7 +47,7 @@ RUN apt-get update \ # Clean up && apt-get autoremove -y \ && apt-get clean -y \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* RUN apt-get update \ # Install Docker CE CLI @@ -62,6 +62,9 @@ RUN apt-get update \ # Install Helm && curl -s https://raw.githubusercontent.com/helm/helm/master/scripts/get | bash - +# Enable bash completion +RUN apt-get update && apt install -y bash-completion && echo "source /etc/bash_completion" >> "/root/.bashrc" + # Verify git, process tools installed RUN apt-get -y install git procps wget nano zsh inotify-tools jq RUN wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh || true @@ -84,3 +87,26 @@ RUN make install-kubebuilder RUN make install-kustomize RUN make install-test-dependency ENV SHELL /bin/bash + +# Save command line history +RUN echo "export HISTFILE=/root/commandhistory/.bash_history" >> "/root/.bashrc" \ + && echo "export PROMPT_COMMAND='history -a'" >> "/root/.bashrc" \ + && mkdir -p /root/commandhistory \ + && touch /root/commandhistory/.bash_history + +# Add useful aliases +RUN echo "alias k=kubectl" >> "/root/.bashrc" +# Add autocomplete to kubectl +RUN echo "source <(kubectl completion bash)" >> "/root/.bashrc" +RUN echo "source <(kubectl completion bash | sed 's/kubectl/k/g')" >> "/root/.bashrc" +# Add kubectx +RUN git clone https://github.com/ahmetb/kubectx.git /root/.kubectx \ + && COMPDIR=$(pkg-config --variable=completionsdir bash-completion) \ + && ln -sf /root/.kubectx/completion/kubens.bash $COMPDIR/kubens \ + && ln -sf /root/.kubectx/completion/kubectx.bash $COMPDIR/kubectx + +# Git command prompt +RUN git clone https://github.com/magicmonty/bash-git-prompt.git ~/.bash-git-prompt --depth=1 \ + && echo "if [ -f \"$HOME/.bash-git-prompt/gitprompt.sh\" ]; then GIT_PROMPT_ONLY_IN_REPO=1 && source $HOME/.bash-git-prompt/gitprompt.sh; fi" >> "/root/.bashrc" + +ENV PATH="/root/.kubectx:${PATH}" \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f4d6935..b95d5d0 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,17 +1,35 @@ // If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml. { "name": "Go", - "dockerComposeFile": "docker-compose.yml", - "service": "docker-in-docker", + "dockerFile": "./Dockerfile", "workspaceFolder": "/workspace", - "postCreateCommand": "make set-kindcluster", - "shutdownAction": "stopCompose", + "context": "..", + "workspaceMount": "src=${localWorkspaceFolder},dst=/workspace,type=bind", + "runArgs": [ + // Mount the env file + "--env-file", "${localWorkspaceFolder}/.devcontainer/.env", + // Mount go mod cache + "-v", "dboperator-gomodcache:/go/pkg", + // Cache vscode exentsions installs and homedir + "-v", "dboperator-vscodecache:/root/.vscode-server", + // Keep command history + "-v", "dboperator-bashhistory:/root/commandhistory", + // Enable security needed for docker + "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined", + // Mount docker socket for docker builds + "-v", "/var/run/docker.sock:/var/run/docker.sock", + "--network", "host", + "-e GO111MODULE=on", + // Mount azure + "-v", "${env:HOME}${env:USERPROFILE}/.azure:/home/vscode/.azure" + // Optionally mount k8s auth to existing cluster + // "-v", "${env:HOME}${env:USERPROFILE}/.kube:/home/vscode/.kube", + ], "extensions": [ "ms-azuretools.vscode-docker", "ms-vscode.go" ], "settings": { - "terminal.integrated.shell.linux": "zsh", "go.gopath": "/go", "go.inferGopath": true, "go.useLanguageServer": true, diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml deleted file mode 100644 index 1707c6b..0000000 --- a/.devcontainer/docker-compose.yml +++ /dev/null @@ -1,22 +0,0 @@ -version: '3' -services: - docker-in-docker: - build: - context: ../ - dockerfile: .devcontainer/Dockerfile - network_mode: "host" - volumes: - # Update this to wherever you want VS Code to mount the folder of your project - - ..:/workspace - - # This lets you avoid setting up Git again in the container - - ~/.gitconfig:/root/.gitconfig - - ~/.ssh:/root/.ssh:ro # does not work on Windows! Will need to generate in container :( - # Forwarding the socket is optional, but lets docker work inside the container if you install the Docker CLI. - # See the docker-in-docker-compose definition for details on how to install it. - - /var/run/docker.sock:/var/run/docker.sock - - # Overrides default command so things don't shut down after the process ends - useful for debugging - command: sleep infinity - env_file: - - .env \ No newline at end of file diff --git a/Makefile b/Makefile index 1106d7c..273756f 100644 --- a/Makefile +++ b/Makefile @@ -141,7 +141,6 @@ endif @echo "deploying controller to cluster" make deploy-controller - install-kind: ifeq (,$(shell which kind)) @echo "installing kind" diff --git a/docs/contributing.md b/docs/contributing.md index 18d1146..df7c85b 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -51,6 +51,22 @@ If you are using Visual Studio Code with [Remote - Containers](https://marketpla ``` 7. Once your kind cluster has been created, you can now start testing your Azure Databicks Operator within your own local kubernetes environment! +## Advanced: DevContainer Cache + +To speedup start times for the `devcontainer` and reduce the requirement for internet connectivity when starting we cache the `.vscodeserver` and `/go/pkg` folder to docker volumes. The [VSCode docs cover this topic here](https://code.visualstudio.com/docs/remote/containers-advanced#_avoiding-extension-reinstalls-on-container-rebuild). + +The downside is that changes to the `extension` list in `devcontainer.json` won't automatically be picked up. To clear the cache run `docker volume rm dboperator-vscodecache -f`. + +You'll need to remove existing instance of the `devcontainer` before clearing the cache. Use `docker ps -a` and then locating the container with a name `vsc-azure-databricks-operator-*` and using `docker rm -f CONTAINER-NAME-HERE` to remove it. + +In `bash` the following will automate the process: + +``` + docker ps -a | grep vsc-azure-databricks | awk '{print $1}' | xargs docker rm -f + docker volume rm dboperator-vscodecache -f + docker volume rm dboperator-gomodcache -f +``` + # Building and Running the operator ## Basics @@ -58,8 +74,7 @@ The scaffolding for the project is generated using `Kubebuilder`. It is a good i See `Makefile` at the root directory of the project. By default, executing `make` will build the project and produce an executable at `./bin/manager` -For example, to quick start ->this assumes dependencies have been downloaded and existing CRDs have been installed. See next section +For example, to quick start this assumes dependencies have been downloaded and existing CRDs have been installed. See next section ``` $ git clone https://github.com/microsoft/azure-databricks-operator.git $ cd azure-databricks-operator