Skip to content
This repository has been archived by the owner on Jan 28, 2022. It is now read-only.

DevContainer move to single dockerfile from compose #100

Merged
merged 8 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 28 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Azadehkhojandi marked this conversation as resolved.
Show resolved Hide resolved

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 \
Azadehkhojandi marked this conversation as resolved.
Show resolved Hide resolved
&& 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}"
28 changes: 23 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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": [
Azadehkhojandi marked this conversation as resolved.
Show resolved Hide resolved
// 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",
JasonTheDeveloper marked this conversation as resolved.
Show resolved Hide resolved
// 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",
Azadehkhojandi marked this conversation as resolved.
Show resolved Hide resolved
],
"extensions": [
"ms-azuretools.vscode-docker",
"ms-vscode.go"
],
"settings": {
"terminal.integrated.shell.linux": "zsh",
"go.gopath": "/go",
"go.inferGopath": true,
"go.useLanguageServer": true,
Expand Down
22 changes: 0 additions & 22 deletions .devcontainer/docker-compose.yml

This file was deleted.

1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ endif
@echo "deploying controller to cluster"
make deploy-controller
Azadehkhojandi marked this conversation as resolved.
Show resolved Hide resolved


install-kind:
ifeq (,$(shell which kind))
@echo "installing kind"
Expand Down
19 changes: 17 additions & 2 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,30 @@ 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
The scaffolding for the project is generated using `Kubebuilder`. It is a good idea to become familiar with this [project](https://github.com/kubernetes-sigs/kubebuilder). The [quick start](https://book.kubebuilder.io/quick-start.html) guide is also quite useful.

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
Expand Down