From fbe40001d35ea5cf74c92f35d76c642a480a5c9f Mon Sep 17 00:00:00 2001 From: Dalf Date: Sat, 29 Jun 2019 11:59:13 +0200 Subject: Update Docker image See #1561 , use uwsgi and Alpine Linux Volume: /var/log/uwsgi contains error log for 2 days (file uwsgi.log) /etc/searx contains the settings.yml and uwsgi.ini files. The docker image creates them if they don't exist. The two files can be modified after the first run. See below. Environement variables: MORTY_URL : external URL of Morty MORTY_KEY : base64 encoded key BASE_URL : external URL of Searx BIND_ADDRESS : internal HTTP port to listen to Labels : org.label-schema.schema.* Parameters: -h : display this help -d : will update the settings and quit immediately (settings.yml and uwsgi.ini) -f : always update the settings (previous version saved with suffix .old). without this parameter, the new settings are copied with suffix .new When the Docker image contains newer settings: - without -f parameter: the new versions are copied to /etc/searx/settings.yml.new and /etc/searx/uwsgi.ini.new. - with -f parameter: the old versions are renamed with .old suffix. The new version replaces /etc/searx/settings.yml and /etc/searx/uwsgi.ini Build using "./manage.sh docker_build", add "push" as parameter also push the Docker image. The script requires a git repository to work (it makes sure that the last git tag matches searx/version.py) "git describe" is used to create a meaningful version. Example : 0.15.0-90-49c5bcb4-dirty (dirty means that the docker image was made with uncommited changes). Use "docker inspect -f {{.Config.Labels.version}} searx" to get the version of an existing image. .dockerignore based on .gitignore .travis.yml: include docker stage --- manage.sh | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'manage.sh') diff --git a/manage.sh b/manage.sh index c564827ac..7279eaf39 100755 --- a/manage.sh +++ b/manage.sh @@ -158,6 +158,74 @@ grunt_build() { grunt --gruntfile "$SEARX_DIR/static/themes/simple/gruntfile.js" } +docker_build() { + # Check if it is a git repository + if [ ! -d .git ]; then + echo "This is not Git repository" + exit 1 + fi + + if [ ! -x "$(which git)" ]; then + echo "git is not installed" + exit 1 + fi + + if [ ! git remote get-url origin 2> /dev/null ]; then + echo "there is no remote origin" + exit 1 + fi + + # This is a git repository + + # "git describe" to get the Docker version (for example : v0.15.0-89-g0585788e) + # awk to remove the "v" and the "g" + SEARX_GIT_VERSION=$(git describe --match "v[0-9]*\.[0-9]*\.[0-9]*" HEAD 2>/dev/null | awk -F'-' '{OFS="-"; $1=substr($1, 2); $3=substr($3, 2); print}') + + # add the suffix "-dirty" if the repository has uncommited change + git update-index -q --refresh + if [ ! -z "$(git diff-index --name-only HEAD --)" ]; then + SEARX_GIT_VERSION="${SEARX_GIT_VERSION}-dirty" + fi + + # Get the last git commit id, will be added to the Searx version (see Dockerfile) + VERSION_GITCOMMIT=$(echo $SEARX_GIT_VERSION | cut -d- -f2-4) + echo "Last commit : $VERSION_GITCOMMIT" + + # Check consistency between the git tag and the searx/version.py file + # /!\ HACK : parse Python file with bash /!\ + # otherwise it is not possible build the docker image without all Python dependencies ( version.py loads __init__.py ) + # SEARX_PYTHON_VERSION=$(python -c "import six; import searx.version; six.print_(searx.version.VERSION_STRING)") + SEARX_PYTHON_VERSION=$(cat searx/version.py | grep "\(VERSION_MAJOR\|VERSION_MINOR\|VERSION_BUILD\) =" | cut -d\= -f2 | sed -e 's/^[[:space:]]*//' | paste -sd "." -) + if [ $(echo "$SEARX_GIT_VERSION" | cut -d- -f1) != "$SEARX_PYTHON_VERSION" ]; then + echo "Inconsistency between the last git tag and the searx/version.py file" + echo "git tag: $SEARX_GIT_VERSION" + echo "searx/version.py: $SEARX_PYTHON_VERSION" + exit 1 + fi + + # define the docker image name + # /!\ HACK to get the user name /!\ + GITHUB_USER=$(git remote get-url origin | sed 's/.*github\.com\/\([^\/]*\).*/\1/') + SEARX_IMAGE_NAME="${GITHUB_USER:-searx}/searx" + + # build Docker image + echo "Building image ${SEARX_IMAGE_NAME}:${SEARX_GIT_VERSION}" + sudo docker build \ + --build-arg SEARX_GIT_VERSION="${SEARX_GIT_VERSION}" \ + --build-arg VERSION_GITCOMMIT="${VERSION_GITCOMMIT}" \ + --build-arg LABEL_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \ + --build-arg LABEL_VCS_REF=$(git rev-parse HEAD) \ + --build-arg LABEL_VCS_URL=$(git remote get-url origin) \ + --build-arg TIMESTAMP_SETTINGS=$(git log -1 --format="%cd" --date=unix -- searx/settings.yml) \ + --build-arg TIMESTAMP_UWSGI=$(git log -1 --format="%cd" --date=unix -- dockerfiles/uwsgi.ini) \ + -t ${SEARX_IMAGE_NAME}:latest -t ${SEARX_IMAGE_NAME}:${SEARX_GIT_VERSION} . + + if [ "$1" = "push" ]; then + sudo docker push ${SEARX_IMAGE_NAME}:latest + sudo docker push ${SEARX_IMAGE_NAME}:${SEARX_GIT_VERSION} + fi +} + # # Help # @@ -182,6 +250,7 @@ Commands locales - Compile locales styles - Build less files grunt_build - Build files for themes + docker_build - Build Docker image Tests ----- -- cgit v1.2.3-54-g00ecf