From 20580bcbd458fa18c13bb9c1a32466ee5af48f97 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Sat, 24 Apr 2021 08:53:12 +0200 Subject: [PATCH] [docker] multiarch support: linux/amd64,linux/arm64,linux/arm/v7 make docker.buildx : build and push multiarch build. (it can't be only build) use buildx with the --cache-from and --cache-to options to cache the layers (only the last built is cached) --- .github/workflows/integration.yml | 2 +- Dockerfile | 6 +++--- Makefile | 2 +- docs/admin/installation-docker.rst | 16 ++++++++-------- manage | 27 +++++++++++++++++++++------ 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 0068c3964..914ce163f 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -121,4 +121,4 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push if: env.DOCKERHUB_USERNAME != null - run: make -e GIT_URL=$(git remote get-url origin) docker.push + run: make -e GIT_URL=$(git remote get-url origin) docker.buildx diff --git a/Dockerfile b/Dockerfile index 3fbf62f35..477cdb1ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -73,18 +73,18 @@ ARG GIT_URL=unknown ARG SEARX_GIT_VERSION=unknown ARG LABEL_VCS_REF= ARG LABEL_VCS_URL= -LABEL maintainer="searx <${GIT_URL}>" \ +LABEL maintainer="searxng <${GIT_URL}>" \ description="A privacy-respecting, hackable metasearch engine." \ version="${SEARX_GIT_VERSION}" \ org.label-schema.schema-version="1.0" \ - org.label-schema.name="searx" \ + org.label-schema.name="searxng" \ org.label-schema.version="${SEARX_GIT_VERSION}" \ org.label-schema.url="${LABEL_VCS_URL}" \ org.label-schema.vcs-ref=${LABEL_VCS_REF} \ org.label-schema.vcs-url=${LABEL_VCS_URL} \ org.label-schema.build-date="${LABEL_DATE}" \ org.label-schema.usage="https://github.com/searx/searx-docker" \ - org.opencontainers.image.title="searx" \ + org.opencontainers.image.title="searxng" \ org.opencontainers.image.version="${SEARX_GIT_VERSION}" \ org.opencontainers.image.url="${LABEL_VCS_URL}" \ org.opencontainers.image.revision=${LABEL_VCS_REF} \ diff --git a/Makefile b/Makefile index 66008d33e..2d760c496 100644 --- a/Makefile +++ b/Makefile @@ -73,7 +73,7 @@ MANAGE += buildenv MANAGE += babel.compile MANAGE += data.all data.languages data.useragents MANAGE += docs.html docs.live docs.gh-pages docs.prebuild docs.clean -MANAGE += docker.build docker.push +MANAGE += docker.build docker.push docker.buildx MANAGE += gecko.driver MANAGE += node.env node.clean MANAGE += py.build py.clean diff --git a/docs/admin/installation-docker.rst b/docs/admin/installation-docker.rst index 13d21bc46..120c9cb08 100644 --- a/docs/admin/installation-docker.rst +++ b/docs/admin/installation-docker.rst @@ -11,19 +11,19 @@ Docker installation ---- -Docker image searx/searx -======================== +Docker image searxng/searxng +============================ -The docker image is `searx/searx `_ (based on `github.com/searx/searx `_). +The docker image is `searxng/searxng `_ (based on `github.com/searxng/searxng `_). Make sure you have `installed Docker `_. For instance, you can deploy a local instance: .. code:: sh export PORT=80 - docker pull searx/searx - docker run --rm -d -v ${PWD}/searx:/etc/searx -p $PORT:8080 -e BASE_URL=http://localhost:$PORT/ searx/searx + docker pull searxng/searxng + docker run --rm -d -v ${PWD}/searx:/etc/searx -p $PORT:8080 -e BASE_URL=http://localhost:$PORT/ searxng/searxng Go to ``http://localhost:$PORT``. @@ -37,7 +37,7 @@ Command line .. code:: sh - docker run --rm -it searx/searx -h + docker run --rm -it searxng/searxng -h .. program-output:: ../dockerfiles/docker-entrypoint.sh help @@ -45,11 +45,11 @@ Command line Build the image --------------- -It's also possible to build searx from the embedded Dockerfile. +It's also possible to build SearXNG from the embedded Dockerfile. .. code:: sh - git clone https://github.com/searx/searx.git + git clone https://github.com/searxng/searxng.git cd searx make docker.build diff --git a/manage b/manage index 3ff1a6f88..3282cc645 100755 --- a/manage +++ b/manage @@ -152,6 +152,10 @@ docker.push() { docker.build push } +docker.buildx() { + docker.build buildx +} + # shellcheck disable=SC2119 docker.build() { pyenv.install @@ -210,23 +214,34 @@ docker.build() { GITHUB_USER=$(echo "${GIT_URL}" | sed 's/.*github\.com\/\([^\/]*\).*/\1/') SEARX_IMAGE_NAME="${SEARX_IMAGE_NAME:-${GITHUB_USER:-searxng}/searxng}" + BUILD="build" + if [ "$1" = "buildx" ]; then + # buildx includes the push option + CACHE_TAG="${SEARX_IMAGE_NAME}:latest-build-cache" + BUILD="buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 --push --cache-from=type=registry,ref=$CACHE_TAG --cache-to=type=registry,ref=$CACHE_TAG,mode=max" + shift + fi + build_msg DOCKER "Build command: ${BUILD}" + # build Docker image build_msg DOCKER "Building image ${SEARX_IMAGE_NAME}:${SEARX_GIT_VERSION}" - sudo docker build \ + # shellcheck disable=SC2086 + docker $BUILD \ + --build-arg BASE_IMAGE="${DEPENDENCIES_IMAGE_NAME}" \ --build-arg GIT_URL="${GIT_URL}" \ --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_URL}" \ - --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)" \ + --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 + docker push "${SEARX_IMAGE_NAME}:latest" + docker push "${SEARX_IMAGE_NAME}:${SEARX_GIT_VERSION}" + fi ) dump_return $? }