-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
executable file
·70 lines (57 loc) · 2.04 KB
/
bootstrap.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
#!/bin/bash
### The following environment variables can be used to adjust processing
# 1. We're downloading and installing micromamba here, if required:
MAMBA_ROOT_PREFIX=${MAMBA_ROOT_PREFIX:-"$PWD/mamba"}
# 2. The path to the productive python environment:
PRODUCTION_ENV=${PRODUCTION_ENV:-"$PWD/venv"}
# if present, use this file to initialize the production environment:
ENVIRONMENT_FILE=${ENVIRONMENT_FILE:-"environment.yml"}
# otherwise, just install python in the given version:
PYTHON_VERSION=${PYTHON_VERSION:-3.10}
# 3. finally, run pip with the following argument to install the project:
PIP_SPEC="${PIP_SPEC:-.[production]}"
###
export MAMBA_ROOT_PREFIX PRODUCTION_ENV
micromamba="$MAMBA_ROOT_PREFIX/bin/micromamba"
echob () {
tput bold
echo "$@"
tput sgr0
}
if [[ -x "$micromamba" ]]; then
echob "Micromamba environment present at $MAMBA_ROOT_PREFIX"
else
echob "Downloading micromamba to $MAMBA_ROOT_PREFIX ..."
mkdir "$MAMBA_ROOT_PREFIX" && wget -qO- https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -C "$MAMBA_ROOT_PREFIX" -xj bin/micromamba
fi
if [[ -r ${ENVIRONMENT_FILE} ]]
then
echob "Found environment.yml, installing its contents to $PRODUCTION_ENV"
$micromamba create --no-rc --yes -p "$PRODUCTION_ENV" -f "${ENVIRONMENT_FILE}"
elif [[ -x "${PRODUCTION_ENV}/bin/python${PYTHON_VERSION}" ]]
then
echob "Python $PYTHON_VERSION is already installed in $PRODUCTION_ENV"
else
echob "Using micromamba to install Python $PYTHON_VERSION to $PRODUCTION_ENV ..."
$micromamba create --no-rc --yes -p "$PRODUCTION_ENV" python=3.10 wheel -c conda-forge
fi
if [[ -n "$PIP_SPEC" ]]
then
echob "Using pip to install the project ($PIP_SPEC) ..."
$micromamba --no-rc -p "$PRODUCTION_ENV" run pip install "$PIP_SPEC"
fi
if [[ ! -r run-server ]]
then
cat > run-server.sh <<EOF
#!/bin/sh
cd "$PWD"
if test -r .env
then
. ./.env
fi
exec $PRODUCTION_ENV/bin/gunicorn
EOF
chmod 755 ./run-server.sh
echob "You may now want to create an .env file to configure stuff"
echob "and run $PWD/run-server.sh to start the server."
fi