Skip to content

Commit

Permalink
Version 4 initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuru committed Dec 29, 2024
1 parent a00723b commit 0da2146
Show file tree
Hide file tree
Showing 33 changed files with 1,489 additions and 648 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ build: $(DOCKER_BASE_OS).build
install: $(DOCKER_BASE_OS).install

run:
@geodesic
@$(APP_NAME)

%.run: %.build %.install
@geodesic
@$(APP_NAME)

run/check:
@if [[ -n "$$(docker ps --format '{{ .Names }}' --filter name="^/$(APP_NAME)\$$")" ]]; then \
Expand Down
522 changes: 522 additions & 0 deletions docs/ReleaseNotes-v4.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion os/alpine/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ RUN helm3 plugin install https://github.com/databus23/helm-diff.git --version v$
# Configure host AWS configuration to be available from inside Docker image
#
# AWS_DATA_PATH is a PATH-like variable for configuring the AWS botocore library to
# load additional modules. Do not set it. ENV AWS_DATA_PATH=/localhost/.aws
# load additional modules. Do not set it.
ARG GEODESIC_AWS_HOME=/localhost/.aws
ENV AWS_CONFIG_FILE=${GEODESIC_AWS_HOME}/config
ENV AWS_SHARED_CREDENTIALS_FILE=${GEODESIC_AWS_HOME}/credentials
Expand Down
22 changes: 12 additions & 10 deletions os/debian/Dockerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ RUN for dir in $XDG_DATA_HOME $XDG_CONFIG_HOME $XDG_CACHE_HOME; do \
ENV BANNER "geodesic"

ENV MOTD_URL=http://geodesic.sh/motd
ENV HOME=/conf

# Install all packages as root
USER root
# We used to override user home directory to /conf, but we no longer do that.
ENV HOME=/root

# Keep dpkg quiet about running non-interactively
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
Expand Down Expand Up @@ -134,8 +135,9 @@ RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.
# Install packages (but only explicitly listed ones)
RUN apt-get update && apt-get install -y --no-install-recommends \
$(grep -h -v '^#' /etc/apt/packages.txt /etc/apt/packages-debian.txt | sed -E 's/@(cloudposse|community|testing)//g' ) && \
mkdir -p /etc/bash_completion.d/ /etc/profile.d/ /conf && \
touch /conf/.gitconfig
mkdir -p /etc/bash_completion.d/ /etc/profile.d/ # \
# /conf && \
# touch /conf/.gitconfig

# Install `tofu` as an alternative to `terraform`, if it is available.
# Set priority to 5, which is lower than any other Cloud Posse Terraform package,
Expand Down Expand Up @@ -163,17 +165,15 @@ WORKDIR /tmp
COPY --from=python /usr/local/ /usr/local/

# Explicitly set KUBECONFIG to enable kube_ps1 prompt
ENV KUBECONFIG=/conf/.kube/config
ENV KUBECONFIG="${HOME}/.kube/config"
# Install an empty kubeconfig to suppress some warnings
COPY rootfs/conf/.kube/config /conf/.kube/config
COPY rootfs/etc/kubeconfig "${KUBECONFIG}"
# Set mode on kubeconfig to suppress some warnings while installing tools
RUN chmod 600 $KUBECONFIG

#
# Install kubectl
#
# Set KUBERNETES_VERSION and KOPS_BASE_IMAGE in /conf/kops/kops.envrc
#
RUN kubectl completion bash > /etc/bash_completion.d/kubectl.sh

# https://github.com/ahmetb/kubectx/releases
Expand Down Expand Up @@ -230,8 +230,8 @@ RUN helm3 plugin install https://github.com/databus23/helm-diff.git --version v$
# Configure host AWS configuration to be available from inside Docker image
#
# AWS_DATA_PATH is a PATH-like variable for configuring the AWS botocore library to
# load additional modules. Do not set it. ENV AWS_DATA_PATH=/localhost/.aws
ARG GEODESIC_AWS_HOME=/localhost/.aws
# load additional modules. Do not set it.
ARG GEODESIC_AWS_HOME=${HOME}/.aws
ENV AWS_CONFIG_FILE=${GEODESIC_AWS_HOME}/config
ENV AWS_SHARED_CREDENTIALS_FILE=${GEODESIC_AWS_HOME}/credentials
# Region abbreviation types are "fixed" (always 3 chars), "short" (4-5 chars), or "long" (the full AWS string)
Expand Down Expand Up @@ -330,11 +330,13 @@ RUN apt-get update && apt-get install -y --no-install-recommends pandoc && \
RUN for dir in $XDG_DATA_HOME $XDG_CONFIG_HOME $XDG_CACHE_HOME; do \
chmod -R a+rwX $dir; done

WORKDIR /conf
RUN mkdir /workspace
WORKDIR /workspace

ENTRYPOINT ["/bin/bash"]
CMD ["-c", "boot"]

ARG DEV_VERSION
ENV GEODESIC_DEV_VERSION=$DEV_VERSION
ENV GEODESIC_VERSION="${GEODESIC_VERSION}${GEODESIC_DEV_VERSION:+ (${GEODESIC_DEV_VERSION})}"

1 change: 0 additions & 1 deletion os/debian/packages-debian.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ ldnsutils
# locales
net-tools
netcat-openbsd
oathtool
procps
wget

Expand Down
1 change: 0 additions & 1 deletion rootfs/conf/.emacs

This file was deleted.

1 change: 0 additions & 1 deletion rootfs/conf/.inputrc

This file was deleted.

2 changes: 1 addition & 1 deletion rootfs/conf/.kube/config → rootfs/etc/kubeconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This is a placeholder Kuberentes configuration file ("kubeconfig") to suppress some warnings.
# We recommend placing real kubeconfig files under /dev/shm to reduce the chance of accidental exposure.
# We recommend placing real kubeconfig files under /dev/shm to reduce the chance of accidental exposure.
11 changes: 0 additions & 11 deletions rootfs/etc/motd

This file was deleted.

18 changes: 18 additions & 0 deletions rootfs/etc/motd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This is the local message of the day (motd) that is displayed when you log into the container.
# It is sourced from /etc/profile.d/motd.sh as a bash script so that it can interpolate variables.

cat << EOF
IMPORTANT:
# Unless there were errors reported above,
# * Configuration from your host \$HOME directory should be available
# * under both \`${LOCAL_HOME}\` and \`${HOME}\`.
# * Your AWS configuration should be available at \`${AWS_CONFIG_FILE}\`.
# * Your host AWS credentials should be available.
# * Use Leapp on your host computer to manage your credentials.
# * Leapp is free, open source, and available from https://leapp.cloud
# * Use the AWS_PROFILE environment variable to manage your AWS IAM role, or
# * you can interactively select AWS profiles via the \`assume-role\` command,
# * which will launch a subshell with your selected profile set.
EOF
21 changes: 21 additions & 0 deletions rootfs/etc/profile.d/_01-launch-warning.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Files in the profile.d directory are executed by the lexicographical order of their file names.
# This file is named _01-launch-warning.sh. The leading underscore is needed to ensure this file executes before
# other files with alphabetical names. The number portion is to ensure proper ordering among
# the high-priority scripts.
#
# This file has no dependencies and does not strictly need to come first,
# but it is nice to have the warnings come before other output.

# In case this output is being piped into a shell, print a warning message

# Specifically, this guards against:
# docker run -it cloudposse/geodesic:latest-debian | bash

printf 'printf "\\nIf piping Geodesic output into a shell, do not attach a terminal (-t flag)\\n\\r" >&2; exit 8;'
# In case this output is not being piped into a shell, hide the warning message.
# Use backspaces, because carriage returns may be ignored or translated into newlines.
printf '\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b'
printf '\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b'
printf ' '
printf '\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b'
printf '\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b'
27 changes: 22 additions & 5 deletions rootfs/etc/profile.d/_07-term-mode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,43 @@
# and always returns true. With -l it outputs integer luminance values for foreground
# and background colors. With -ll it outputs labels on the luminance values as well.
function _is_term_dark_mode() {
local x fg_rgb bg_rgb fg_lum bg_lum
local x fg_rgb bg_rgb fg_lum bg_lum exit_code

# Do not try to auto-detect if we are not in a terminal
# or if termcap does not think we are in a color terminal
if tty -s && [[ -n "$(tput setaf 1 2>/dev/null)" ]]; then
# Extract the RGB values of the foreground and background colors via OSC 10 and 11.
# Redirect output to `/dev/tty` in case we are in a subshell where output is a pipe,
# because this output has to go directly to the terminal.
local saved_state=$(stty -g)
[[ $GEODESIC_TRACE =~ "terminal" ]] && echo "$(tput setaf 1)* TERMINAL TRACE: Checking terminal color scheme...$(tput sgr0)" >&2
stty -echo
echo -ne '\e]10;?\a\e]11;?\a' >/dev/tty
IFS=: read -t 0.1 -d $'\a' x fg_rgb
IFS=: read -t 0.1 -d $'\a' x bg_rgb
stty echo
# Timeout of 2 was not enough when waking for sleep.
# The second read should be part of the first response, should not need much time at all regardless.
IFS=: read -s -t 1 -d $'\a' x fg_rgb
if [[ $exit_code -gt 128 ]] || [[ -z $fg_rgb ]] && [[ ${GEODESIC_TERM_COLOR_SIGNAL} == "true" ]]; then
IFS=: read -s -t 30 -d $'\a' x fg_rgb
exit_code=$?
[[ $exit_code -gt 128 ]] || [[ -z $fg_rgb ]] && export GEODESIC_TERM_COLOR_AUTO=disabled
fi
[[ $exit_code -gt 128 ]] || exit_code=0
IFS=: read -s -t 0.5 -d $'\a' x bg_rgb
((exit_code += $?))
stty "$saved_state"
else
if [[ $GEODESIC_TRACE =~ "terminal" ]]; then
echo "* TERMINAL TRACE: ${FUNCNAME[0]} called, but not running in a color terminal." >&2
fi
fi

if [[ -z $fg_rgb ]] || [[ -z $bg_rgb ]]; then
if [[ ${GEODESIC_TERM_COLOR_SIGNAL} == "true" ]] && [[ ${GEODESIC_TERM_COLOR_AUTO} == "disabled" ]]; then
printf "\n\n\tTerminal light/dark mode detection failed from signal handler. Disabling automatic detection.\n" >&2
printf "\tYou can manually change modes with\n\n\tupdate-terminal-color-mode [dark|light]\n\n" >&2
printf "\tYou can re-enable automatic detection with\n\n\tunset GEODESIC_TERM_COLOR_AUTO\n\n" >&2
fi

if [[ $exit_code -gt 128 ]] || [[ -z $fg_rgb ]] || [[ -z $bg_rgb ]]; then
if [[ $GEODESIC_TRACE =~ "terminal" ]] && tty -s; then
echo "$(tput setaf 1)* TERMINAL TRACE: Terminal did not respond to OSC 10 and 11 queries.$(tput sgr0)" >&2
fi
Expand Down
67 changes: 60 additions & 7 deletions rootfs/etc/profile.d/_10-colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,32 @@
# The main change is that it uses the terminal's default colors for foreground and background,
# whereas the previous version "reset" the color by setting it to black, which fails in dark mode.

function update-terminal-mode() {
function update-terminal-color-mode() {
local new_mode="$1"
local quiet=false
case $new_mode in
dark | light) ;;

quiet)
quiet=true
# fall through
# shellcheck disable=SC2034
;&
"")
new_mode=$(_is_term_dark_mode -mm)
;;

*)
echo "Usage: update-terminal-mode [dark|light]" >&2
echo "Usage: update-terminal-color-mode [dark|light]" >&2
return 1
;;
esac

if [[ $new_mode == "unknown" ]]; then
if ! tty -s; then
echo "No terminal detected." >&2
[[ "$quiet" == "true" ]] || echo "No terminal detected." >&2
elif [[ -z "$(tput op 2>/dev/null)" ]]; then
echo "Terminal does not appear to support color." >&2
[[ "$quiet" == "true" ]] || echo "Terminal does not appear to support color." >&2
fi
new_mode="light"
fi
Expand All @@ -40,10 +46,18 @@ function update-terminal-mode() {
[[ "${_geodesic_tput_cache[TERM]}" != "$TERM" ]]; then
_geodesic_tput_cache_init "$1"
else
echo "Not updating terminal mode from $new_mode to $new_mode"
[[ "$quiet" == "true" ]] || echo "Not updating terminal mode from $new_mode to $new_mode" >&2
fi
}

function get-terminal-color-mode() {
echo "${_geodesic_tput_cache[dark_mode]:-light}"
}

function _is_color_term() {
[[ -t 1 ]] && tty -s && [[ -n "$(tput op 2 2>/dev/null)" ]]
}

# We call `tput` several times for every prompt, and it can add up, so we cache the results.
function _geodesic_tput_cache_init() {
declare -g -A _geodesic_tput_cache
Expand Down Expand Up @@ -76,7 +90,7 @@ function _geodesic_tput_cache_init() {
# from here, so we need to tell the user to run the command to fix them.
if [[ $BASH_SUBSHELL != 0 ]]; then
printf "\n* Terminal mode settings have been lost (%s,%s).\n" "$SHLVL" "$BASH_SUBSHELL" >&2
printf "* Please run: update-terminal-mode \n\n" >&2
printf "* Please run: update-terminal-color-mode \n\n" >&2
fi

local bold=$(tput bold)
Expand Down Expand Up @@ -108,6 +122,11 @@ function _geodesic_tput_cache_init() {
case $new_mode in
dark | light) ;;

quiet)
quiet=true
# fall through
# shellcheck disable=SC2034
;&
"")
new_mode=$(_is_term_dark_mode -m)
;;
Expand Down Expand Up @@ -175,7 +194,7 @@ function _geodesic_color() {
#
# In bash, the expression `var[subscript]` has, unfortunately, two very different meanings,
# depending on whether `var` has been declared as an associative array or not. If `var` has
# NOT been declared an associative arry, then `subscript` is treated as an arithmetic expression.
# NOT been declared an associative array, then `subscript` is treated as an arithmetic expression.
# Within an expression, shell variables may be referenced by name without using the parameter
# expansion syntax, meaning `subscript` evaluates to `$subscript`, and the value of the variable
# `$subscript` is treated as an arithmetic expression (subject to recursive expansion), which is expected
Expand Down Expand Up @@ -278,3 +297,37 @@ function reset_terminal_colors() {
}

_geodesic_tput_cache_init

# Although SIGWINCH is a standard signal to indicate the window *size* has changed,
# some terminals (not sure which ones) also send a SIGWINCH signal when the window colors change.
# For the other terminals, catching SIGWINCH gives users an easy way of triggering a color update: resize the window.
# So we catch the signal to update the terminal colors, preserving any existing signal handlers.

function _update-terminal-color-mode-sigwinch() {
[[ ${GEODESIC_TERM_COLOR_SIGNAL} == "true" ]] || [[ ${GEODESIC_TERM_COLOR_AUTO:-true} != "true" ]] && return 0

# Ignore repeated signals while a signal is being processed
export GEODESIC_TERM_COLOR_SIGNAL=true
update-terminal-color-mode quiet
unset GEODESIC_TERM_COLOR_SIGNAL
}

if _is_color_term; then
# We install the trap handler whether GEODESIC_TERM_COLOR_AUTO is set or not,
# because we will not be able to detect the change in that variable if
# it started out disabled and then someone enables it.

# Save existing trap (if any)
existing_trap=$(trap -p WINCH)

# Set up new trap that runs both the existing trap and the update-terminal-color-mode function
if [ -n "$existing_trap" ]; then
# Extract the existing command from the trap output
existing_cmd=$(echo "$existing_trap" | sed "s/trap -- '\(.*\)' SIGWINCH/\1/")
trap "${existing_cmd}; _update-terminal-color-mode-sigwinch" WINCH
else
trap _update-terminal-color-mode-sigwinch WINCH
fi

unset existing_trap existing_cmd
fi
31 changes: 0 additions & 31 deletions rootfs/etc/profile.d/_20-localhost.sh

This file was deleted.

Loading

0 comments on commit 0da2146

Please sign in to comment.