From b30caf18f4baab5f8b0e9c315846c808169b205d Mon Sep 17 00:00:00 2001 From: Xenion1987 <39803750+Xenion1987@users.noreply.github.com> Date: Wed, 26 Jun 2024 23:34:29 +0200 Subject: [PATCH] update: devcontainer --- .devcontainer/Dockerfile | 55 +-- .devcontainer/devcontainer.json | 162 ++++---- .devcontainer/requirements.txt | 1 + .devcontainer/scripts/post-create-command.sh | 90 ++++- .../scripts/setup-docker-container.sh | 352 +++++++++++++++--- 5 files changed, 493 insertions(+), 167 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 52c42f0..6513130 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,53 +1,18 @@ FROM python:slim-bookworm # Set Variables -ARG LINUX_USER=vscode -ARG TF_VERSION=1.6.6 -ARG TFDOCS_VERSION=latest -ARG TFLINT_VERSION=latest -ARG TFTRIVY_VERSION=latest -ARG TERRAGRUNT_VERSION=latest +ARG LINUX_USER +ARG TERRAFORM_VERSION +ARG TERRAFORMER_VERSION +ARG TFDOCS_VERSION +ARG TFLINT_VERSION +ARG TFTRIVY_VERSION +ARG TERRAGRUNT_VERSION # Copy setup script COPY ./scripts/setup-docker-container.sh /tmp +COPY requirements.txt /tmp # Install all applications -RUN /tmp/setup-docker-container.sh install all ${TF_VERSION} ${TFDOCS_VERSION} ${TFLINT_VERSION} ${TFTRIVY_VERSION} ${TERRAGRUNT_VERSION} - -# # Install OS requirements -# RUN /tmp/setup-docker-container.sh install os-requirements - -# # Install pip -# RUN /tmp/setup-docker-container.sh install pip - -# # Install pip requirements -# RUN /tmp/setup-docker-container.sh install pip-requirements - -# # Install Terraform and Terraform tools -# RUN /tmp/setup-docker-container.sh install terraform ${TF_VERSION} \ -# && /tmp/setup-docker-container.sh install terraform-docs ${TFDOCS_VERSION} \ -# && /tmp/setup-docker-container.sh install terragrunt ${TERRAGRUNT_VERSION} \ -# && /tmp/setup-docker-container.sh install tflint ${TFLINT_VERSION} \ -# && /tmp/setup-docker-container.sh install trivy ${TFTRIVY_VERSION} - - -# # Install Pre-Commit -# RUN /tmp/setup-docker-container.sh install pre-commit - -# # Setup python-argcomplete -# RUN /tmp/setup-docker-container.sh setup python-argcomplete - -# # Setup default user -# RUN /tmp/setup-docker-container.sh setup user ${LINUX_USER} - -# # Setup default user id_rsa ssh keypair -# RUN /tmp/setup-docker-container.sh setup ssh-key ${LINUX_USER} - -# # Set default user -# USER ${LINUX_USER} -# WORKDIR /home/${LINUX_USER} - -# # Setup oh-my-bash -# RUN /tmp/setup-docker-container.sh setup oh-my-bash - -# HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD [ "pgrep bash" ] +RUN chmod +x /tmp/setup-docker-container.sh && \ + /tmp/setup-docker-container.sh install all terraform ${TERRAFORM_VERSION} ${TERRAFORMER_VERSION} ${TFDOCS_VERSION} ${TFLINT_VERSION} ${TFTRIVY_VERSION} ${TERRAGRUNT_VERSION} diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index aa4eb54..3a23900 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,78 +1,98 @@ { - "name": "terraform-playground", - "build": { - "dockerfile": "./Dockerfile", - "args": { - "-t": "local/terraform-playground" - }, - "context": "." - }, - "runArgs": [ - "--name=terraform-playground", - "--hostname=terraform" - ], - "initializeCommand": "bash ./.devcontainer/scripts/initialize-command.sh", - "onCreateCommand": "bash ./.devcontainer/scripts/on-create-command.sh", - "postCreateCommand": "bash ./.devcontainer/scripts/post-create-command.sh", - "remoteUser": "vscode", - // "remoteEnv": { - // "PATH": "${containerEnv:PATH}:/home/vscode/.local/bin" + "name": "terraform", + // "image": "git.dogado.net:5000/mcs/eaa/docker-image-terraform:latest", + "build": { + // "args": { + // "LINUX_USER": "", + // "TERRAFORM_VERSION": "", + // "TERRAFORMER_VERSION": "", + // "TFDOCS_VERSION": "", + // "TFLINT_VERSION": "", + // "TFTRIVY_VERSION": "", + // "TERRAGRUNT_VERSION": "" // }, - "features": { - // https://github.com/devcontainers/features/tree/main/src/common-utils - "ghcr.io/devcontainers/features/common-utils:2": { - // "upgradePackages": "true", - "installZsh": "false", - "configureZshAsDefaultShell": "false", - // "userUid": "1000", - // "userGid": "1000", - "username": "vscode" + "dockerfile": "Dockerfile" + }, + "runArgs": [ + "--hostname=terraform" + ], + "initializeCommand": "bash ./.devcontainer/scripts/initialize-command.sh", + "onCreateCommand": "bash ./.devcontainer/scripts/on-create-command.sh", + "postCreateCommand": "bash ./.devcontainer/scripts/post-create-command.sh", + "containerEnv": { + "TZ": "Europe/Berlin" + }, + "remoteUser": "vscode", + "remoteEnv": { + "PATH": "${containerEnv:PATH}:/home/vscode/.local/bin:/workspaces/terraform-playground/.devcontainer/scripts" + }, + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "installZsh": "false", + "configureZshAsDefaultShell": "false", + "username": "vscode", + // "userUid": "1000", + // "userGid": "1000", + "upgradePackages": "false" + } + }, + "customizations": { + "vscode": { + "settings": { + "telemetry.telemetryLevel": "off", + "files.eol": "\n", + "files.insertFinalNewline": true, + "files.autoSave": "off", + "editor.formatOnSave": true, + "editor.tabSize": 2, + "git.autorefresh": true, + "git.autofetch": true, + "git.autofetchPeriod": 90, + "git.pullTags": false, + "git.confirmSync": false, + "terminal.integrated.scrollback": 10000, + "[markdown]": { + "editor.defaultFormatter": "yzhang.markdown-all-in-one", + "editor.tabSize": 3 + }, + "[terraform]": { + "editor.defaultFormatter": "hashicorp.terraform" }, - // https://github.com/devcontainers/features/tree/main/src/docker-outside-of-docker - "ghcr.io/devcontainers/features/docker-outside-of-docker": { - // "dockerDashComposeVersion": "v2", - "installDockerBuildx": false + "[terraform-vars]": { + "editor.defaultFormatter": "hashicorp.terraform" } + }, + "extensions": [ + "sleistner.vscode-fileutils", + "yzhang.markdown-all-in-one", + "HashiCorp.terraform", + "hashicorp.hcl", + "mhutchie.git-graph" + ] + } + }, + "mounts": [ + // OPTIONAL: Mount your local docker socket into the devcontainer for using proivider 'docker' + // { + // "source": "/var/run/docker.sock", + // "target": "/var/run/docker.sock", + // "type": "bind" + // }, + // OPTIONAL: Mount your local workspace directory into the devcontainer + { + "source": "${localEnv:HOME}${localEnv:USERPROFILE}/.aws", + "target": "/home/vscode/.aws", + "type": "bind" }, - "customizations": { - "vscode": { - "settings": { - "telemetry.telemetryLevel": "off", - "files.eol": "\n", - "files.insertFinalNewline": true, - "files.autoSave": "off", - "editor.formatOnSave": true, - "git.autorefresh": true, - "git.autofetch": true, - "git.autofetchPeriod": 90, - "git.pullTags": false, - "git.confirmSync": false - }, - "extensions": [ - "sleistner.vscode-fileutils", - "esbenp.prettier-vscode", - "yzhang.markdown-all-in-one", - "HashiCorp.terraform" - ] - } + { + "source": "${localEnv:HOME}${localEnv:USERPROFILE}/.config/openstack", + "target": "/home/vscode/.config/openstack", + "type": "bind" }, - "mounts": [ - // OPTIONAL: Mount your local docker socket into the devcontainer for using proivider 'docker' - // { - // "source": "/var/run/docker.sock", - // "target": "/var/run/docker.sock", - // "type": "bind" - // }, - // OPTIONAL: Mount your local workspace directory into the devcontainer - // { - // "source": "${localEnv:HOME}${localEnv:USERPROFILE}/workspace", - // "target": "/home/vscode/workspace", - // "type": "bind" - // }, - { - "source": "devcontainer-history", - "target": "/home/vscode/.history_export", - "type": "volume" - } - ] + { + "source": "devcontainer-history", + "target": "/home/vscode/.history_export", + "type": "volume" + } + ] } diff --git a/.devcontainer/requirements.txt b/.devcontainer/requirements.txt index e69de29..7f7afbf 100644 --- a/.devcontainer/requirements.txt +++ b/.devcontainer/requirements.txt @@ -0,0 +1 @@ +jinja2 diff --git a/.devcontainer/scripts/post-create-command.sh b/.devcontainer/scripts/post-create-command.sh index cc3233b..aae5706 100755 --- a/.devcontainer/scripts/post-create-command.sh +++ b/.devcontainer/scripts/post-create-command.sh @@ -1,12 +1,11 @@ #!/usr/bin/env bash -# OPTIONAL: Setup oh-my-bash -# if .devcontainer/scripts/setup-docker-container.sh setup oh-my-bash; then -# .devcontainer/scripts/on-create-command.sh -# fi +# Add newline to PS1 +sed -r -i 's/}\\\$ "$/}\\n\\$ "/' ~/".${SHELL##*/}rc" # Install terraform autocomplete terraform -install-autocomplete +terragrunt --install-autocomplete # Install terraform-docs autocomplete if ! grep -q 'terraform-docs completion' ~/".${SHELL##*/}rc"; then @@ -20,10 +19,87 @@ if ! grep -q 'trivy completion' ~/".${SHELL##*/}rc"; then echo -e 'source <(trivy completion "${SHELL##*/}")' >>~/".${SHELL##*/}rc" fi -# Re-source profile -# shellcheck source=/dev/null -source ~/".${SHELL##*/}rc" if ! git status &>/dev/null; then git config --global --add safe.directory "${PWD}" fi pre-commit install + +# # Create silent ssh config file +# [[ -d ~/.ssh ]] || mkdir ~/.ssh +# chmod 700 ~/.ssh +# cat << _EOF > ~/.ssh/config +# StrictHostKeyChecking no +# UserKnownHostsFile /dev/null +# LogLevel ERROR +# _EOF + +# Add functions to source aws and openstack credentials +if [[ ! $(grep -qo source-aws-credentials ~/".${SHELL##*/}rc") == "source-aws-credentials" ]]; then + cat << _EOF >> ~/".${SHELL##*/}rc" + +function source-aws-credentials() { + export AWS_DEFAULT_REGION=\$(awk -F' = ' '/region/ {print \$NF}' ~/.aws/config) + export AWS_ENDPOINT_URL=\$(awk -F' = ' '/endpoint/ {print \$NF}' ~/.aws/config) + export AWS_ACCESS_KEY_ID=\$(awk -F' = ' '/aws_access_key_id/ {print \$NF}' ~/.aws/credentials) + export AWS_SECRET_ACCESS_KEY=\$(awk -F' = ' '/aws_secret_access_key/ {print \$NF}' ~/.aws/credentials) + grep -E '^AWS' < <(env | sort) +} +_EOF +fi +if [[ ! $(grep -qo source-openstack-credentials ~/".${SHELL##*/}rc") == "source-openstack-credentials" ]]; then + cat << _EOF >> ~/".${SHELL##*/}rc" + +function source-openstack-credentials() { + . ~/.config/openstack/groupone-mcs-openstack.sh \\ + && grep "OS_" < <(env | sort) +} +_EOF +fi +if ! grep -qo 'function sc' ~/".${SHELL##*/}rc"; then + cat << _EOF >> ~/".${SHELL##*/}rc" + +# Source AWS and OS credentials and print them safely +function sc() { + local o + o=\$(source-aws-credentials) + o+=\$'\n' + o+=\$(source-openstack-credentials) + while read -r v; do + export \$v + done <<<"\${o}" + sed -E \\ + -e 's/^(.*ACCESS_KEY.*)=(.*)$/\1=***/' \\ + -e 's/^(OS_PASSWORD=)(.*)$/\1***/' <<<"\${o}" | \\ + column -s '=' -t +} +_EOF +fi +if ! grep -qo 'function cc' ~/".${SHELL##*/}rc"; then + cat << _EOF >> ~/".${SHELL##*/}rc" + +# Check environment for AWS and OS credentials and print them safely +function cc() { + local o + o=\$(grep -E -e "^AWS_" -e "^OS_"< <(env | sort)) + sed -E \\ + -e 's/^(.*ACCESS_KEY.*)=(.*)$/\1=***/' \\ + -e 's/^(OS_PASSWORD=)(.*)$/\1***/' <<<"\${o}" | \\ + column -s '=' -t +} +_EOF +fi +if ! grep -qo 'eval sc' ~/".${SHELL##*/}rc"; then + cat << _EOF >> ~/".${SHELL##*/}rc" + +eval sc +_EOF +fi + +if command -v openstack &>/dev/null; then + if ! grep -qo 'openstack complete' ~/".${SHELL##*/}rc"; then + cat << _EOF >> ~/".${SHELL##*/}rc" + +source <(openstack complete) +_EOF + fi +fi diff --git a/.devcontainer/scripts/setup-docker-container.sh b/.devcontainer/scripts/setup-docker-container.sh index dbc43fc..655f627 100755 --- a/.devcontainer/scripts/setup-docker-container.sh +++ b/.devcontainer/scripts/setup-docker-container.sh @@ -1,27 +1,57 @@ #!/usr/bin/env bash + +# shellcheck disable=SC2312 # Consider invoking this command separately to avoid masking its return value +export DEBIAN_FRONTEND=noninteractive + ############################################## # Helper functions ############################################## -export DEBIAN_FRONTEND=noninteractive -function apt_cleanup() { +function cbanner() { + ############################################# + # DESCRIPTION: + # Print a banner as an eye catcher or separator + # + # EXAMPLE USAGE: + # cbanner Hello World + # + # OUTPUT: + ######################################## + # Hello World # + ######################################## + ############################################# + + local STRING="${*}" + local BANNER_SYMBOL="#" + local BANNER_WIDTH=40 + local SPACES_LEFT_COUNT=$(((BANNER_WIDTH - ${#STRING} - 2) / 2)) + local BANNER_LINE + BANNER_LINE=$(printf "%${BANNER_WIDTH}s" | tr ' ' "${BANNER_SYMBOL}") + + echo "${BANNER_LINE}" + echo "#$(printf "%${SPACES_LEFT_COUNT}s")${STRING}$(printf "%$((BANNER_WIDTH - ${#STRING} - 2 - SPACES_LEFT_COUNT))s")#" + echo "${BANNER_LINE}" +} +function helper_apt_cleanup() { + cbanner "Proceeding ${FUNCNAME[0]}" apt -y autoremove apt -y autoclean apt -y clean rm -rf /var/lib/apt/lists/* } -function apt_install() { +function helper_apt_install() { + cbanner "Proceeding ${FUNCNAME[0]} ${*}" apt update && apt -y --no-install-recommends install "${@}" && - apt_cleanup + helper_apt_cleanup } -function get_latest_git_release() { +function helper_get_latest_git_release() { local org="${1}" local repo="${2}" curl --fail -sS "https://api.github.com/repos/${org}/${repo}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' } -function get_machine_arch() { +function helper_get_machine_arch() { local machine_arch="" case $(uname -m) in i386) @@ -39,32 +69,96 @@ function get_machine_arch() { aarch64) dpkg --print-architecture | grep -q "arm64" && machine_arch="arm64" || machine_arch="arm" ;; + *) + machine_arch="UNKNOWN" + ;; esac - echo $machine_arch + echo "${machine_arch}" +} +function helper_fix_gcc() { + if dpkg -l gcc &>/dev/null; then + apt -y purge gcc + apt -y autoremove + fi + apt update + apt -y install gcc + helper_apt_cleanup } ############################################## # Install functions ############################################## -function install_all() { - install_os_requirements +function install_all_ansible() { + cbanner "Proceeding ${FUNCNAME[0]} ${*}" + install_os_requirements_ansible + install_pip + install_pip_requirements + install_pre_commit + install_ansible "${1}" + shift + install_ansible_lint "${1}" + shift + install_openstacksdk + helper_apt_cleanup +} +function install_all_terraform() { + cbanner "Proceeding ${FUNCNAME[0]} ${*}" + install_os_requirements_terraform install_pip install_pip_requirements install_pre_commit install_terraform "${1}" - install_tf_docs "${2}" - install_tf_lint "${3}" - install_trivy "${4}" - install_terragrunt "${5}" - apt_cleanup + shift + install_terraformer "${1}" + shift + install_tf_docs "${1}" + shift + install_tf_lint "${1}" + shift + install_trivy "${1}" + shift + install_terragrunt "${1}" + shift + install_awscli "${1}" + shift + install_openstackclient "${1}" + shift + helper_apt_cleanup } -function install_os_requirements() { +function install_os_requirements_ansible() { + cbanner "Proceeding ${FUNCNAME[0]}" apt -y purge imagemagick imagemagick-6-common - apt_install \ + apt -y dist-upgrade + helper_apt_install \ apt-transport-https \ apt-utils \ + bash-completion \ curl \ dialog \ git \ + gcc \ + gpg \ + gnupg \ + lsb-release \ + openssh-client \ + python3-pip \ + python3-apt \ + python3-venv \ + sshpass \ + sudo \ + unzip +} +function install_os_requirements_terraform() { + cbanner "Proceeding ${FUNCNAME[0]}" + apt -y purge imagemagick imagemagick-6-common + apt -y dist-upgrade + helper_apt_install \ + apt-transport-https \ + apt-utils \ + bash-completion \ + curl \ + dialog \ + gettext \ + git \ gpg \ gnupg \ lsb-release \ @@ -73,23 +167,92 @@ function install_os_requirements() { openssh-client \ sudo \ unzip - apt -y dist-upgrade +} +function install_ansible() { + cbanner "Proceeding ${FUNCNAME[0]} ${*}" + if [[ "${1}" == "latest" ]]; then + python3 -m pip install --upgrade \ + ansible + else + python3 -m pip install --upgrade \ + "ansible${1}" + fi +} +function install_ansible_lint() { + cbanner "Proceeding ${FUNCNAME[0]} ${*}" + if [[ "${1}" == "latest" ]]; then + python3 -m pip install --upgrade \ + ansible-lint + else + python3 -m pip install --upgrade \ + "ansible-lint${1}" + fi +} +function install_awscli() { + cbanner "Proceeding ${FUNCNAME[0]} ${*}" + local machine_arch + local install_path=/usr/local/aws-cli + local binary_path=/usr/local/bin + case $(uname -m) in + aarch64) + machine_arch="aarch64" + ;; + *) + machine_arch="x86_64" + ;; + esac + curl "https://awscli.amazonaws.com/awscli-exe-linux-${machine_arch}.zip" -o "/tmp/awscliv2.zip" + cd /tmp || exit 1 + unzip /tmp/awscliv2.zip + /tmp/aws/install --install-dir "${install_path}" --bin-dir "${binary_path}" + if [[ -f /usr/local/bin/aws ]]; then + rm -rf /tmp/awscliv2.zip /tmp/aws + return 0 + else + exit 1 + fi +} +function install_openstacksdk() { + cbanner "Proceeding ${FUNCNAME[0]}" + helper_fix_gcc + if [[ "${1}" == "latest" ]]; then + python3 -m pip install --upgrade \ + openstacksdk + else + python3 -m pip install --upgrade \ + "openstacksdk${1}" + fi +} +function install_openstackclient() { + cbanner "Proceeding ${FUNCNAME[0]}" + helper_fix_gcc + if [[ "${1}" == "latest" ]]; then + python3 -m pip install --upgrade \ + python-openstackclient + else + python3 -m pip install --upgrade \ + "python-openstackclient${1}" + fi } function install_pip() { + cbanner "Proceeding ${FUNCNAME[0]}" python3 -m pip install --upgrade \ pip } function install_pip_requirements() { - if [[ $(grep -Evc '^[[:space:]]*#' .devcontainer/requirements.txt) -gt 0 ]]; then + cbanner "Proceeding ${FUNCNAME[0]}" + if [[ $(grep -Evc '^[[:space:]]*#' requirements.txt) -gt 0 ]]; then python3 -m pip install --upgrade \ - -r .devcontainer/requirements.txt + -r requirements.txt fi } function install_pre_commit() { + cbanner "Proceeding ${FUNCNAME[0]}" python3 -m pip install --upgrade \ pre-commit } function install_terraform() { + cbanner "Proceeding ${FUNCNAME[0]} ${*}" local tf_version tf_version="${1:-latest}" if [[ ${tf_version} == "latest" ]]; then @@ -101,39 +264,60 @@ function install_terraform() { gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/hashicorp.list - apt_install "${tf_version}" + helper_apt_install "${tf_version}" +} +function install_terraformer() { + cbanner "Proceeding ${FUNCNAME[0]} ${*}" + local machine_arch machine_os version + local org=GoogleCloudPlatform + local repo=terraformer + local binary_path=/usr/bin + local binary_name=terraformer + machine_arch=$(helper_get_machine_arch) + machine_os=$(uname) + machine_os=${machine_os,,} + version="${1:-latest}" + + if [[ ${version} == "latest" ]]; then + version=$(helper_get_latest_git_release "${org}" "${repo}") + fi + curl -sSLo "${binary_path}/${binary_name}" \ + --url "https://github.com/${org}/${repo}/releases/download/${version}/terraformer-all-${machine_os,,}-${machine_arch,,}" + chmod +x "${binary_path}/${binary_name}" } function install_terragrunt() { + cbanner "Proceeding ${FUNCNAME[0]} ${*}" local machine_arch machine_os version local org=gruntwork-io local repo=terragrunt local binary_path=/usr/bin local binary_name=terragrunt - machine_arch=$(get_machine_arch) + machine_arch=$(helper_get_machine_arch) machine_os=$(uname) machine_os=${machine_os,,} version="${1:-latest}" if [[ ${version} == "latest" ]]; then - version=$(get_latest_git_release "${org}" "${repo}") + version=$(helper_get_latest_git_release "${org}" "${repo}") fi curl -sSLo "${binary_path}/${binary_name}" \ --url "https://github.com/${org}/${repo}/releases/download/${version}/terragrunt_${machine_os}_${machine_arch}" chmod +x "${binary_path}/${binary_name}" } function install_tf_docs() { + cbanner "Proceeding ${FUNCNAME[0]} ${*}" local machine_arch machine_os version local org=terraform-docs local repo=terraform-docs local binary_path=/usr/bin local binary_name=terraform-docs - - machine_arch=$(get_machine_arch) + machine_arch=$(helper_get_machine_arch) machine_os=$(uname) machine_os=${machine_os,,} version="${1:-latest}" + if [[ ${version} == "latest" ]]; then - version=$(get_latest_git_release "${org}" "${repo}") + version=$(helper_get_latest_git_release "${org}" "${repo}") fi curl -sSLo /tmp/terraform-docs.tar.gz \ --url "https://terraform-docs.io/dl/${version}/terraform-docs-${version}-${machine_os}-${machine_arch}.tar.gz" @@ -143,11 +327,13 @@ function install_tf_docs() { rm -f /tmp/{README.md,LICENSE,*{.tar,.tgz,.gz}} } function install_tf_lint() { + cbanner "Proceeding ${FUNCNAME[0]} ${*}" local TFLINT_VERSION export TFLINT_VERSION="${1:-latest}" curl -sSL https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash } function install_trivy() { + cbanner "Proceeding ${FUNCNAME[0]} ${*}" local version version="${1:-latest}" if [[ ${version} == "latest" ]]; then @@ -159,21 +345,40 @@ function install_trivy() { gpg --dearmor -o /usr/share/keyrings/trivy.gpg echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/trivy.list - apt_install "${version}" + helper_apt_install "${version}" +} +function install_minio_client() { + cbanner "Proceeding ${FUNCNAME[0]}" + local machine_arch machine_os + local binary_path=/usr/bin/minio-binaries + local binary_name=mc + + machine_arch=$(helper_get_machine_arch) + machine_os=$(uname) + machine_os=${machine_os,,} + curl -sSL \ + --url "https://dl.min.io/client/mc/release/linux-${machine_arch}/mc" \ + --output "${binary_path}/${binary_name}" \ + --create-dirs + + chmod +x "${binary_path}/${binary_name}" + export PATH="${PATH}:${binary_path}" } ############################################## # Setup functions ############################################## function setup_python_argcomplete() { - if [ -f /usr/bin/activate-global-python-argcomplete3 ]; then + cbanner "Proceeding ${FUNCNAME[0]}" + if [[ -f /usr/bin/activate-global-python-argcomplete3 ]]; then /usr/bin/activate-global-python-argcomplete3 - elif [ -f /usr/bin/activate-global-python-argcomplete ]; then + elif [[ -f /usr/bin/activate-global-python-argcomplete ]]; then /usr/bin/activate-global-python-argcomplete else return 0 fi } function setup_user() { + cbanner "Proceeding ${FUNCNAME[0]} ${*}" local usr # local pswd usr="${1}" @@ -194,6 +399,7 @@ function setup_user() { "/home/${usr}/.bashrc" } function setup_omb() { + cbanner "Proceeding ${FUNCNAME[0]} ${*}" local theme local user_home theme="${1:-powerline-multiline}" @@ -213,6 +419,7 @@ function setup_omb() { fi } function setup_ssh_key() { + cbanner "Proceeding ${FUNCNAME[0]} ${*}" local usr usr="${1}" su - "${usr}" -c 'ssh-keygen -q -t rsa -b 4096 -f ~/.ssh/id_rsa -N "" -C "ansible_devcontainer" <</dev/null' @@ -246,23 +453,37 @@ function help_install() { install - Install applications SUB-COMMANDS: - all \\ - [TF_VERSION] \\ - [TFDOCS_VERSION] \\ - [TFLINT_VERSION] \\ - [TFTRIVY_VERSION] \\ - [TERRAGRUNT_VERSION] - Install all applications + ansible [VERSION] - Install ansible via pip + ansible-lint [VERSION] - Install ansible-lint via pip + awscli [VERSION] - Install awscli via pip help - Show [COMMAND] help + mc - Install MinIO client 'mc' pip - Install pip pip-requirements - Install pip packages from requirements.txt pre-commit - Install PreCommit via pip - os-requirements - Install OS requirements + openstacksdk - Install OpenStackSDK via pip + openstackclient - Install OpenStack-CLI via pip + os-requirements-ansible - Install OS requirements + os-requirements-terraform - Install OS requirements terraform [VERSION] - Install terraform VERSION (default: latest) + terraformer [VERSION] - Install terraformer VERSION (default: latest) terraform-docs [VERSION] - Install terraform-docs VERSION (default: latest) terragrunt [VERSION] - Install terragrunt VERSION (default: latest) tflint [VERSION] - Install terraform-lint VERSION (default: latest) trivy [VERSION] - Install trivy VERSION (default: latest) + all + SUB-COMMANDS: + ansible \\ + [ANSIBLE_VERSION] \\ + [ANSIBLE_LINT_VERSION] - Install all ansible applications + terraform \\ + [TERRAFORM_VERSION] \\ + [TERRAFORMER_VERSION] \\ + [TFDOCS_VERSION] \\ + [TFLINT_VERSION] \\ + [TFTRIVY_VERSION] \\ + [TERRAGRUNT_VERSION] - Install all terraform applications _ENDOFHELP @@ -284,7 +505,6 @@ function help_setup() { user USERNAME - Add linux user USERNAME - _ENDOFHELP } ############################################## @@ -297,7 +517,36 @@ function main() { case $1 in all) shift - install_all "${1:-latest}" "${2:-latest}" "${3:-latest}" "${4:-latest}" "${5:-latest}" + case $1 in + ansible) + shift + install_all_ansible "${1:-latest}" "${2:-latest}" + ;; + terraform) + shift + install_all_terraform "${1:-latest}" "${2:-latest}" "${3:-latest}" "${4:-latest}" "${5:-latest}" + ;; + *) + echo "Missing or wrong SUB-COMMAND - Exit" + help_install + exit 1 + ;; + esac + ;; + ansible) + shift + install_ansible "${1:-latest}" + ;; + ansible-lint) + shift + install_ansible_lint "${1:-latest}" + ;; + awscli) + shift + install_awscli "${1:-latest}" + ;; + mc) + install_minio_client ;; pip) install_pip @@ -308,28 +557,43 @@ function main() { pre-commit) install_pre_commit ;; - os-requirements) - install_os_requirements + openstacksdk) + shift + install_openstacksdk "${1:-latest}" + ;; + openstackclient) + shift + install_openstackclient "${1:-latest}" + ;; + os-requirements-ansible) + install_os_requirements_ansible + ;; + os-requirements-terraform) + install_os_requirements_terraform ;; terraform) shift - install_terraform "${1}" + install_terraform "${1:-latest}" + ;; + terraformer) + shift + install_terraformer "${1:-latest}" ;; terraform-docs) shift - install_tf_docs "${1}" + install_tf_docs "${1:-latest}" ;; terragrunt) shift - install_terragrunt "${1}" + install_terragrunt "${1:-latest}" ;; tflint) shift - install_tf_lint "${1}" + install_tf_lint "${1:-latest}" ;; trivy) shift - install_trivy "${1}" + install_trivy "${1:-latest}" ;; *) echo "Missing or wrong SUB-COMMAND - Exit"