forked from pythoninthegrasses/python_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
255 lines (217 loc) · 7.1 KB
/
Copy pathjustfile
File metadata and controls
255 lines (217 loc) · 7.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# See https://just.systems/man/en
# positional args
# * NOTE: unable to reuse recipe name (e.g., start/stop); prefix recipes with `@`
# set positional-arguments := true
# load .env
set dotenv-load
# set env var
export APP := `echo ${APP_NAME}`
export CPU := `echo ${CPU}`
export IMAGE := `echo ${IMAGE}`
export MEM := `echo ${MEM}`
export NS := `echo ${NS}`
export PROF := `echo ${PROF}`
export SCRIPT := "harden"
export SHELL := `echo ${SHELL}`
export TAG := `echo ${TAG}`
export VERSION := "latest"
# x86_64/arm64
arch := `uname -m`
# hostname
host := `uname -n`
# operating system
os := `uname -s`
# home directory
home_dir := env_var('HOME')
# docker-compose / docker compose
# * https://docs.docker.com/compose/install/linux/#install-using-the-repository
docker-compose := if `command -v docker-compose; echo $?` == "0" {
"docker-compose"
} else {
"docker compose"
}
# [halp] list available commands
default:
just --list
# [init] install dependencies, tooling, and virtual environment
install:
#!/usr/bin/env bash
set -euxo pipefail
# TODO: QA
# dependencies
if [[ {{os}} == "Linux" ]]; then
. "/etc/os-release"
case $ID in
ubuntu|debian)
sudo apt update && sudo apt install -y \
build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl \
llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
;;
arch|endeavouros)
sudo pacman -S --noconfirm \
base-devel openssl zlib bzip2 xz readline sqlite tk
;;
fedora)
sudo dnf install -y \
make gcc zlib-devel bzip2 bzip2-devel readline-devel \
sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
;;
centos)
sudo yum install -y \
make gcc zlib-devel bzip2 bzip2-devel readline-devel \
sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
;;
*)
echo "Unsupported OS"
exit 1
;;
esac
elif [[ {{os}} == "Darwin" ]]; then
xcode-select --install
[[ $(command -v brew >/dev/null 2>&1; echo $?) == "0" ]] || /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install gettext openssl readline sqlite3 xz zlib tcl-tk
elif [[ os() == "Windows"]]; then
echo "Windows is not supported"
exit 1
else
echo "Unsupported OS"
exit 1
fi
# install asdf
git clone https://github.com/asdf-vm/asdf.git "{{home_dir}}/.asdf" --branch v0.11.1
. "{{home_dir}}/.asdf/asdf.sh"
# install python w/asdf
asdf plugin-add python
asdf install python {{PY_VER}}
# install poetry
asdf plugin-add poetry https://github.com/asdf-community/asdf-poetry.git
asdf install poetry {{POETRY}}
# create virtual environment
poetry config virtualenvs.in-project true
poetry env use python
poetry install --no-root
# [deps] update dependencies
update-deps:
#!/usr/bin/env bash
# set -euxo pipefail
find . -maxdepth 3 -name "pyproject.toml" -exec \
echo "[{}]" \; -exec \
echo "Clearing pypi cache..." \; -exec \
poetry cache clear --all pypi --no-ansi \; -exec \
poetry update --lock --no-ansi \;
# [deps] export requirements.txt
export-reqs: update-deps
#!/usr/bin/env bash
# set -euxo pipefail
find . -maxdepth 3 -name "pyproject.toml" -exec \
echo "[{}]" \; -exec \
echo "Exporting requirements.txt..." \; -exec \
poetry export --no-ansi --without-hashes --output requirements.txt \;
# [git] update git submodules
sub:
@echo "To add a submodule:"
@echo "git submodule add https://github.com/username/repo.git path/to/submodule"
@echo "Updating all submodules..."
git submodule update --init --recursive && git pull --recurse-submodules -j8
# [git] update pre-commit hooks
pre-commit:
@echo "To install pre-commit hooks:"
@echo "pre-commit install -f"
@echo "Updating pre-commit hooks..."
pre-commit autoupdate
# [minikube] start minikube + tilt
start-minikube:
#!/usr/bin/env bash
set -euxo pipefail
if [[ $(minikube status -f \{\{\.Host\}\}) = 'Stopped' ]]; then
minikube start --memory={{MEM}} --cpus={{CPU}} -p {{PROF}}
fi
# [tilt] deploy docker image to local k8s cluster
tilt-up: start-minikube
tilt up
# [minikube] stop minikube
stop-minikube:
minikube stop -p {{PROF}}
# [check] lint sh script
checkbash:
#!/usr/bin/env bash
checkbashisms {{SCRIPT}}
if [[ $? -eq 1 ]]; then
echo "bashisms found. Exiting..."
exit 1
else
echo "No bashisms found"
fi
# [docker] build locally
build: checkbash
#!/usr/bin/env bash
set -euxo pipefail
if [[ {{arch}} == "arm64" ]]; then
docker build -f Dockerfile -t {{APP}} --build-arg CHIPSET_ARCH=aarch64-linux-gnu .
else
docker build -f Dockerfile --progress=plain -t {{APP}} .
fi
# [scripts] run script in working directory
sh args=SCRIPT:
sh {{args}}
# [docker] intel build
buildx: checkbash
docker buildx build -f Dockerfile --progress=plain -t ${TAG} --build-arg CHIPSET_ARCH=x86_64-linux-gnu --load .
# [docker] arm build w/docker-compose defaults
build-clean: checkbash
#!/usr/bin/env bash
set -euxo pipefail
if [[ {{arch}} == "arm64" ]]; then
{{docker-compose}} build --pull --no-cache --build-arg CHIPSET_ARCH=aarch64-linux-gnu --parallel
else
{{docker-compose}} build --pull --no-cache --parallel
fi
# [docker] login to registry (exit code 127 == 0)
login:
#!/usr/bin/env bash
# set -euxo pipefail
echo "Log into ${REGISTRY_URL} as ${USER_NAME}. Please enter your password: "
cmd=$(docker login --username ${USER_NAME} ${REGISTRY_URL})
if [[ $("$cmd" >/dev/null 2>&1; echo $?) -ne 127 ]]; then
echo 'Not logged into Docker. Exiting...'
exit 1
fi
# [docker] tag image as latest
tag-latest:
docker tag {{APP}}:latest {{IMAGE}}/{{APP}}:latest
# [docker] tag latest image from VERSION file
tag-version:
@echo "create tag {{APP}}:{{VERSION}} {{IMAGE}}/{{APP}}:{{VERSION}}"
docker tag {{APP}} {{IMAGE}}/{{APP}}:{{VERSION}}
# [docker] push latest image
push: login
docker push {{IMAGE}}/{{APP}}:{{TAG}}
# [docker] pull latest image
pull: login
docker pull {{IMAGE}}/{{APP}}
# [docker] run container
run: build
#!/usr/bin/env bash
# set -euxo pipefail
docker run --rm -it \
--name {{APP}} \
--env-file .env \
--entrypoint={{SHELL}} \
-h ${HOST:-localhost} \
-v $(pwd)/app:/app \
{{APP}}
# [docker] start docker-compose container
up: build
{{docker-compose}} up -d
# [docker] get running container logs
logs:
{{docker-compose}} logs -tf --tail="50" {{APP}}
# [docker] ssh into container
exec:
docker exec -it {{APP}} {{SHELL}}
# [docker] stop docker-compose container
stop:
{{docker-compose}} stop
# [docker] remove docker-compose container(s) and networks
down: stop
{{docker-compose}} down --remove-orphans