File tree Expand file tree Collapse file tree 10 files changed +114
-71
lines changed Expand file tree Collapse file tree 10 files changed +114
-71
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,9 @@ default: help
1414.pre-commit-cache :
1515 mkdir .pre-commit-cache
1616
17+ .git/hooks/_commons.inc.sh :
18+ cp bin/_commons.inc.sh .git/hooks/_commons.inc.sh
19+
1720.git/hooks/pre-commit :
1821 cp bin/git-pre-commit-hook .git/hooks/pre-commit
1922
@@ -23,17 +26,18 @@ default: help
2326# ## BOOTSTRAP
2427bootstrap : # # setup development environment (build dev service and install git hooks)
2528bootstrap : \
26- build \
27- migrate \
28- create-superuser \
29- jupytext--to-ipynb
29+ build \
30+ migrate \
31+ create-superuser \
32+ jupytext--to-ipynb
3033.PHONY : bootstrap
3134
3235git-hooks : # # install pre-commit hook
3336git-hooks : \
34- .pre-commit-cache \
35- .git/hooks/pre-commit \
36- .git/hooks/commit-msg
37+ .pre-commit-cache \
38+ .git/hooks/_commons.inc.sh \
39+ .git/hooks/pre-commit \
40+ .git/hooks/commit-msg
3741.PHONY : git-hooks
3842
3943# ## BUILD
Original file line number Diff line number Diff line change 1+ #
2+ # Bash library for utility scripts
3+ #
4+ # shellcheck shell=bash
5+
6+ declare DOCKER_USER
7+ declare -i DOCKER_UID
8+ declare -i DOCKER_GID
9+
10+ DOCKER_UID=" $( id -u) "
11+ DOCKER_GID=" $( id -g) "
12+ # Use a higher GID for MacOS users to prevent permission issues with the default
13+ # GID=20
14+ if [[ " ${OSTYPE} " =~ " darwin" ]]; then
15+ DOCKER_GID=1000
16+ fi
17+ DOCKER_USER=" ${DOCKER_UID} :${DOCKER_GID} "
18+
19+ export DOCKER_UID
20+ export DOCKER_GID
21+ export DOCKER_USER
22+
23+
24+ function compose(){
25+
26+ docker compose " $@ "
27+ }
28+
29+
30+ function compose_run(){
31+
32+ if [[ -z " ${2} " ]]; then
33+ echo " usage: compose_run [--no-deps] SERVICE COMMAND"
34+ exit 1
35+ fi
36+
37+ # Arguments
38+ declare -i no_deps
39+ if [[ " $1 " == " --no-deps" ]]; then
40+ no_deps=1
41+ shift
42+ fi
43+
44+ declare service=" ${1} "
45+ shift
46+
47+ declare user=" ${DOCKER_USER} "
48+ declare volume=" ./src/${service} :/app"
49+ declare -a args=(--rm --user " ${user} " --volume " ${volume} " )
50+
51+ # Prevent 'the input device is not a TTY' error from `docker compose run`
52+ # by disabling TTY when standard output is not a TTY
53+ if [[ " $( tty 2> /dev/null) " == " not a tty" ]]; then
54+ args+=(--no-TTY)
55+ fi
56+
57+ # Do not run related services
58+ if [[ no_deps -eq 1 ]]; then
59+ args+=(--no-deps)
60+ fi
61+
62+ compose run \
63+ " ${args[@]} " \
64+ " ${service} " \
65+ " $@ "
66+ }
Original file line number Diff line number Diff line change 22
33set -eo pipefail
44
5- declare DOCKER_USER
6- DOCKER_UID=" $( id -u) "
7- DOCKER_GID=" $( id -g) "
5+ declare cmd
86
7+ source " $( dirname " $( readlink -f " $0 " ) " ) /_commons.inc.sh"
98
10- DOCKER_USER=" ${DOCKER_UID} :${DOCKER_GID} "
11-
12- extra_args=()
13- # Prevent 'the input device is not a TTY' error from `docker compose run`
14- # by disabling TTY when standard output is not a TTY
15- if [[ " $1 " == run && " $( tty 2> /dev/null) " == " not a tty" ]]; then
16- extra_args=(run --no-TTY)
9+ cmd=" compose"
10+ if [[ " $1 " == run ]]; then
11+ cmd=" compose_run"
1712 shift
1813fi
1914
20-
21- DOCKER_USER=${DOCKER_USER} \
22- DOCKER_UID=${DOCKER_UID} \
23- DOCKER_GID=${DOCKER_GID} \
24- docker compose " ${extra_args[@]} " " $@ "
15+ eval $cmd " $@ "
Original file line number Diff line number Diff line change 11#! /usr/bin/env bash
22
3+ set -eo pipefail
4+
35cz --config dev/pyproject.toml " $@ "
Original file line number Diff line number Diff line change 11#! /usr/bin/env bash
22
3+ set -eo pipefail
4+
35# read commit message
46MESSAGE=$( cat " $1 " )
57
Original file line number Diff line number Diff line change 11#! /usr/bin/env bash
22
3- declare DOCKER_USER
4- DOCKER_USER=" $( id -u) :$( id -g) "
3+ set -eo pipefail
54
6- DOCKER_USER=${DOCKER_USER} docker compose \
7- run \
8- --no-TTY \
9- --rm \
10- dev \
5+ source " $( dirname " $( readlink -f " $0 " ) " ) /_commons.inc.sh"
6+
7+ compose_run --no-deps \
8+ dev \
119 bash -c " cd dev && uv run pre-commit run"
Original file line number Diff line number Diff line change 11#! /usr/bin/env bash
22
3- declare DOCKER_USER
4- DOCKER_USER=" $( id -u) :$( id -g) "
3+ set -eo pipefail
54
6- DOCKER_USER=${DOCKER_USER} docker compose run --rm notebook uv run jupytext " $@ "
5+ source " $( dirname " $( readlink -f " $0 " ) " ) /_commons.inc.sh"
6+
7+ compose_run \
8+ notebook \
9+ uv run jupytext " $@ "
Original file line number Diff line number Diff line change 22
33set -eo pipefail
44
5- declare DOCKER_USER
6- DOCKER_UID=" $( id -u) "
7- DOCKER_GID=" $( id -g) "
8- DOCKER_USER=" ${DOCKER_UID} :${DOCKER_GID} "
9-
10- DOCKER_USER=${DOCKER_USER} \
11- DOCKER_UID=${DOCKER_UID} \
12- DOCKER_GID=${DOCKER_GID} \
13- docker compose run -it \
14- tycho \
5+ source " $( dirname " $( readlink -f " $0 " ) " ) /_commons.inc.sh"
6+
7+ declare service=${SERVICE:- tycho}
8+
9+ compose_run \
10+ " ${service} " \
1511 uv run python manage.py " $@ "
Original file line number Diff line number Diff line change 22
33set -eo pipefail
44
5- declare TEST=true
6- declare service=${SERVICE:- tycho}
7- declare cmd=" uv run pytest"
8- declare volume=" ./src/${service} :/app"
9- declare DOCKER_USER
10- DOCKER_UID=" $( id -u) "
11- DOCKER_GID=" $( id -g) "
12- DOCKER_USER=" ${DOCKER_UID} :${DOCKER_GID} "
5+ source " $( dirname " $( readlink -f " $0 " ) " ) /_commons.inc.sh"
136
7+ declare service=${SERVICE:- tycho}
148
15- DOCKER_USER=${DOCKER_USER} \
16- DOCKER_UID=${DOCKER_UID} \
17- DOCKER_GID=${DOCKER_GID} \
18- docker compose run --rm \
19- -e TEST=" ${TEST} " \
20- -v " ${volume} " \
21- " ${service} " \
22- ${cmd} " $@ "
9+ compose_run \
10+ " ${service} " \
11+ uv run pytest " $@ "
Original file line number Diff line number Diff line change 22
33set -eo pipefail
44
5+ source " $( dirname " $( readlink -f " $0 " ) " ) /_commons.inc.sh"
6+
57declare service=" ${SERVICE:- tycho} "
6- declare volume=" ./src/${service} :/app"
7- declare DOCKER_USER
8- DOCKER_UID=" $( id -u) "
9- DOCKER_GID=" $( id -g) "
10- DOCKER_USER=" ${DOCKER_UID} :${DOCKER_GID} "
118
12- DOCKER_USER=${DOCKER_USER} \
13- DOCKER_UID=${DOCKER_UID} \
14- DOCKER_GID=${DOCKER_GID} \
15- docker compose run --rm --no-deps \
16- -u " uv:uv" \
17- -v " ${volume} " \
18- " ${service} " \
19- uv " $@ "
9+ compose_run --no-deps \
10+ " ${service} " \
11+ uv " $@ "
You can’t perform that action at this time.
0 commit comments