This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add install script for those not using devcontainer (#322)
This installs the tools to `$clone/hack/tools` instead. There is a `dev.sh` script to run to get into a shell with a `PATH` pointing to the right place.
- Loading branch information
Showing
5 changed files
with
167 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,44 +14,21 @@ RUN apt-get update \ | |
# RUN curl -fsSL https://get.docker.com | sh - | ||
# RUN usermod -aG docker vscode | ||
|
||
# Go dependencies | ||
ENV GO111MODULE=on | ||
RUN mkdir -p /tmp/gotools \ | ||
&& export GOPATH=/tmp/gotools \ | ||
&& export GOCACHE=/tmp/gotools/cache \ | ||
&& go get \ | ||
# go tools for vscode are preinstalled by base image (see first comment in Dockefile) | ||
# golangci-lint is provided by base image | ||
github.com/jandelgado/[email protected] \ | ||
github.com/mitchellh/[email protected] \ | ||
k8s.io/code-generator/cmd/[email protected] \ | ||
sigs.k8s.io/controller-tools/cmd/[email protected] \ | ||
sigs.k8s.io/[email protected] \ | ||
sigs.k8s.io/kustomize/kustomize/[email protected] \ | ||
&& mv /tmp/gotools/bin/* /usr/local/bin/ \ | ||
&& rm -rf /tmp/gotools | ||
|
||
# install kubectl | ||
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.19.0/bin/linux/amd64/kubectl \ | ||
&& chmod +x ./kubectl \ | ||
&& mv ./kubectl /usr/local/bin/kubectl | ||
|
||
# install go-task (as task runner) | ||
RUN curl -sL "https://github.com/go-task/task/releases/download/v3.0.0/task_linux_amd64.tar.gz" | tar xz -C /usr/local/bin task | ||
RUN curl -sL "https://raw.githubusercontent.com/go-task/task/v3.0.0/completion/bash/task.bash" > "/home/vscode/.oh-my-bash/completions/task.completion.sh" | ||
COPY install-dependencies.sh . | ||
RUN ./install-dependencies.sh devcontainer && rm install-dependencies.sh | ||
|
||
# install kubebuilder | ||
RUN os=$(go env GOOS) \ | ||
&& arch=$(go env GOARCH) \ | ||
&& curl -L https://go.kubebuilder.io/dl/2.3.1/${os}/${arch} | tar -xz -C /tmp/ \ | ||
&& mv /tmp/kubebuilder_2.3.1_${os}_${arch} /usr/local/kubebuilder | ||
# Add kubebuilder to PATH | ||
ENV PATH=$PATH:/usr/local/kubebuilder/bin | ||
|
||
# add bash customizations | ||
# Add further bash customizations | ||
# note that the base image includes oh-my-bash, we are enabling plugins here | ||
RUN sed -i '/^plugins=/a kubectl\ngolang' "/home/vscode/.bashrc" | ||
RUN sed -i '/^completions=/a kubectl\ngo\ntask' "/home/vscode/.bashrc" | ||
# make kubectl completions work with 'k' alias | ||
|
||
# Make kubectl completions work with 'k' alias | ||
RUN echo 'complete -F __start_kubectl k' >> "/home/vscode/.bashrc" | ||
|
||
# Setup go-task completions | ||
RUN curl -sL "https://raw.githubusercontent.com/go-task/task/v3.0.0/completion/bash/task.bash" > "/home/vscode/.oh-my-bash/completions/task.completion.sh" | ||
|
||
ENV KIND_CLUSTER_NAME=k8sinfra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/bin/sh | ||
|
||
set -eu | ||
|
||
# This script must run in two modes: | ||
# | ||
# - When being used to set up a devcontainer. | ||
# In this mode the code is not checked out yet, | ||
# and we can install the tools globally. | ||
# | ||
# - When being used to install tools locally. | ||
# In this mode the code is already checked out, | ||
# and we do not want to pollute the user’s system. | ||
# | ||
# To distinguish between these modes we will | ||
# have the devcontainer script pass an argument: | ||
|
||
if [ "$1" = "devcontainer" ]; then | ||
TOOL_DEST=/usr/local/bin | ||
KUBEBUILDER_DEST=/usr/local/kubebuilder | ||
else | ||
TOOL_DEST=$(git rev-parse --show-toplevel)/hack/tools | ||
mkdir -p "$TOOL_DEST" | ||
KUBEBUILDER_DEST="$TOOL_DEST/kubebuilder" | ||
fi | ||
|
||
if ! command -v go > /dev/null 2>&1; then | ||
echo "Go must be installed manually: https://golang.org/doc/install" | ||
exit 1 | ||
fi | ||
|
||
if ! command -v az > /dev/null 2>&1; then | ||
echo "Azure CLI must be installed manually: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli" | ||
exit 1 | ||
fi | ||
|
||
echo "Installing tools to $TOOL_DEST" | ||
|
||
# Install Go tools | ||
TMPDIR=$(mktemp -d) | ||
clean() { | ||
rm -rf "$TMPDIR" | ||
} | ||
trap clean EXIT | ||
|
||
export GOBIN=$TOOL_DEST | ||
export GOPATH=$TMPDIR | ||
export GOCACHE=$TMPDIR/cache | ||
export GO111MODULE=on | ||
|
||
echo "Installing Go tools…" | ||
|
||
# go tools for vscode are preinstalled by base image (see first comment in Dockerfile) | ||
go get \ | ||
github.com/jandelgado/[email protected] \ | ||
github.com/mitchellh/[email protected] \ | ||
k8s.io/code-generator/cmd/[email protected] \ | ||
sigs.k8s.io/controller-tools/cmd/[email protected] \ | ||
sigs.k8s.io/[email protected] \ | ||
sigs.k8s.io/kustomize/kustomize/[email protected] | ||
|
||
if [ "$1" != "devcontainer" ]; then | ||
echo "Installing golangci-lint…" | ||
# golangci-lint is provided by base image if in devcontainer | ||
# this command copied from there | ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$TOOL_DEST" 2>&1 | ||
fi | ||
|
||
echo "Installing kubectl…" | ||
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.19.0/bin/linux/amd64/kubectl \ | ||
&& chmod +x ./kubectl \ | ||
&& mv ./kubectl "$TOOL_DEST/kubectl" | ||
|
||
# Install go-task (task runner) | ||
echo "Installing go-task…" | ||
curl -sL "https://github.com/go-task/task/releases/download/v3.0.0/task_linux_amd64.tar.gz" | tar xz -C "$TOOL_DEST" task | ||
|
||
# Install kubebuilder | ||
echo "Installing kubebuilder…" | ||
os=$(go env GOOS) | ||
arch=$(go env GOARCH) | ||
curl -L "https://go.kubebuilder.io/dl/2.3.1/${os}/${arch}" | tar -xz -C /tmp/ | ||
mv "/tmp/kubebuilder_2.3.1_${os}_${arch}" "$KUBEBUILDER_DEST" | ||
|
||
echo "Installed tools: $(ls "$TOOL_DEST")" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/sh | ||
|
||
set -eu | ||
|
||
GIT_ROOT=$(git rev-parse --show-toplevel) | ||
TOOL_DEST=$GIT_ROOT/hack/tools | ||
|
||
if [ ! -f "$TOOL_DEST/task" ]; then # check for local installation | ||
if [ ! -f "/usr/local/bin/task" ]; then # or devcontainer installation | ||
$GIT_ROOT/.devcontainer/install-dependencies.sh local # otherwise, install the tools | ||
fi | ||
fi | ||
|
||
export PATH="$PATH:$TOOL_DEST:$TOOL_DEST/kubebuilder/bin" | ||
|
||
echo "Entering $SHELL with expanded PATH (use 'exit' to quit):" | ||
echo "Try running 'task -l' to see possible commands." | ||
$SHELL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"folders": [ | ||
{ | ||
"path": "." | ||
}, | ||
{ | ||
"path": "hack/generated" | ||
}, | ||
|