Skip to content

Commit

Permalink
Bugfix devcontainer windows (#1108)
Browse files Browse the repository at this point in the history
* updating the devcontainer for windows
  • Loading branch information
Justin Pflueger authored Jun 8, 2020
1 parent 725dc08 commit 1a76b69
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 153 deletions.
140 changes: 62 additions & 78 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,96 +3,80 @@
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

FROM golang:1.13.5
FROM golang:1.13.10-buster

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Configure apt, install packages and tools
RUN apt-get update \
# Configure apt, install packages and cli tools
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get -y install --no-install-recommends apt-transport-https ca-certificates curl gnupg2 lsb-release \
#
# Install recommended utils
&& apt-get -y install --no-install-recommends apt-utils 2>&1 \
# Install Kubebuilder
&& curl -sL https://go.kubebuilder.io/dl/2.3.1/$(go env GOOS)/$(go env GOARCH) | tar -xz --strip-components=2 -C /usr/local/bin \
#
# Install sudo
&& apt-get -y install sudo \
# Install Helm
&& curl -s https://get.helm.sh/helm-v3.2.1-linux-amd64.tar.gz | tar -zxv --strip-components=1 -C /usr/local/bin linux-amd64/helm \
#
# Verify git, process tools, lsb-release (common in install instructions for CLIs) installed
&& apt-get -y install git procps lsb-release \
# Install Docker CLI package source
&& curl -fsSL https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/gpg | (OUT=$(apt-key add - 2>&1) || echo $OUT) \
&& echo "deb [arch=amd64] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list \
#
# Install gocode-gomod
&& go get -x -d github.com/stamblerre/gocode 2>&1 \
&& go build -o gocode-gomod github.com/stamblerre/gocode \
&& mv gocode-gomod $GOPATH/bin/ \
&& GO111MODULE=on go get -v golang.org/x/tools/gopls@latest 2>&1 \
# Add the Azure CLI package source
&& curl -sL https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 2>/dev/null \
&& echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/azure-cli.list \
#
# Install Go tools
&& go get -u -v \
github.com/mdempsky/gocode \
github.com/uudashr/gopkgs/cmd/gopkgs \
github.com/ramya-rao-a/go-outline \
github.com/acroca/go-symbols \
github.com/godoctor/godoctor \
golang.org/x/tools/cmd/guru \
golang.org/x/tools/cmd/gorename \
github.com/rogpeppe/godef \
github.com/zmb3/gogetdoc \
github.com/haya14busa/goplay/cmd/goplay \
github.com/sqs/goreturns \
github.com/josharian/impl \
github.com/davidrjenni/reftools/cmd/fillstruct \
github.com/fatih/gomodifytags \
github.com/cweill/gotests/... \
golang.org/x/tools/cmd/goimports \
golang.org/x/lint/golint \
github.com/alecthomas/gometalinter \
honnef.co/go/tools/... \
github.com/mgechev/revive \
github.com/derekparker/delve/cmd/dlv 2>&1 \
# Install Packages
&& apt-get update \
&& apt-get install -y --no-install-recommends \
docker-ce-cli \
azure-cli \
zsh \
#
# Install ZSH shell
&& wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh || true \
#
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

RUN apt-get update \
#
# Install Docker CE CLI
&& apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common lsb-release \
&& curl -fsSL https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/gpg | apt-key add - 2>/dev/null \
&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" \
&& apt-get update \
&& apt-get install -y docker-ce-cli \
RUN export DEBIAN_FRONTEND=noninteractive \
#
# Install kubectl
&& curl -sSL -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl \
&& chmod +x /usr/local/bin/kubectl \
# Install Go development tools
&& GO111MODULE=on go get -v \
golang.org/x/tools/gopls@latest \
golang.org/x/lint/golint@latest \
github.com/go-delve/delve/cmd/dlv@latest \
2>&1 \
#
# Install Helm
&& curl -s https://raw.githubusercontent.com/helm/helm/master/scripts/get | bash - \
#
# Install Azure CLI
&& curl -sL https://aka.ms/InstallAzureCLIDeb | bash -

# 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

ENV PATH="/usr/local/kubebuilder/bin:${PATH}"

ENV GO111MODULE=on

ENV AZURE_CLIENT_ID="${AZURE_CLIENT_ID}"
ENV AZURE_CLIENT_SECRET="${AZURE_CLIENT_SECRET}"
ENV AZURE_SUBSCRIPTION_ID="${AZURE_SUBSCRIPTION_ID}"
ENV AZURE_TENANT_ID="${AZURE_TENANT_ID}"
ENV KUBECONFIG="/root/.kube/kind-config-kind"

COPY ./Makefile ./
RUN make install-kind
RUN make install-kubebuilder
RUN make install-kustomize
RUN make install-test-dependencies
# Install Go test dependencies
&& GO111MODULE=on go get -v \
github.com/jstemmer/go-junit-report@latest \
github.com/axw/gocov/gocov@latest \
github.com/AlekSi/gocov-xml \
github.com/wadey/gocovmerge \
2>&1

# Set the default shell to bash instead of sh
ENV SHELL /bin/bash
# Copy shares from localhost into container when new shells are created
RUN echo '\n\
if [ -d "/usr/local/share/kube-localhost" ]; then\n\
mkdir -p $HOME/.kube\n\
cp -r /usr/local/share/kube-localhost/* $HOME/.kube\n\
chown -R $(id -u) $HOME/.kube\n\
sed -i -e "s/localhost/host.docker.internal/g" $HOME/.kube/config\n\
\n\
if [ -d "/usr/local/share/minikube-localhost" ]; then\n\
mkdir -p $HOME/.minikube\n\
cp -r /usr/local/share/minikube-localhost/ca.crt $HOME/.minikube\n\
cp -r /usr/local/share/minikube-localhost/client.crt $HOME/.minikube\n\
cp -r /usr/local/share/minikube-localhost/client.key $HOME/.minikube\n\
chown -R $(id -u) $HOME/.minikube\n\
sed -i -r "s|(\s*certificate-authority:\s).*|\\1$HOME\/.minikube\/ca.crt|g" $HOME/.kube/config\n\
sed -i -r "s|(\s*client-certificate:\s).*|\\1$HOME\/.minikube\/client.crt|g" $HOME/.kube/config\n\
sed -i -r "s|(\s*client-key:\s).*|\\1$HOME\/.minikube\/client.key|g" $HOME/.kube/config\n\
fi\n\
fi\n\
if [ -d "/usr/local/share/azure-localhost" ]; then\n\
mkdir -p $HOME/.azure\n\
cp -r /usr/local/share/azure-localhost/* $HOME/.azure\n\
chown -R $(id -u) $HOME/.azure\n\
fi' | tee -a /root/.bashrc /root/.zshrc /home/${USERNAME}/.bashrc >> /home/${USERNAME}/.zshrc
4 changes: 0 additions & 4 deletions .devcontainer/build.sh

This file was deleted.

76 changes: 55 additions & 21 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,59 @@
// 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",
"workspaceFolder": "/workspace",
"shutdownAction": "stopCompose",
"postCreateCommand": "make set-kindcluster",
"extensions": [
"ms-azuretools.vscode-docker",
"ms-vscode.go"
"name": "ASO",
"dockerFile": "Dockerfile",

"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt", "seccomp=unconfined",
"--env-file=${localWorkspaceFolder}/.env"
],

"settings": {
"terminal.integrated.shell.linux": "zsh",
"go.gopath": "/go",
"go.inferGopath": true,
"go.useLanguageServer": true,
"go.toolsEnvVars": {
"GO111MODULE": "on"
},
"remote.extensionKind": {
"ms-azuretools.vscode-docker": "workspace"
}
}
"terminal.integrated.shell.linux": "zsh",
"go.gopath": "/go",
"go.useLanguageServer": true,
"[go]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
},
// Optional: Disable snippets, as they conflict with completion ranking.
"editor.snippetSuggestions": "none",
},
"[go.mod]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
},
},
"gopls": {
// Add parameter placeholders when completing a function.
"usePlaceholders": true,

// If true, enable additional analyses with staticcheck.
// Warning: This will significantly increase memory usage.
"staticcheck": false,
}
},

"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker-host.sock,type=bind",
// Comment the next line to avoid syncing your kubeconfig
"source=${env:HOME}${env:USERPROFILE}/.kube,target=/usr/local/share/kube-localhost,type=bind",
// Uncomment the next line to also sync certs in your .minikube folder
// "source=${env:HOME}${env:USERPROFILE}/.minikube,target=/usr/local/share/minikube-localhost,type=bind",
// Comment the next line to avoid syncing azure cli config
"source=${env:HOME}${env:USERPROFILE}/.azure,target=/usr/local/share/azure-localhost,type=bind",
],

"extensions": [
"ms-vscode.go",
"ms-vscode.azurecli",
"ms-azuretools.vscode-docker",
"ms-kubernetes-tools.vscode-kubernetes-tools"
],

"remoteEnv": {
"GO111MODULE": "on",
},
}
22 changes: 0 additions & 22 deletions .devcontainer/docker-compose.yml

This file was deleted.

43 changes: 15 additions & 28 deletions docs/howto/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,35 +159,22 @@ Then, open a web browser and navigate to the [Metrics Endpoint](http://127.0.0.1
If you're using VSCode with [Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extensions installed, you can quickly have your environment set up and ready to go, with everything you need to get started.
1. Clone the repository into the following folder `~/go/src/github.com/Azure`.
2. Make sure the environment variable `GO111MODULE` is set to `on`.
```
export GO111MODULE=on
```
3. Install test certificates using `make generate-test-certs`.
4. Open this folder `~/go/src/github.com/Azure` in VSCode.
5. Inside the folder `.devcontainer`, create a file called `.env` and using the following template, copy your environment variable details.
```txt
AZURE_CLIENT_ID=
AZURE_CLIENT_SECRET=
AZURE_SUBSCRIPTION_ID=
AZURE_TENANT_ID=
```
6. Open the Command Pallet (`Command+Shift+P` on MacOS or `CTRL+Shift+P` on Windows), type `Remote-Containers: Open Folder in Container...`, select the ```Azure-service-operator``` folder and hit enter.
7. VSCode will relaunch and start building our development container. This will install all the necessary dependencies required for you to begin developing.
8. Once the container has finished building, you can now start testing your Azure Service Operator within your own local kubernetes environment via the terminal inside VSCode.
**Note**: after the DevContainer has finished building, the Kind cluster will start initializing and installing the Azure Service Operator in the background. This will take some time before it is available.
1. Clone the repository and open the folder in VS Code. (will refer to the folder as PROJECT_DIR)
2. Create a new file at $PROJECT_DIR/.env with the following variables set for your environment:
```
AZURE_TENANT_ID=
AZURE_SUBSCRIPTION_ID=
AZURE_CLIENT_ID=
AZURE_CLIENT_SECRET=
```
To see when the Kind cluster is ready, use `docker ps -a` to list your running containers, look for `IMAGE` with the name `azure-service-operator_devcontainer_docker-in-docker...`. Using that image's `CONTAINER ID`, use `docker logs -f CONTAINER ID` to view the logs from the container setting up your cluster.
9. Use `kubectl apply` with the sample YAML files to create custom resources for testing.
3. Click on the green button in the lower left-hand corner and select "Remote-Containers: Reopen in Container" from the drop-down
4. VSCode will relaunch and start building our development container. This will install all the necessary dependencies required for you to begin developing.
5. Once the container has finished building, you can now start testing your Azure Service Operator within your own local kubernetes environment via the terminal inside VSCode.
6. Install test certificates using `make generate-test-certs`.
7. Install CRDs using `make install`.
8. Run the project using `make run`.
9. In another terminal, use `kubectl apply` with the sample YAML files to create custom resources for testing.
For eg., use `kubectl apply -f config/samples/azure_v1alpha1_azuresqlserver.yaml` from the terminal to create a SQL server using the operator.
`kubectl describe SqlServer` would show the events that indicate if the resource is created or being created.
Expand Down

0 comments on commit 1a76b69

Please sign in to comment.