1-click installer using micromamba to install git and python into a contained environment (if necessary) before running the normal installation script

This commit is contained in:
cmdr2 2022-10-12 16:38:06 +05:30 committed by tildebyte
parent 2b6d78e436
commit 71426d200e
7 changed files with 293 additions and 0 deletions

View File

@ -0,0 +1,51 @@
The installer zip contains two files: the script, and the micromamba binary.
Micromamba is a single ~8mb binary file, that acts like a package manager (drop-in replacement for conda).
# Download micromamba from:
* Windows x64: `curl -Ls https://micro.mamba.pm/api/micromamba/win-64/latest | tar -xvj bin/micromamba_win_x64.exe`
* Linux x64: `curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba_linux_x64`
* Linux arm64: `curl -Ls https://micro.mamba.pm/api/micromamba/linux-aarch64/latest | tar -xvj bin/micromamba_linux_arm64`
* Mac x64: `curl -Ls https://micro.mamba.pm/api/micromamba/osx-64/latest | tar -xvj bin/micromamba_mac_x64`
* Mac arm64 (M1/Apple Silicon): `curl -Ls https://micro.mamba.pm/api/micromamba/osx-arm64/latest | tar -xvj bin/micromamba_mac_arm64`
The download link provides tar.bz2 files.
(source https://mamba.readthedocs.io/en/latest/installation.html)
# Create the installer
Create the following folder structure, and zip it up.
For Linux/Mac: Make sure the `chmod u+x` permission is granted to `installer.sh` and the corresponding `micromamba` binary.
### Windows x64:
```
.\installer.bat
.\installer_files\micromamba_win_x64.exe
```
### Linux x64:
```
.\installer.sh
.\installer_files\micromamba_linux_x64
```
### Linux arm64:
```
.\installer.sh
.\installer_files\micromamba_linux_arm64
```
### Mac x64:
```
.\installer.sh
.\installer_files\micromamba_mac_x64
```
### Mac arm64 (M1/Apple Silicon):
```
.\installer.sh
.\installer_files\micromamba_mac_arm64
```

80
installer/install.bat Normal file
View File

@ -0,0 +1,80 @@
@echo off
@rem This script will install git and python (if not found on the PATH variable)
@rem using micromamba (an 8mb static-linked single-file binary, conda replacement).
@rem For users who already have git and python, this step will be skipped.
@rem Next, it'll checkout the project's git repo, if necessary.
@rem Finally, it'll create the conda environment and preload the models.
@rem This enables a user to install this project without manually installing python and git.
@rem prevent the window from closing after an error
if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit )
@rem config
set MAMBA_ROOT_PREFIX=%cd%\installer_files\mamba
set INSTALL_ENV_DIR=%cd%\installer_files\env
set MICROMAMBA_BINARY_FILE=%cd%\installer_files\micromamba_win_x64.exe
set PATH=%PATH%;%INSTALL_ENV_DIR%;%INSTALL_ENV_DIR%\Library\bin;%INSTALL_ENV_DIR%\Scripts
@rem initialize micromamba
if not exist "%MAMBA_ROOT_PREFIX%" (
mkdir "%MAMBA_ROOT_PREFIX%"
copy "%MICROMAMBA_BINARY_FILE%" "%MAMBA_ROOT_PREFIX%\micromamba.exe"
@rem test the mamba binary
echo Micromamba version:
call "%MAMBA_ROOT_PREFIX%\micromamba.exe" --version
@rem run the shell hook, otherwise activate will fail
if not exist "%MAMBA_ROOT_PREFIX%\Scripts" (
call "%MAMBA_ROOT_PREFIX%\micromamba.exe" shell hook --log-level 4 -s cmd.exe
)
)
call "%MAMBA_ROOT_PREFIX%\condabin\mamba_hook.bat"
@rem figure out whether git and python needs to be installed
set PACKAGES_TO_INSTALL=
call python --version "" >tmp/stdout.txt 2>tmp/stderr.txt
if "%ERRORLEVEL%" NEQ "0" set PACKAGES_TO_INSTALL=%PACKAGES_TO_INSTALL% python
call git --version "" >tmp/stdout.txt 2>tmp/stderr.txt
if "%ERRORLEVEL%" NEQ "0" set PACKAGES_TO_INSTALL=%PACKAGES_TO_INSTALL% git
@rem (if necessary) install git and python into a contained environment
if "%PACKAGES_TO_INSTALL%" NEQ "" (
echo "Packages to install: %PACKAGES_TO_INSTALL%"
@rem install git and python into the installer env
if not exist "%INSTALL_ENV_DIR%" (
call micromamba create -y --prefix "%INSTALL_ENV_DIR%"
)
call micromamba install -y --prefix "%INSTALL_ENV_DIR%" -c conda-forge %PACKAGES_TO_INSTALL%
@rem activate
call micromamba activate "%INSTALL_ENV_DIR%"
)
@rem get the repo (and load into the current directory)
if not exist ".git" (
call git init
call git remote add origin https://github.com/cmdr2/InvokeAI.git
call git fetch
call git checkout origin/main -ft
)
@rem create the environment
call micromamba create -f environment.yml
call micromamba activate invokeai
@rem preload the models
call python scripts\preload_models.py
@rem make the models dir
mkdir models\ldm\stable-diffusion-v1
pause

85
installer/install.sh Normal file
View File

@ -0,0 +1,85 @@
#!/bin/bash
# This script will install git and python (if not found on the PATH variable)
# using micromamba (an 8mb static-linked single-file binary, conda replacement).
# For users who already have git and python, this step will be skipped.
# Next, it'll checkout the project's git repo, if necessary.
# Finally, it'll create the conda environment and preload the models.
# This enables a user to install this project without manually installing python and git.
OS_NAME=$(uname -s)
case "${OS_NAME}" in
Linux*) OS_NAME="linux";;
Darwin*) OS_NAME="mac";;
*) echo "Unknown OS: $OS_NAME! This script runs only on Linux or Mac" && exit
esac
OS_ARCH=$(uname -m)
case "${OS_ARCH}" in
x86_64*) OS_ARCH="x64";;
arm64*) OS_ARCH="arm64";;
*) echo "Unknown system architecture: $OS_ARCH! This script runs only on x86_64 or arm64" && exit
esac
# config
export MAMBA_ROOT_PREFIX="$(pwd)/installer_files/mamba"
INSTALL_ENV_DIR="$(pwd)/installer_files/env"
MICROMAMBA_BINARY_FILE="$(pwd)/installer_files/micromamba_${OS_NAME}_${OS_ARCH}"
if [ -e "$INSTALL_ENV_DIR" ]; then export PATH="$PATH;$INSTALL_ENV_DIR/bin"; fi
# initialize micromamba
mkdir -p "$MAMBA_ROOT_PREFIX"
cp "$MICROMAMBA_BINARY_FILE" "$MAMBA_ROOT_PREFIX/micromamba"
# test the mamba binary
echo Micromamba version:
"$MAMBA_ROOT_PREFIX/micromamba" --version
# run the shell hook, otherwise activate will fail
eval "$($MAMBA_ROOT_PREFIX/micromamba shell hook -s posix)"
# figure out what needs to be installed
PACKAGES_TO_INSTALL=""
if ! hash "python" &>/dev/null; then PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL python"; fi
if ! hash "git" &>/dev/null; then PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL git"; fi
# install git and python into a contained environment (if necessary)
if [ "$PACKAGES_TO_INSTALL" != "" ]; then
echo "Packages to install: $PACKAGES_TO_INSTALL"
# install git and python into the installer env
if [ ! -e "$INSTALL_ENV_DIR" ]; then
micromamba create -y --prefix "$INSTALL_ENV_DIR"
fi
micromamba install -y --prefix "$INSTALL_ENV_DIR" -c conda-forge $PACKAGES_TO_INSTALL
# activate
micromamba activate "$INSTALL_ENV_DIR"
fi
# get the repo (and load into the current directory)
if [ ! -e ".git" ]; then
git init
git remote add origin https://github.com/cmdr2/InvokeAI.git
git fetch
git checkout origin/main -ft
fi
# create the environment
if [ "$OS_NAME" == "mac" ]; then
PIP_EXISTS_ACTION=w CONDA_SUBDIR=osx-arm64 micromamba create -f environment-mac.yml
else
micromamba create -f environment.yml
fi
micromamba activate invokeai
# preload the models
python scripts/preload_models.py
# make the models dir
mkdir -p models/ldm/stable-diffusion-v1

29
invoke.bat Normal file
View File

@ -0,0 +1,29 @@
@echo off
@rem prevent the window from closing after running the commands
if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit )
@rem check if conda exists, otherwise use micromamba
set CONDA_COMMAND=conda
call conda --version "" >tmp/stdout.txt 2>tmp/stderr.txt
if "%ERRORLEVEL%" NEQ "0" set CONDA_COMMAND=micromamba
@rem initialize micromamba, if using that
if "%CONDA_COMMAND%" EQU "micromamba" (
set MAMBA_ROOT_PREFIX=%cd%\installer_files\mamba
set INSTALL_ENV_DIR=%cd%\installer_files\env
if not exist "%MAMBA_ROOT_PREFIX%\condabin" (
echo "Have you run install.bat?"
exit /b
)
call "%MAMBA_ROOT_PREFIX%\condabin\mamba_hook.bat"
call micromamba activate "%INSTALL_ENV_DIR%"
)
call %CONDA_COMMAND% activate invokeai
pause

27
invoke.sh Normal file
View File

@ -0,0 +1,27 @@
#!/bin/bash
if [ "$0" == "bash" ]; then
# check if conda exists, otherwise use micromamba
CONDA_COMMAND="conda"
if ! hash "conda" &>/dev/null; then CONDA_COMMAND="micromamba"; fi
# initialize micromamba, if using that
if [ "$CONDA_COMMAND" == "micromamba" ]; then
export MAMBA_ROOT_PREFIX="$(pwd)/installer_files/mamba"
INSTALL_ENV_DIR="$(pwd)/installer_files/env"
if [ ! -e "$MAMBA_ROOT_PREFIX" ]; then
echo "Have you run install.sh?"
exit
fi
eval "$($MAMBA_ROOT_PREFIX/micromamba shell hook -s posix)"
micromamba activate "$INSTALL_ENV_DIR"
)
$CONDA_COMMAND activate invokeai
else
bash --init-file invoke.sh
fi

11
update.bat Normal file
View File

@ -0,0 +1,11 @@
@echo off
set INSTALL_ENV_DIR=%cd%\installer_files\env
set PATH=%PATH%;%INSTALL_ENV_DIR%;%INSTALL_ENV_DIR%\Library\bin;%INSTALL_ENV_DIR%\Scripts
@rem update the repo
if exist ".git" (
call git pull
)
pause

10
update.sh Normal file
View File

@ -0,0 +1,10 @@
#!/bin/bash
INSTALL_ENV_DIR="$(pwd)/installer_files/env"
if [ -e "$INSTALL_ENV_DIR" ]; then export PATH="$PATH;$INSTALL_ENV_DIR/bin"; fi
# update the repo
if [ -e ".git" ]; then
git pull
fi