Skip to content

Commit

Permalink
feat: running locally through dev container (#8677)
Browse files Browse the repository at this point in the history
* test: test

Signed-off-by: Tianchu Zhao <[email protected]>

* docs: add dev-container notes

Signed-off-by: Tianchu Zhao <[email protected]>

* fix: removed unused devcontainer feature

Signed-off-by: Tianchu Zhao <[email protected]>

* fix: move devcontainer features kubectl/git to DOCKERFILE, siwtch to bullseye variant

Signed-off-by: Tianchu Zhao <[email protected]>

* fix: rephrase sentence according to comments

Signed-off-by: Tianchu Zhao <[email protected]>

* fix: add k3d start wait according to comments

Signed-off-by: Tianchu Zhao <[email protected]>

* fix: spell check dictionary

Signed-off-by: Tianchu Zhao <[email protected]>

* fix: add running locally timings

Signed-off-by: Tianchu Zhao <[email protected]>

* fix: use Home/go as GOPATH due mac doesnt support write at root level

Signed-off-by: Tianchu Zhao <[email protected]>

* fix: doc apple silicon typo

Signed-off-by: Tianchu Zhao <[email protected]>

* fix: set kube/config post k3d creation

Signed-off-by: Tianchu Zhao <[email protected]>

* fix: move features to DOCKERFILE and pin versions

Signed-off-by: Tianchu Zhao <[email protected]>

* fix: chown on GOPATH instead of ~, ~ in mac starts from Users instead of home, this can cause issues

Signed-off-by: Tianchu Zhao <[email protected]>

* docs: add running-locally linux notes

Signed-off-by: Tianchu Zhao <[email protected]>

* docs: running-locally, update manual setup time

Signed-off-by: Tianchu Zhao <[email protected]>
  • Loading branch information
tczhao committed May 12, 2022
1 parent 515e076 commit 1f2417e
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 4 deletions.
41 changes: 41 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.234.0/containers/debian/.devcontainer/base.Dockerfile

ARG VARIANT="bullseye"
FROM --platform=linux/amd64 mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}

ARG NEW_USERNAME=""
ARG HOME=""
ARG OLD_USERNAME="vscode"
ARG VSCODE_SCRIPT_VERSION=""

ARG PROTOC_ZIP="protoc-3.14.0-linux-x86_64.zip"
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get install -y apt-transport-https ca-certificates git sudo \
# use new user instead of vscode user
&& usermod -l $NEW_USERNAME -d /home/$NEW_USERNAME -m $OLD_USERNAME \
&& groupmod -n $NEW_USERNAME $OLD_USERNAME \
&& echo $NEW_USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$NEW_USERNAME \
&& chmod 0440 /etc/sudoers.d/$NEW_USERNAME \
# kubectl
&& curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg \
&& echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list \
&& apt-get update \
&& apt-get install -y kubectl \
# protobuf
&& curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/${PROTOC_ZIP} \
&& unzip -o ${PROTOC_ZIP} -d /usr/local bin/protoc \
&& unzip -o ${PROTOC_ZIP} -d /usr/local 'include/*' \
&& rm -f ${PROTOC_ZIP} \
&& chmod 755 /usr/local/bin/protoc \
&& chmod -R 755 /usr/local/include/ \
# k3d
&& wget -q -O - https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash \
# go
&& bash -ec "$(curl -fsSL "https://raw.githubusercontent.com/microsoft/vscode-dev-containers/$VSCODE_SCRIPT_VERSION/script-library/go-debian.sh")" -- "1.18" "/usr/local/go" "$HOME/go" "automatic" "true" "false" \
# dind
&& bash -ec "$(curl -fsSL "https://raw.githubusercontent.com/microsoft/vscode-dev-containers/$VSCODE_SCRIPT_VERSION/script-library/docker-in-docker-debian.sh")" -- "true" "automatic" "true" "20.10" "v1" \
# node
&& bash -ec "$(curl -fsSL "https://raw.githubusercontent.com/microsoft/vscode-dev-containers/$VSCODE_SCRIPT_VERSION/script-library/node-debian.sh")" -- "/usr/local/share/nvm" "16" "automatic" "true" "true" \
# python
&& bash -ec "$(curl -fsSL "https://raw.githubusercontent.com/microsoft/vscode-dev-containers/$VSCODE_SCRIPT_VERSION/script-library/python-debian.sh")" -- "3.9" \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
30 changes: 30 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.234.0/containers/debian
{
"name": "Debian",
"build": {
"dockerfile": "Dockerfile",
"args": {
"VARIANT": "bullseye",
"NEW_USERNAME": "${localEnv:USER}",
"HOME": "${localEnv:HOME}",
"VSCODE_SCRIPT_VERSION": "v0.234.0"
}
},

"settings": {},

"extensions": [],

"mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ],

"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],

"remoteUser": "${localEnv:USER}",
"features": {},

"workspaceMount": "source=${localWorkspaceFolder},target=${localEnv:HOME}/go/src/github.com/argoproj/argo-workflows,type=bind",
"workspaceFolder": "${localEnv:HOME}/go/src/github.com/argoproj/argo-workflows",

"postCreateCommand": "bash -i .devcontainer/startup.sh"
}
18 changes: 18 additions & 0 deletions .devcontainer/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -e

sudo apt update
sudo chown $USER:docker /var/run/docker.sock
sudo chown -fR $USER:golang $GOPATH

echo '127.0.0.1 dex\n127.0.0.1 minio\n127.0.0.1 postgres\n127.0.0.1 mysql' | sudo tee -a /etc/hosts

if k3d cluster list | grep k3s-default;
then
echo "skip k3s creation, k3s-default cluster already exist"
else
k3d cluster create
fi

until k3d cluster start --wait ; do sleep 5 ; done
k3d kubeconfig merge k3s-default --kubeconfig-merge-default --kubeconfig-switch-context
4 changes: 4 additions & 0 deletions .spelling
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ backend
blkperl
boolean
booleans
buildkit
config
cpu
cron
daemoned
dev-container
dinever
dropdown
e.g.
Expand All @@ -131,6 +133,7 @@ i.e.
instantiator
instantiators
jenkins
k3d
k8s-jobs
kube
kubelet
Expand All @@ -147,6 +150,7 @@ namespaces
natively
p.m.
params
pre-commit
rc2
repo
roadmap
Expand Down
41 changes: 37 additions & 4 deletions docs/running-locally.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
# Running Locally

You have two options:

1. If you're using VSCode, you use the Dev-Container. This takes about 7 minutes. Pre-commit checks take about 4 minutes to run.
1. Install the requirements on your computer manually. This takes about 1 hour. Pre-commit checks take about 3 minutes to run.

## Git Clone

Close the Git repo into: `$(GOPATH)/src/github.com/argoproj/argo-workflows`. Any other path will mean the code
generation does not work.

## Development Container

A development container is a running Docker container with a well-defined tool/runtime stack and its prerequisites.
[The Visual Studio Code Remote - Containers](https://code.visualstudio.com/docs/remote/containers) extension lets you use a Docker container as a full-featured development environment.

System requirements can be found [here](https://code.visualstudio.com/docs/remote/containers#_system-requirements)

Note:

* `GOPATH` must be `$HOME/go`.
* for **Apple Silicon**
* This platform can spend 3 times the indicated time
* Configure Docker Desktop to use BuildKit:

```json
"features": {
"buildkit": false
},
```

* For **Windows WSL2**
* Configure [`.wslconfig`](https://docs.microsoft.com/en-us/windows/wsl/wsl-config#configuration-setting-for-wslconfig) to limit memory usage by the WSL2 to prevent VSCode OOM.

* For **Linux**
* Use [Docker Desktop](https://docs.docker.com/desktop/linux/install/) instead of [Docker Engine](https://docs.docker.com/engine/install/) to prevent incorrect network configuration by k3d

## Requirements

* [Go 1.18](https://golang.org/dl/)
Expand All @@ -20,14 +56,11 @@ Alternatively, you can use [Minikube](https://github.com/kubernetes/minikube) to
Once a local Kubernetes cluster has started via `minikube start`, your kube config will use Minikube's context
automatically.

⚠️ Do not use Docker for Desktop, it does not support Kubernetes RBAC (i.e. `kubectl auth can-i` always
⚠️ Do not use Docker for Desktop with its embedded Kubernetes, it does not support Kubernetes RBAC (i.e. `kubectl auth can-i` always
returns `allowed`).

## Developing locally

Close the Git repo into: `$(GOPATH)/src/github.com/argoproj/argo-workflows`. Any other path will mean the code
generation does not work.

Add the following to your `/etc/hosts`:

```text
Expand Down

0 comments on commit 1f2417e

Please sign in to comment.