Skip to content

Commit fc6b6df

Browse files
Update justfile w/args
Update justfile Sort exports, fix spaces -> tabs
1 parent b82ef01 commit fc6b6df

File tree

2 files changed

+111
-106
lines changed

2 files changed

+111
-106
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ TAG=7.8.2003
66
CPU=3
77
MEM=2048
88
NS=cs50w
9+
POETRY=1.3.2
910
PROF=minikube
11+
PY_VER=3.10.9
1012
SHELL=/bin/bash
1113
USER=apiuser
1214
PASSWORD=apiuserpassword

justfile

Lines changed: 109 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
# See https://just.systems/man/en
22

3-
# positional args
4-
# * NOTE: unable to reuse recipe name (e.g., start/stop); prefix recipes with `@`
5-
# set positional-arguments := true
6-
73
# load .env
84
set dotenv-load
95

6+
# positional params
7+
set positional-arguments
8+
109
# set env var
11-
export APP := `echo ${APP_NAME}`
12-
export CPU := `echo ${CPU}`
13-
export IMAGE := `echo ${IMAGE}`
14-
export MEM := `echo ${MEM}`
15-
export NS := `echo ${NS}`
16-
export PROF := `echo ${PROF}`
17-
export SCRIPT := "harden"
18-
export SHELL := `echo ${SHELL}`
19-
export TAG := `echo ${TAG}`
20-
export VERSION := "latest"
10+
export APP := `echo ${APP_NAME:-"python_template"}`
11+
export CPU := `echo ${CPU:-"2"}`
12+
export CWD := `echo $(pwd)`
13+
export IMAGE := `echo "python3.10.9-slim-bullseye:latest"`
14+
export MEM := `echo ${MEM:-"2048"}`
15+
export NS := `echo ${NS:-"default"}`
16+
export POETRY := `echo ${POETRY:-"1.3.2"}`
17+
export PROF := `echo ${PROF:-"minikube"}`
18+
export PY_VER := `echo ${PY_VER:-"3.10.9"}`
19+
export SCRIPT := `echo ${SCRIPT:-"startup.sh"}`
20+
export SHELL := `echo ${SHELL:-"/bin/bash"}`
21+
export TAG := `echo ${TAG:-"latest"}`
22+
export VERSION := `echo ${VERSION:-"latest"}`
2123

2224
# x86_64/arm64
2325
arch := `uname -m`
@@ -42,118 +44,119 @@ docker-compose := if `command -v docker-compose; echo $?` == "0" {
4244
# [halp] list available commands
4345
default:
4446
just --list
47+
@echo {{IMAGE}}
4548

4649
# [init] install dependencies, tooling, and virtual environment
47-
install:
48-
#!/usr/bin/env bash
49-
set -euxo pipefail
50-
51-
# TODO: QA
52-
# dependencies
53-
if [[ {{os}} == "Linux" ]]; then
54-
. "/etc/os-release"
55-
case $ID in
56-
ubuntu|debian)
57-
sudo apt update && sudo apt install -y \
58-
build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl \
59-
llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
60-
;;
61-
arch|endeavouros)
62-
sudo pacman -S --noconfirm \
63-
base-devel openssl zlib bzip2 xz readline sqlite tk
64-
;;
65-
fedora)
66-
sudo dnf install -y \
67-
make gcc zlib-devel bzip2 bzip2-devel readline-devel \
68-
sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
69-
;;
70-
centos)
71-
sudo yum install -y \
72-
make gcc zlib-devel bzip2 bzip2-devel readline-devel \
73-
sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
74-
;;
75-
*)
76-
echo "Unsupported OS"
77-
exit 1
78-
;;
79-
esac
80-
elif [[ {{os}} == "Darwin" ]]; then
81-
xcode-select --install
82-
[[ $(command -v brew >/dev/null 2>&1; echo $?) == "0" ]] || /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
83-
brew install gettext openssl readline sqlite3 xz zlib tcl-tk
84-
elif [[ os() == "Windows"]]; then
85-
echo "Windows is not supported"
86-
exit 1
87-
else
88-
echo "Unsupported OS"
89-
exit 1
90-
fi
91-
92-
# install asdf
93-
git clone https://github.com/asdf-vm/asdf.git "{{home_dir}}/.asdf" --branch v0.11.1
94-
. "{{home_dir}}/.asdf/asdf.sh"
95-
96-
# install python w/asdf
97-
asdf plugin-add python
98-
asdf install python {{PY_VER}}
99-
100-
# install poetry
101-
asdf plugin-add poetry https://github.com/asdf-community/asdf-poetry.git
102-
asdf install poetry {{POETRY}}
103-
104-
# create virtual environment
105-
poetry config virtualenvs.in-project true
106-
poetry env use python
107-
poetry install --no-root
50+
install args=CWD:
51+
#!/usr/bin/env bash
52+
set -euxo pipefail
53+
54+
# TODO: QA
55+
# dependencies
56+
if [[ {{os}} == "Linux" ]]; then
57+
. "/etc/os-release"
58+
case $ID in
59+
ubuntu|debian)
60+
sudo apt update && sudo apt install -y \
61+
build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl \
62+
llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
63+
;;
64+
arch|endeavouros)
65+
sudo pacman -S --noconfirm \
66+
base-devel openssl zlib bzip2 xz readline sqlite tk
67+
;;
68+
fedora)
69+
sudo dnf install -y \
70+
make gcc zlib-devel bzip2 bzip2-devel readline-devel \
71+
sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
72+
;;
73+
centos)
74+
sudo yum install -y \
75+
make gcc zlib-devel bzip2 bzip2-devel readline-devel \
76+
sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
77+
;;
78+
*)
79+
echo "Unsupported OS"
80+
exit 1
81+
;;
82+
esac
83+
elif [[ {{os}} == "Darwin" ]]; then
84+
xcode-select --install
85+
[[ $(command -v brew >/dev/null 2>&1; echo $?) == "0" ]] || /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
86+
brew install gettext openssl readline sqlite3 xz zlib tcl-tk
87+
elif [[ os() == "Windows"]]; then
88+
echo "Windows is not supported"
89+
exit 1
90+
else
91+
echo "Unsupported OS"
92+
exit 1
93+
fi
94+
95+
# install asdf
96+
git clone https://github.com/asdf-vm/asdf.git "{{home_dir}}/.asdf" --branch v0.11.1
97+
. "{{home_dir}}/.asdf/asdf.sh"
98+
99+
# install python w/asdf
100+
asdf plugin-add python
101+
asdf install python {{PY_VER}}
102+
103+
# install poetry
104+
asdf plugin-add poetry https://github.com/asdf-community/asdf-poetry.git
105+
asdf install poetry {{POETRY}}
106+
107+
# create virtual environment
108+
poetry config virtualenvs.in-project true
109+
poetry env use python
110+
poetry --directory {{args}} install --no-root
108111

109112
# [deps] update dependencies
110-
update-deps:
111-
#!/usr/bin/env bash
112-
# set -euxo pipefail
113-
find . -maxdepth 3 -name "pyproject.toml" -exec \
114-
echo "[{}]" \; -exec \
115-
echo "Clearing pypi cache..." \; -exec \
116-
poetry cache clear --all pypi --no-ansi \; -exec \
117-
poetry update --lock --no-ansi \;
113+
update-deps args=CWD:
114+
#!/usr/bin/env bash
115+
# set -euxo pipefail
116+
find . -maxdepth 3 -name "pyproject.toml" -exec \
117+
echo "[{}]" \; -exec \
118+
echo "Clearing pypi cache..." \; -exec \
119+
poetry --directory {{args}} cache clear --all pypi --no-ansi \; -exec \
120+
poetry --directory {{args}} update --lock --no-ansi \;
118121

119122
# [deps] export requirements.txt
120-
export-reqs: update-deps
121-
#!/usr/bin/env bash
122-
# set -euxo pipefail
123-
find . -maxdepth 3 -name "pyproject.toml" -exec \
124-
echo "[{}]" \; -exec \
125-
echo "Exporting requirements.txt..." \; -exec \
126-
poetry export --no-ansi --without-hashes --output requirements.txt \;
123+
export-reqs args=CWD: update-deps
124+
#!/usr/bin/env bash
125+
# set -euxo pipefail
126+
find {{CWD}} -maxdepth 3 -name "pyproject.toml" -exec \
127+
echo "[{}]" \; -exec \
128+
echo "Exporting requirements.txt..." \; -exec \
129+
poetry --directory {{args}} export --no-ansi --without-hashes --output requirements.txt \;
127130

128131
# [git] update git submodules
129132
sub:
130-
@echo "To add a submodule:"
131-
@echo "git submodule add https://github.com/username/repo.git path/to/submodule"
132-
@echo "Updating all submodules..."
133-
git submodule update --init --recursive && git pull --recurse-submodules -j8
133+
@echo "To add a submodule:"
134+
@echo "git submodule add https://github.com/username/repo.git path/to/submodule"
135+
@echo "Updating all submodules..."
136+
git submodule update --init --recursive && git pull --recurse-submodules -j8
134137

135138
# [git] update pre-commit hooks
136139
pre-commit:
137-
@echo "To install pre-commit hooks:"
138-
@echo "pre-commit install -f"
139-
@echo "Updating pre-commit hooks..."
140-
pre-commit autoupdate
140+
@echo "To install pre-commit hooks:"
141+
@echo "pre-commit install -f"
142+
@echo "Updating pre-commit hooks..."
143+
pre-commit autoupdate
141144

142145
# [minikube] start minikube + tilt
143146
start-minikube:
144-
#!/usr/bin/env bash
145-
set -euxo pipefail
146-
if [[ $(minikube status -f \{\{\.Host\}\}) = 'Stopped' ]]; then
147-
minikube start --memory={{MEM}} --cpus={{CPU}} -p {{PROF}}
148-
fi
147+
#!/usr/bin/env bash
148+
set -euxo pipefail
149+
if [[ $(minikube status -f \{\{\.Host\}\}) = 'Stopped' ]]; then
150+
minikube start --memory={{MEM}} --cpus={{CPU}} -p {{PROF}}
151+
fi
149152

150153
# [tilt] deploy docker image to local k8s cluster
151154
tilt-up: start-minikube
152-
tilt up
155+
tilt up
153156

154157
# [minikube] stop minikube
155158
stop-minikube:
156-
minikube stop -p {{PROF}}
159+
minikube stop -p {{PROF}}
157160

158161
# [check] lint sh script
159162
checkbash:
@@ -178,7 +181,7 @@ build: checkbash
178181

179182
# [scripts] run script in working directory
180183
sh args=SCRIPT:
181-
sh {{args}}
184+
sh {{args}}
182185

183186
# [docker] intel build
184187
buildx: checkbash

0 commit comments

Comments
 (0)