Skip to content

Commit

Permalink
Dockerfile examples, Renovate config, color text bugfixes (#939)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuru authored May 8, 2024
1 parent 45cf6f9 commit ee845d8
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 87 deletions.
8 changes: 6 additions & 2 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
"github-actions": {
"enabled": false
},
"docker": {
"ignorePaths": ["rootfs/**"]
"dockerfile": {
"ignorePaths": [
"rootfs/**",
"Dockerfile.custom",
"Dockerfile.options"
]
}
}
2 changes: 1 addition & 1 deletion .github/workflows/vhs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: "make all"
run: make all

- uses: charmbracelet/vhs-action@v1
- uses: charmbracelet/vhs-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
path: demo.tape
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile.custom
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

# We always recommend pinning versions where changes are likely to break things.
# We put the versions up top here so they are easy to find and update.
ARG VERSION=1.2.1
# Find the latest version at https://github.com/cloudposse/geodesic/releases
ARG VERSION=2.11.0
# Changing base OS for Geodesic is possible by changing this arg, but
# unfortunately, the package managers are different, so it is not that simple.
ARG OS=debian
Expand Down
74 changes: 21 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


<!-- markdownlint-disable -->
<a href="https://cpco.io/homepage"><img src=".github/banner.png?raw=true" alt="Project Banner"/></a><br/>
<p align="right">
Expand Down Expand Up @@ -41,16 +43,6 @@ Geodesic is a robust Linux toolbox container, crafted to optimize DevOps workflo
<img src="docs/demo.gif" alt="Demo" />*<br/>Example of running a shell based on the `cloudposse/geodesic` base docker image.*


---
> [!NOTE]
> This project is part of Cloud Posse's comprehensive ["SweetOps"](https://cpco.io/homepage?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/geodesic&utm_content=) approach towards DevOps.
> <details><summary><strong>Learn More</strong></summary>
>
> It's 100% Open Source and licensed under the [APACHE2](LICENSE).
>
> </details>
<a href="https://cloudposse.com/readme/header/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/geodesic&utm_content=readme_header_link"><img src="https://cloudposse.com/readme/header/img"/></a>


## Introduction
Expand Down Expand Up @@ -96,9 +88,8 @@ Want to learn more? [Check out our getting started with Geodesic guide!](https:/



## Usage


## Usage

### Quickstart

Expand All @@ -117,7 +108,14 @@ geodesic

In general we recommend creating a customized version of Geodesic by creating your own `Dockerfile` starting with
```
ARG VERSION=2.0.0
# We always recommend pinning versions to avoid surprises and breaking changes.
# We put the version up top here so it is easy to find and update.
# Find the latest version at https://github.com/cloudposse/geodesic/releases
ARG VERSION=2.11.0
# If you don't want to bothered with updating the version, you can use `latest` instead,
# but keep in mind that as long as you have a local image with the `latest` tag,
# it will not be updated by `docker run`. You will have to explicitly pull the latest image.
# ARG VERSION=latest
ARG OS=debian
FROM cloudposse/geodesic:$VERSION-$OS
Expand Down Expand Up @@ -215,23 +213,21 @@ Check out these related projects.
- [Build Harness](https://github.com/cloudposse/dev) - Collection of Makefiles to facilitate building Golang projects, Dockerfiles, Helm charts, and more
- [terraform-aws-components](https://github.com/cloudposse/terraform-aws-components) - Catalog of reusable Terraform components and blueprints for provisioning reference architectures



## ✨ Contributing

This project is under active development, and we encourage contributions from our community.



Many thanks to our outstanding contributors:

<a href="https://github.com/cloudposse/geodesic/graphs/contributors">
<img src="https://contrib.rocks/image?repo=cloudposse/geodesic&max=24" />
</a>

### 🐛 Bug Reports & Feature Requests

Please use the [issue tracker](https://github.com/cloudposse/geodesic/issues) to report any bugs or file feature requests.

### 💻 Developing

If you are interested in being a contributor and want to get involved in developing this project or help out with Cloud Posse's other projects, we would love to hear from you!
Hit us up in [Slack](https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/geodesic&utm_content=slack), in the `#cloudposse` channel.
For 🐛 bug reports & feature requests, please use the [issue tracker](https://github.com/cloudposse/geodesic/issues).

In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.
1. Review our [Code of Conduct](https://github.com/cloudposse/geodesic/?tab=coc-ov-file#code-of-conduct) and [Contributor Guidelines](https://github.com/cloudposse/.github/blob/main/CONTRIBUTING.md).
Expand All @@ -256,38 +252,6 @@ Dropped straight into your Inbox every week — and usually a 5-minute read.

[Join us every Wednesday via Zoom](https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/geodesic&utm_content=office_hours) for your weekly dose of insider DevOps trends, AWS news and Terraform insights, all sourced from our SweetOps community, plus a _live Q&A_ that you can’t find anywhere else.
It's **FREE** for everyone!

## About

This project is maintained by <a href="https://cpco.io/homepage?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/geodesic&utm_content=">Cloud Posse, LLC</a>.
<a href="https://cpco.io/homepage?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/geodesic&utm_content="><img src="https://cloudposse.com/logo-300x69.svg" align="right" /></a>

We are a [**DevOps Accelerator**](https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/geodesic&utm_content=commercial_support) for funded startups and enterprises.
Use our ready-to-go terraform architecture blueprints for AWS to get up and running quickly.
We build it with you. You own everything. Your team wins. Plus, we stick around until you succeed.

<a href="https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/geodesic&utm_content=commercial_support"><img alt="Learn More" src="https://img.shields.io/badge/learn%20more-success.svg?style=for-the-badge"/></a>

*Your team can operate like a pro today.*

Ensure that your team succeeds by using our proven process and turnkey blueprints. Plus, we stick around until you succeed.

<details>
<summary>📚 <strong>See What's Included</strong></summary>

- **Reference Architecture.** You'll get everything you need from the ground up built using 100% infrastructure as code.
- **Deployment Strategy.** You'll have a battle-tested deployment strategy using GitHub Actions that's automated and repeatable.
- **Site Reliability Engineering.** You'll have total visibility into your apps and microservices.
- **Security Baseline.** You'll have built-in governance with accountability and audit logs for all changes.
- **GitOps.** You'll be able to operate your infrastructure via Pull Requests.
- **Training.** You'll receive hands-on training so your team can operate what we build.
- **Questions.** You'll have a direct line of communication between our teams via a Shared Slack channel.
- **Troubleshooting.** You'll get help to triage when things aren't working.
- **Code Reviews.** You'll receive constructive feedback on Pull Requests.
- **Bug Fixes.** We'll rapidly work with you to fix any bugs in our projects.
</details>

<a href="https://cloudposse.com/readme/commercial-support/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/geodesic&utm_content=readme_commercial_support_link"><img src="https://cloudposse.com/readme/commercial-support/img"/></a>
## License

<a href="https://opensource.org/licenses/Apache-2.0"><img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=for-the-badge" alt="License"></a>
Expand All @@ -296,7 +260,9 @@ Ensure that your team succeeds by using our proven process and turnkey blueprint
<summary>Preamble to the Apache License, Version 2.0</summary>
<br/>
<br/>

Complete license is available in the [`LICENSE`](LICENSE) file.

```text
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand All @@ -320,6 +286,8 @@ under the License.
## Trademarks

All other trademarks referenced herein are the property of their respective owners.


---
Copyright © 2017-2024 [Cloud Posse, LLC](https://cpco.io/copyright)

Expand Down
9 changes: 8 additions & 1 deletion README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ usage: |-
In general we recommend creating a customized version of Geodesic by creating your own `Dockerfile` starting with
```
ARG VERSION=2.0.0
# We always recommend pinning versions to avoid surprises and breaking changes.
# We put the version up top here so it is easy to find and update.
# Find the latest version at https://github.com/cloudposse/geodesic/releases
ARG VERSION=2.11.0
# If you don't want to bothered with updating the version, you can use `latest` instead,
# but keep in mind that as long as you have a local image with the `latest` tag,
# it will not be updated by `docker run`. You will have to explicitly pull the latest image.
# ARG VERSION=latest
ARG OS=debian
FROM cloudposse/geodesic:$VERSION-$OS
Expand Down
30 changes: 19 additions & 11 deletions rootfs/etc/profile.d/_07-term-mode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,26 @@
function _is_term_dark_mode() {
local x fg_rgb bg_rgb fg_lum bg_lum

# 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.
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
# 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.
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
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_TRACE =~ "terminal" ]]; then
echo $(tput setaf 1)* TRACE: "Terminal did not respond to OSC 10 and 11 queries.$(tput sgr0)" >&2
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
# If we cannot determine the color scheme, we assume light mode for historical reasons.
if [[ "$*" =~ -b ]] || [[ "$*" =~ -m ]]; then
Expand Down Expand Up @@ -116,7 +124,7 @@ function _srgb_to_luminance() {
if [[ -z $color ]]; then
if [[ $GEODESIC_TRACE =~ "terminal" ]]; then
# Use tput and sgr0 here because this is early in the startup sequence and trace logging
echo "$(tput setaf 1)* TRACE: ${FUNCNAME[0]} called with empty or no argument.$(tput sgr0)" >&2
echo "$(tput setaf 1)* TERMINAL TRACE: ${FUNCNAME[0]} called with empty or no argument.$(tput sgr0)" >&2
fi
echo "0"
return
Expand Down
79 changes: 62 additions & 17 deletions rootfs/etc/profile.d/_10-colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function update-terminal-mode() {
dark | light) ;;

"")
new_mode=$(_is_term_dark_mode -m)
new_mode=$(_is_term_dark_mode -mm)
;;

*)
Expand All @@ -25,8 +25,19 @@ function update-terminal-mode() {
;;
esac

if [[ $new_mode == "unknown" ]]; then
if ! tty -s; then
echo "No terminal detected." >&2
elif [[ -z "$(tput op 2>/dev/null)" ]]; then
echo "Terminal does not appear to support color." >&2
fi
new_mode="light"
fi

# See comments in _geodesic_color() below for why we test ${_geodesic_tput_cache@a}
if [[ ${_geodesic_tput_cache@a} != "A" ]] || [[ "${_geodesic_tput_cache[dark_mode]}" != "$new_mode" ]]; then
if [[ ${_geodesic_tput_cache@a} != "A" ]] ||
[[ "${_geodesic_tput_cache[dark_mode]}" != "$new_mode" ]] ||
[[ "${_geodesic_tput_cache[TERM]}" != "$TERM" ]]; then
_geodesic_tput_cache_init "$1"
else
echo "Not updating terminal mode from $new_mode to $new_mode"
Expand All @@ -36,17 +47,38 @@ function update-terminal-mode() {
# 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
local old_term=${_geodesic_tput_cache[TERM]}
# Save the terminal type so we can invalidate the cache if it changes
_geodesic_tput_cache[TERM]="$TERM"

local color_off=$(tput op 2>/dev/null) # reset foreground and background colors to defaults

if ! tty -s || [[ -z $color_off ]]; then
if [[ $GEODESIC_TRACE =~ "terminal" ]]; then
if ! tty -s; then
echo '* TERMINAL TRACE: Not running in a terminal, not attempting to colorize output' >&2
elif [[ -z $color_off ]]; then
echo '* TERMINAL TRACE: `tput` did not output anything for "op", not attempting to colorize output' >&2
else
echo '* TERMINAL TRACE: Unknown error (script bug), not attempting to colorize output' >&2
fi
fi
if [[ $old_term != ${_geodesic_tput_cache[TERM]} ]]; then
_geodesic_generate_color_functions dummy
command -V geodesic_prompt_style &>/dev/null && geodesic_prompt_style
fi
return 1
fi

# If we are here, we have lost the terminal mode settings.
# If we are not in a subshell, we are fixing them now.
# However, if we are in a subshell, we cannot fix them in the main shell
# 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.\n" >&2
printf "\n* Terminal mode settings have been lost (%s,%s).\n" "$SHLVL" "$BASH_SUBSHELL" >&2
printf "* Please run: update-terminal-mode \n\n" >&2
fi

local color_off=$(tput op) # reset foreground and background colors to defaults
local bold=$(tput bold)
local bold_off

Expand All @@ -61,6 +93,7 @@ function _geodesic_tput_cache_init() {

# Set up normal colors for light mode
_geodesic_tput_cache=(
[TERM]="$TERM"
[black]=$(tput setaf 0)
[red]=$(tput setaf 1)
[green]=$(tput setaf 2)
Expand Down Expand Up @@ -120,9 +153,11 @@ function _geodesic_tput_cache_init() {
_geodesic_tput_cache["bold-off"]=$(printf "\x01%s\x02" "$bold_off")
fi

# Save the terminal type so we can invalidate the cache if it changes
_geodesic_tput_cache[TERM]="$TERM"
_geodesic_tput_cache[dark_mode]="$new_mode"
if [[ $old_term != ${_geodesic_tput_cache[TERM]} ]]; then
_geodesic_generate_color_functions color
command -V geodesic_prompt_style &>/dev/null && geodesic_prompt_style
fi
}

# Colorize text using ANSI escape codes.
Expand Down Expand Up @@ -212,18 +247,26 @@ function _geodesic_color() {
# Also, "yellow" is not necessarily yellow, it varies with the terminal theme, and
# would be better named "caution" or "info".

function _generate_color_functions() {
local color
for color in red green yellow cyan; do
eval "function ${color}() { _geodesic_color ${color} \"\$*\"; }"
eval "bold-${color}() { _geodesic_color bold-${color} \"\$*\"; }"
eval "function ${color}-n() { _geodesic_color ${color}-n \"\$*\"; }"
eval "bold-${color}-n() { _geodesic_color bold-${color}-n \"\$*\"; }"
done
}
function _geodesic_generate_color_functions() {
local color colors
colors=(red green yellow cyan)

_generate_color_functions
unset _generate_color_functions
if [[ "$1" != "dummy" ]]; then
for color in "${colors[@]}"; do
eval "function ${color}() { _geodesic_color ${color} \"\$*\"; }"
eval "bold-${color}() { _geodesic_color bold-${color} \"\$*\"; }"
eval "function ${color}-n() { _geodesic_color ${color}-n \"\$*\"; }"
eval "bold-${color}-n() { _geodesic_color bold-${color}-n \"\$*\"; }"
done
else
for color in "${colors[@]}"; do
eval "function ${color}() { printf -- '%s\n' \"\$*\"; }"
eval "bold-${color}() { printf -- '%s\n' \"\$*\"; }"
eval "function ${color}-n() { printf -- '%s\n' \"\$*\"; }"
eval "bold-${color}-n() { printf -- '%s\n' \"\$*\"; }"
done
fi
}

function bold() {
_geodesic_color bold "$*"
Expand All @@ -233,3 +276,5 @@ function bold() {
function reset_terminal_colors() {
tput sgr0
}

_geodesic_tput_cache_init
Loading

0 comments on commit ee845d8

Please sign in to comment.