Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env bash
help() {
cat <<EOF
Simple monorepo lifecycle/pipeline tool for running one or more commands on one
or more directories that have diffs compared to an ansector. The primary
use case is for selective CI jobs within a trunk based workflow.
Takes two arguments, <glob> <command>. The command is invoked from each
directory context matching the glob.
@tomdavidson
tomdavidson / tf-config-files.tf
Created December 5, 2019 06:41
Terraform example loading config from dir of files
variable "config_files_path" {
default = "../../teams/*.yaml"
description = "The path to team config files"
}
data "local_file" "configs" {
for_each = { for k, file in fileset(dirname(var.config_files_path), basename(var.config_files_path)) :
k => abspath("${dirname(var.config_files_path)}/${file}")
}
@tomdavidson
tomdavidson / .editorconfig
Last active March 20, 2021 09:26
coordinated code configs
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false
$ cat Dockerfile
FROM docker.io/hello-world
$ docker build --tag uscm5 .
STEP 1: FROM docker.io/hello-world
STEP 2: COMMIT uscm5
--> d1165f22123
Successfully tagged localhost/uscm5:latest
Successfully tagged docker.io/library/hello-world:latest
d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726
#!/usr/bin/env zx
const shellFiles = globby.globbySync(['**/*.sh', '**/*.bash'], { gitignore: true });
nothrow($`npx -y shellcheck -f diff ssa-pg/scripts/deploy-infra.sh | git apply`);
@tomdavidson
tomdavidson / lolaus.sh
Created November 5, 2021 09:57
lolaus.sh
#!/usr/bin/env bash
set -euo pipefail
DEBUG=${DEBUG:-}
help() {
cat <<EOF
Simple monorepo lifecycle/pipeline tool for running one or more commands on one
or more directories that have diffs compared to an ancestor. The primary
@tomdavidson
tomdavidson / slugify.sh
Created November 20, 2021 05:13
Lowercased, shortened to 63 bytes, and with everything except 0-9 and a-z replaced with '-'. No leading or trailing '-'. Useful with URLs, host names, domain names, and stack names.
#!/usr/bin/env bash
shopt -s extglob
# Lowercased, shortened to 63 bytes, and with everything except 0-9 and a-z replaced with '-'.
# No leading or trailing '-'. Useful with URLs, host names, domain names, and stack names.
slugify() {
: "${1:?'Usage: slugify NAME'}"
local next="$1"
next="${next,,}" # lowercase
next="${next//+([^a-z0-9])/-}" # replace non-alphanumeric wiht '-'
next="${next#-}" # remove - from the start
@tomdavidson
tomdavidson / bootstrap.sh
Last active November 30, 2021 06:07
bootstrap script for setting up toms new computer
#!/usr/bin/env bash
# promts for sudo and can be installed via:
# wget -O - https://gist.githubusercontent.com/tomdavidson/64828803dbd4718514a465be1d7e908a/raw/75ec0521175b3d8b7d92c188d3dc0d251dbf5469/install-node-zx.sh | bash
! type sudo >/dev/null 2>&1 && apt install sudo && usermod -aG sudo "$(whoami)"
export CLOUDSDK_CORE_PROJECT='dots-333103'
# install NodeJS & zx if not already installed
@tomdavidson
tomdavidson / scrit-as-root.sh
Created November 30, 2021 16:06
snippit to help with scripts that should be run as root
#!/usr/bin/env bash
if [ $SUDO_USER ]; then
realUser=$SUDO_USER
else
realUser=$(whoami)
fi
realUserHome=$(bash -c "cd ~$(printf %q "$realUser") && pwd")
@tomdavidson
tomdavidson / twf.md
Created January 6, 2022 06:12
moving forward trunk based workflow

Trunk-based Workflow

Multiple "right ways" to implement trunk-based delepment and workflow. For more info checkout trunkbaseddevelopment.com. Tom's "right way" emphisies forward moving flow and deploying from artifacts rather than git SHAs:

  • All code change starts and ends with the single, long-lived trunk, main. There are no release, prod, or other long-lived branches. Releases are cut from the trunk.

  • Code review will utilize GitHub PRs from short-lived branches targeting the main trunk. We call these short-lived branches, working branches, to avoid conflating feature-based workflow with our trunk-based workflow.

  • Prior to integration, the proposed change is fully tested, even deployed when end-to-end or manual acceptance tests are needed. Git Hooks are used to run unit tests and static analysis prior to pushing.