-
Notifications
You must be signed in to change notification settings - Fork 3
/
key.sh
executable file
·98 lines (94 loc) · 3.32 KB
/
key.sh
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
#!/bin/bash
set -e
PROJECT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
PROJECT_NAME=$(cat $PROJECT_DIR/PROJECT_NAME | tr -d '\n')
if [ -z "$PROJECT_NAME" ]; then
echo "PROJECT_NAME file must be set with project name."
exit 1
fi
FOLDER_HASH=$(echo $PROJECT_DIR | md5sum | cut -c 1-5)
GEN_VOLUME_NAME=hitch-vol-${PROJECT_NAME}-${FOLDER_HASH}
IMAGE_NAME=hitch-${FOLDER_HASH}-${PROJECT_NAME}
hitchrun() {
podman run --privileged -it --rm \
--network host \
-v $PROJECT_DIR:/src \
-v $GEN_VOLUME_NAME:/gen \
-v ~/.ssh/id_rsa:/root/.ssh/id_rsa \
-v ~/.ssh/id_rsa.pub:/root/.ssh/id_rsa.pub \
-e CI=$CI \
--secret pypitoken,type=env,target=PYPITOKEN \
--secret githubtoken,type=env,target=GITHUBTOKEN \
--workdir /src \
$IMAGE_NAME \
$1
}
case "$1" in
"clean")
case "$2" in
"all")
if podman image exists $IMAGE_NAME; then
podman image rm -f $IMAGE_NAME
fi
if podman volume exists $GEN_VOLUME_NAME; then
podman volume rm -f $GEN_VOLUME_NAME
fi
;;
"gen")
if podman volume exists $GEN_VOLUME_NAME; then
podman volume rm -f $GEN_VOLUME_NAME
fi
podman volume create $GEN_VOLUME_NAME
;;
"pyenv")
hitchrun "rm -rf /gen/pyenv/"
;;
"devenv")
hitchrun "rm /gen/pyenv/versions/devvenv"
;;
*)
echo "Invalid clean target. ./key.sh clean [all]"
exit 1
;;
esac
;;
"make")
case "$2" in
"")
echo "building ci container..."
if ! podman volume exists $GEN_VOLUME_NAME; then
podman volume create $GEN_VOLUME_NAME
fi
podman build -f hitch/Dockerfile-hitch -t $IMAGE_NAME $PROJECT_DIR
hitchrun "virtualenv --python=python3 /gen/venv"
hitchrun "/gen/venv/bin/pip install setuptools-rust"
hitchrun "/gen/venv/bin/pip install -r /src/hitch/hitchreqs.txt"
hitchrun "/gen/venv/bin/python hitch/key.py build"
;;
"gen")
hitchrun "virtualenv --python=python3 /gen/venv"
hitchrun "/gen/venv/bin/pip install setuptools-rust"
hitchrun "/gen/venv/bin/pip install -r /src/hitch/hitchreqs.txt"
hitchrun "/gen/venv/bin/python hitch/key.py build"
;;
"pylibrarytoolkit")
hitchrun "/gen/venv/bin/pip uninstall hitchpylibrarytoolkit -y"
hitchrun "/gen/venv/bin/pip install --no-deps -e /src/hitchpylibrarytoolkit"
;;
"hitchreqs")
hitchrun "/gen/venv/bin/pip-compile hitch/hitchreqs.in -o hitch/hitchreqs.txt"
;;
*)
echo "Invalid make target. ./key.sh make [all|gen|pylibrarytoolkit]"
exit 1
;;
esac
;;
"bash")
hitchrun "bash"
;;
*)
hitchrun "/gen/venv/bin/python hitch/key.py $1 $2 $3 $4 $5 $6 $7 $8 $9"
;;
esac
exit