Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
import 'justfile.base'

set dotenv-load := true

export UBUNTU_PRO_TOKEN_FILE := env_var_or_default('UBUNTU_PRO_TOKEN_FILE', justfile_directory() + "/.secrets/ubuntu_pro_token")
export DOCKER_BUILDKIT := "1"

# technically, these could differ by 1 seconds, but thats unlikely and doesn't matter
# human readable, used as label in docker image

export BUILD_DATE := `date +'%y-%m-%dT%H:%M:%S.%3NZ'`

# monotonic, used as label in docker image *and* in docker tag

export BUILD_NUMBER := `date +'%y%m%d%H%M%S'`
export REVISION := `git rev-parse --short HEAD`

ensure-pro-token:
#!/bin/bash
set -euo pipefail
token_file="{{ UBUNTU_PRO_TOKEN_FILE }}"
if test -z "${UBUNTU_PRO_TOKEN:-}"; then
echo "UBUNTU_PRO_TOKEN is required to create $token_file" >&2
exit 1
fi
mkdir -p "$(dirname "$token_file")"
umask 077
printf '%s' "$UBUNTU_PRO_TOKEN" > "$token_file"
#!/bin/bash
set -euo pipefail
token_file="{{ UBUNTU_PRO_TOKEN_FILE }}"
if test -z "${UBUNTU_PRO_TOKEN:-}"; then
echo "UBUNTU_PRO_TOKEN is required to create $token_file" >&2
exit 1
fi
mkdir -p "$(dirname "$token_file")"
umask 077
printf '%s' "$UBUNTU_PRO_TOKEN" > "$token_file"

# build docker image for version
build version target="python" *args="": ensure-pro-token
docker compose --env-file {{ version }}/env build --pull {{ args }} {{ target }}


# test docker image for version
test version *args="tests -v": (build version)
docker compose --env-file {{ version }}/env run --rm -v $PWD:/workspace python pytest {{ args }}


# run pip-compile to add new dependencies, or update existing ones with --upgrade
update version *args="":
docker compose --env-file {{ version }}/env run --rm -v $PWD:/workspace base pip-compile {{ args }} {{ version }}/requirements.in -o {{ version }}/requirements.txt
Expand All @@ -41,13 +45,17 @@ update version *args="":
render version *args:
docker compose --env-file {{ version }}/env run --rm -v $PWD:/workspace python ./scripts/render.py {{ args }} > {{ version }}/packages.md

@lint-docker:
{{ docker_run_safe }} -i ghcr.io/hadolint/hadolint:{{ hadolint_version }} < Dockerfile

# run linters
check:
@docker run --rm -i hadolint/hadolint:v2.14.0 < Dockerfile
@ls scripts/*.sh | xargs docker run --rm -v "$PWD:/mnt:ro" koalaman/shellcheck:v0.11.0
@docker run --rm -v "$PWD:/repo:ro" --workdir /repo rhysd/actionlint:1.7.10 -color
@shellcheck:
{{ docker_run_safe }} -v "$PWD:/mnt:ro" koalaman/shellcheck:{{ shellcheck_version }} scripts/*.sh

@lint-actions:
{{ docker_run_safe }} -v $(pwd):/repo:ro --workdir /repo kjanat/actionlint:{{ actionlint_version }} -color

# run linters
check: lint-docker shellcheck lint-actions

# publish version (dry run by default - pass "true" to perform publish)
publish version publish="false":
Expand Down
12 changes: 12 additions & 0 deletions justfile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
######## Tooling versions ########

actionlint_version := "1.17.0@sha256:d484cccadf56b6a356466ade9af4c8e05c5dce1badaf0a9ecd0d7639d68d9c92"

shellcheck_version := "v0.11.0@sha256:61862eba1fcf09a484ebcc6feea46f1782532571a34ed51fedf90dd25f925a8d"

hadolint_version := "v2.15.1-alpine@sha256:a1d49ae1a4e83c1dbad26b8c1ad7588c8bd1e04f4866b34ad3cac50335198552"

######## Reusable variables ########
# Run Docker with minimim possible privileges. Note that if you mount any directories in
# you must still ensure these are mounted read-only.
docker_run_safe := 'docker run --rm --network none --read-only --cap-drop ALL --security-opt no-new-privileges:true --user 65534:65534'
Loading