Skip to content

Commit

Permalink
fix(tests): đŸ§ª resolve failing test cases and improve local testing au…
Browse files Browse the repository at this point in the history
…tomation (#7)

- Resolve failing test cases, as the new actions are increased based by 1.

docs

- Add helm README docs using `helm-docs` project.

chore

- Include `.envrc` for Linux/macOS using direnv for loading default environment settings.
- Include devcontainer configuration for codespace/remote container development in pre-built container.
- add mage tasks for automation of:
    - k8s
    - kind cluster local spin-up
    - go tooling setup
    - helm usage (via direct package usage). If values templates are not found then automationally create a cached copy for editing when installing, allowing developer to tweak.

- add golangci-lint configuration

refactor

- Minor code formatting adjustment.
- Minor test output improvements for debugging failed test cases.
- Disabled log output in test suite.

build

- Add precommit configuration.
- Add linting configuration, including Trunk for linting.
- Improve Make with help output.
  • Loading branch information
sheldonhull authored Jul 27, 2022
1 parent e30a21e commit 49e8f88
Show file tree
Hide file tree
Showing 56 changed files with 4,874 additions and 168 deletions.
44 changes: 44 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Note: You can use any Debian/Ubuntu based image you want.
FROM mcr.microsoft.com/vscode/devcontainers/universal:2-focal


# Enable new "BUILDKIT" mode for Docker CLI
ENV DOCKER_BUILDKIT=1

# Options
ARG INSTALL_ZSH="true"
ARG UPGRADE_PACKAGES="false"
ARG USE_MOBY="true"
ARG USERNAME=codespace
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ARG ENABLE_NONROOT_DOCKER="true"
ARG DOCKER_VERSION="latest"
# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies.
USER root
COPY library-scripts/*.sh /tmp/library-scripts/
RUN apt-get update && /bin/bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \
&& /bin/bash /tmp/library-scripts/docker-in-docker-debian.sh "${ENABLE_NONROOT_DOCKER}" "${USERNAME}" "${USE_MOBY}" "${DOCKER_VERSION}" \
&& /bin/bash /tmp/library-scripts/kubectl-helm-debian.sh "latest" "latest" "latest" \
&& mkdir -p /home/${USERNAME}/.minikube \
&& chown ${USERNAME} /home/${USERNAME}/.minikube \
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts/
VOLUME [ "/var/lib/docker" ]
ENTRYPOINT ["/usr/local/share/docker-init.sh"]
CMD ["sleep", "infinity"]
RUN $(curl -fSSl https://github.com/wercker/stern/releases/download/1.11.0/stern_linux_amd64 -o ./stern) && chmod +x ./stern && mv ./stern /usr/local/bin/ && echo 'stern log tool installed'
ENV GOROOT=
ENV GOPATH=/home/${USERNAME}/go
ENV PATH=/home/${USERNAME}/go/bin:$PATH

USER ${USERNAME}


# Setting the ENTRYPOINT to docker-init.sh will start up the Docker Engine
# inside the container "overrideCommand": false is set in devcontainer.json.
# The script will also execute CMD if you need to alter startup behaviors.


# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
59 changes: 59 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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.241.1/containers/kubernetes-helm-minikube
{
"name": "dsv-k8s-codespace",
"dockerFile": "Dockerfile",
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined",
"--privileged",
"--init"
],
"mounts": [
"source=minikube-var-lib-docker,target=/var/lib/docker,type=volume",
"source=minikube-config,target=/home/codespace/.minikube,type=volume",
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.kube,target=/home/codespace/.kube/,type=bind,consistency=cached", // support for SSH keys
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.ssh,target=/home/codespace/.ssh/,type=bind,consistency=cached", // support for SSH keys
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.envrc,target=/home/codespace/.envrc,type=bind,consistency=cached", // envrc from home to allow direnv to mount credentials
// cache gopath directory
"source=go-path,target=/home/vscode/go/,type=volume",
// caching for zsh history, zoxide and others, allowing it to persist after rebuild.
"source=zshcache,target=/home/vscode/.zsh.cache/,type=volume"
],
"overrideCommand": false,
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-azuretools.vscode-docker",
"ms-kubernetes-tools.vscode-kubernetes-tools",
"spmeesseman.vscode-taskexplorer",
"ms-kubernetes-tools.kind-vscode",
"trunk.io",
"GitHub.vscode-pull-request-github",
"yzhang.markdown-all-in-one"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "kubectl version",
// Use 'postStartCommand' to run commands after the container is created like starting minikube.
// "postStartCommand": "nohup bash -c 'minikube start &' > minikube.log 2>&1",
// Minikube does not like running as root, so use a non-root user.
"remoteUser": "codespace",
"features": {
"kubectl-helm-minikube": "latest",
"golang": "latest",
"github-cli": "latest"
},
"containerEnv": {
"GITHUB_OATH_TOKEN": "${env:GITHUB_OATH_TOKEN}",
"GOPATH": "/home/codespace/go/",
"GOROOT": ""
}
}
142 changes: 142 additions & 0 deletions .devcontainer/library-scripts/awscli-debian.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#!/usr/bin/env bash
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
#
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/awscli.md
# Maintainer: The VS Code and Codespaces Teams
#
# Syntax: ./awscli-debian.sh [AWS CLI version]

set -e

AWSCLI_VERSION=${1:-"latest"}
AWSCLI_GPG_KEY=FB5DB77FD5C118B80511ADA8A6310ACC4672475C
AWSCLI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mmFNNegG0Ox
au+VnpcR5Kz3smiTrIwZbRudo1ijhCYPQ7t5CMp9kjC6bObvy1hSIg2xNbMAN/Do
ikebAl36uA6Y/Uczjj3GxZW4ZWeFirMidKbtqvUz2y0UFszobjiBSqZZHCreC34B
hw9bFNpuWC/0SrXgohdsc6vK50pDGdV5kM2qo9tMQ/izsAwTh/d/GzZv8H4lV9eO
tEis+EpR497PaxKKh9tJf0N6Q1YLRHof5xePZtOIlS3gfvsH5hXA3HJ9yIxb8T0H
QYmVr3aIUes20i6meI3fuV36VFupwfrTKaL7VXnsrK2fq5cRvyJLNzXucg0WAjPF
RrAGLzY7nP1xeg1a0aeP+pdsqjqlPJom8OCWc1+6DWbg0jsC74WoesAqgBItODMB
rsal1y/q+bPzpsnWjzHV8+1/EtZmSc8ZUGSJOPkfC7hObnfkl18h+1QtKTjZme4d
H17gsBJr+opwJw/Zio2LMjQBOqlm3K1A4zFTh7wBC7He6KPQea1p2XAMgtvATtNe
YLZATHZKTJyiqA==
=vYOk
-----END PGP PUBLIC KEY BLOCK-----"

if [ "$(id -u)" -ne 0 ]; then
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
fi

# Get central common setting
get_common_setting() {
if [ "${common_settings_file_loaded}" != "true" ]; then
curl -sfL "https://aka.ms/vscode-dev-containers/script-library/settings.env" -o /tmp/vsdc-settings.env 2>/dev/null || echo "Could not download settings file. Skipping."
common_settings_file_loaded=true
fi
if [ -f "/tmp/vsdc-settings.env" ]; then
local multi_line=""
if [ "$2" = "true" ]; then multi_line="-z"; fi
local result="$(grep ${multi_line} -oP "$1=\"?\K[^\"]+" /tmp/vsdc-settings.env | tr -d '\0')"
if [ ! -z "${result}" ]; then declare -g $1="${result}"; fi
fi
echo "$1=${!1}"
}

# Function to run apt-get if needed
apt_get_update_if_needed() {
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
echo "Running apt-get update..."
apt-get update
else
echo "Skipping apt-get update."
fi
}

# Checks if packages are installed and installs them if not
check_packages() {
if ! dpkg -s "$@" >/dev/null 2>&1; then
apt_get_update_if_needed
apt-get -y install --no-install-recommends "$@"
fi
}

export DEBIAN_FRONTEND=noninteractive

check_packages curl ca-certificates gnupg2 dirmngr unzip

verify_aws_cli_gpg_signature() {
local filePath=$1
local sigFilePath=$2

get_common_setting AWSCLI_GPG_KEY
get_common_setting AWSCLI_GPG_KEY_MATERIAL true
local awsGpgKeyring=aws-cli-public-key.gpg

echo "${AWSCLI_GPG_KEY_MATERIAL}" | gpg --dearmor >"./${awsGpgKeyring}"
gpg --batch --quiet --no-default-keyring --keyring "./${awsGpgKeyring}" --verify "${sigFilePath}" "${filePath}"
local status=$?

rm "./${awsGpgKeyring}"

return ${status}
}

install() {
local scriptZipFile=awscli.zip
local scriptSigFile=awscli.sig

# See Linux install docs at https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
if [ "${AWSCLI_VERSION}" != "latest" ]; then
local versionStr=-${AWSCLI_VERSION}
fi
architecture=$(dpkg --print-architecture)
case "${architecture}" in
amd64) architectureStr=x86_64 ;;
arm64) architectureStr=aarch64 ;;
*)
echo "AWS CLI does not support machine architecture '$architecture'. Please use an x86-64 or ARM64 machine."
exit 1
;;
esac
local scriptUrl=https://awscli.amazonaws.com/awscli-exe-linux-${architectureStr}${versionStr}.zip
curl "${scriptUrl}" -o "${scriptZipFile}"
curl "${scriptUrl}.sig" -o "${scriptSigFile}"

verify_aws_cli_gpg_signature "$scriptZipFile" "$scriptSigFile"
if (($? > 0)); then
echo "Could not verify GPG signature of AWS CLI install script. Make sure you provided a valid version."
exit 1
fi

unzip "${scriptZipFile}"
./aws/install

rm -rf ./aws
}

echo "(*) Installing AWS CLI..."

install

echo "Done!"
Loading

0 comments on commit 49e8f88

Please sign in to comment.