diff --git a/Dockerfile b/Dockerfile index 61f77b2..f46fc04 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,81 @@ -FROM python:3.8-slim +FROM lsiobase/python:3.11 -WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y build-essential libcurl4-openssl-dev libssl-dev -COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt +# set version release +ARG WHOOGLESEARCH_RELEASE +ARG BUILD_DATE=unspecified +ARG VCS_REF=unspecified -ARG config_dir=/config -RUN mkdir -p $config_dir -VOLUME $config_dir -ENV CONFIG_VOLUME=$config_dir +# set python to use utf-8 rather than ascii. +ENV PYTHONIOENCODING="UTF-8" + +# enforced https, default false +ARG use_https='' +ENV HTTPS_ONLY="$use_https" ARG username='' ENV WHOOGLE_USER=$username ARG password='' ENV WHOOGLE_PASS=$password -ARG use_https='' -ENV HTTPS_ONLY=$use_https +# set config volume +ARG config_dir=/config +RUN mkdir -p $config_dir +VOLUME $config_dir +ENV CONFIG_VOLUME=$config_dir +LABEL org.label-schema.name="Whoogle Search" +LABEL org.label-schema.description="Self-hosted, ad-free, privacy-respecting Google metasearch engine" +LABEL org.label-schema.vcs-url="https://github.com/benbusby/whoogle-search" +LABEL org.label-schema.build-date="${BUILD_DATE}" +LABEL org.label-schema.vcs-ref="${VCS_REF}" + +RUN \ + echo "**** install build packages ****" && \ + apk add --no-cache --upgrade --virtual .build-dependencies \ + g++ \ + git \ + curl-dev \ + libressl-dev \ + libxml2-dev \ + libxslt-dev \ + libffi-dev \ + python3-dev && \ + echo "**** install runtime packages ****" && \ + apk add --no-cache --upgrade \ + curl \ + py3-pip \ + python3 \ + tar && \ + echo "**** install app ****" && \ + mkdir -p \ + /tmp/whooglesearch && \ + if [ -z ${WHOOGLESEARCH_RELEASE+x} ]; then \ + WHOOGLESEARCH_RELEASE=$(curl -sX GET "https://api.github.com/repos/benbusby/whoogle-search/commits/master" \ + | awk '/sha/{print $4;exit}' FS='[""]'); \ + fi && \ + curl -o \ + /tmp/whooglesearch.tar.gz -L \ + "https://github.com/benbusby/whoogle-search/archive/${WHOOGLESEARCH_RELEASE}.tar.gz" && \ + tar xf \ + /tmp/whooglesearch.tar.gz -C \ + /tmp/whooglesearch --strip-components=1 && \ + echo "**** install pip packages ****" && \ + pip3 install --no-cache-dir -r \ + /tmp/whooglesearch/requirements.txt && \ + cp -r /tmp/whooglesearch/app / && \ + echo "**** clean up ****" && \ + apk del --purge \ + .build-dependencies && \ + rm -rf \ + /tmp/* + +# set config location +ENV CONFIG_VOLUME="/config" + +# add local files +COPY root/ / + +# search port ARG whoogle_port=5000 ENV EXPOSE_PORT=$whoogle_port - -COPY . . - EXPOSE $EXPOSE_PORT - -CMD ["./run"] diff --git a/Dockerfile.aarch64 b/Dockerfile.aarch64 new file mode 100644 index 0000000..f41fc61 --- /dev/null +++ b/Dockerfile.aarch64 @@ -0,0 +1,69 @@ +FROM lsiobase/python:arm64v8-3.11 + +# set version release +ARG WHOOGLESEARCH_RELEASE +ARG BUILD_DATE=unspecified +ARG VCS_REF=unspecified + +# set python to use utf-8 rather than ascii. +ENV PYTHONIOENCODING="UTF-8" + +# enforced https, default false +ARG use_https='' +ENV HTTPS_ONLY="$use_https" + +LABEL org.label-schema.name="Whoogle Search" +LABEL org.label-schema.description="Self-hosted, ad-free, privacy-respecting Google metasearch engine" +LABEL org.label-schema.vcs-url="https://github.com/benbusby/whoogle-search" +LABEL org.label-schema.build-date="${BUILD_DATE}" +LABEL org.label-schema.vcs-ref="${VCS_REF}" + +RUN \ + echo "**** install build packages ****" && \ + apk add --no-cache --upgrade --virtual .build-dependencies \ + g++ \ + git \ + curl-dev \ + libressl-dev \ + libxml2-dev \ + libxslt-dev \ + libffi-dev \ + python3-dev && \ + echo "**** install runtime packages ****" && \ + apk add --no-cache --upgrade \ + curl \ + py3-pip \ + python3 \ + tar && \ + echo "**** install app ****" && \ + mkdir -p \ + /tmp/whooglesearch && \ + if [ -z ${WHOOGLESEARCH_RELEASE+x} ]; then \ + WHOOGLESEARCH_RELEASE=$(curl -sX GET "https://api.github.com/repos/benbusby/whoogle-search/commits/master" \ + | awk '/sha/{print $4;exit}' FS='[""]'); \ + fi && \ + curl -o \ + /tmp/whooglesearch.tar.gz -L \ + "https://github.com/benbusby/whoogle-search/archive/${WHOOGLESEARCH_RELEASE}.tar.gz" && \ + tar xf \ + /tmp/whooglesearch.tar.gz -C \ + /tmp/whooglesearch --strip-components=1 && \ + echo "**** install pip packages ****" && \ + pip3 install --no-cache-dir -r \ + /tmp/whooglesearch/requirements.txt && \ + cp -r /tmp/whooglesearch/app / && \ + echo "**** clean up ****" && \ + apk del --purge \ + .build-dependencies && \ + rm -rf \ + /tmp/* + +# set config location +ENV CONFIG_VOLUME="/config" + +# add local files +COPY root/ / + +# ports and volumes +EXPOSE 5000 +VOLUME /config diff --git a/Dockerfile.armhf b/Dockerfile.armhf new file mode 100644 index 0000000..cb97390 --- /dev/null +++ b/Dockerfile.armhf @@ -0,0 +1,69 @@ +FROM lsiobase/python:arm32v7-3.11 + +# set version release +ARG WHOOGLESEARCH_RELEASE +ARG BUILD_DATE=unspecified +ARG VCS_REF=unspecified + +# set python to use utf-8 rather than ascii. +ENV PYTHONIOENCODING="UTF-8" + +# enforced https, default false +ARG use_https='' +ENV HTTPS_ONLY="$use_https" + +LABEL org.label-schema.name="Whoogle Search" +LABEL org.label-schema.description="Self-hosted, ad-free, privacy-respecting Google metasearch engine" +LABEL org.label-schema.vcs-url="https://github.com/benbusby/whoogle-search" +LABEL org.label-schema.build-date="${BUILD_DATE}" +LABEL org.label-schema.vcs-ref="${VCS_REF}" + +RUN \ + echo "**** install build packages ****" && \ + apk add --no-cache --upgrade --virtual .build-dependencies \ + g++ \ + git \ + curl-dev \ + libressl-dev \ + libxml2-dev \ + libxslt-dev \ + libffi-dev \ + python3-dev && \ + echo "**** install runtime packages ****" && \ + apk add --no-cache --upgrade \ + curl \ + py3-pip \ + python3 \ + tar && \ + echo "**** install app ****" && \ + mkdir -p \ + /tmp/whooglesearch && \ + if [ -z ${WHOOGLESEARCH_RELEASE+x} ]; then \ + WHOOGLESEARCH_RELEASE=$(curl -sX GET "https://api.github.com/repos/benbusby/whoogle-search/commits/master" \ + | awk '/sha/{print $4;exit}' FS='[""]'); \ + fi && \ + curl -o \ + /tmp/whooglesearch.tar.gz -L \ + "https://github.com/benbusby/whoogle-search/archive/${WHOOGLESEARCH_RELEASE}.tar.gz" && \ + tar xf \ + /tmp/whooglesearch.tar.gz -C \ + /tmp/whooglesearch --strip-components=1 && \ + echo "**** install pip packages ****" && \ + pip3 install --no-cache-dir -r \ + /tmp/whooglesearch/requirements.txt && \ + cp -r /tmp/whooglesearch/app / && \ + echo "**** clean up ****" && \ + apk del --purge \ + .build-dependencies && \ + rm -rf \ + /tmp/* + +# set config location +ENV CONFIG_VOLUME="/config" + +# add local files +COPY root/ / + +# ports and volumes +EXPOSE 5000 +VOLUME /config diff --git a/README.md b/README.md index ecf4a96..b0f9936 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,36 @@ docker run --publish 5000:5000 --detach --name whoogle-search whoogle-search:1.0 And kill with: `docker rm --force whoogle-search` +#### Docker-Compose + +```bash +version: "3" +services: + whoogle-search: + container_name: whoogle-search + hostname: whoogle-search + image: "benbusby/whoogle-search" + restart: always + ports: + - "5000:5000" + environment: + - PUID=1000 + - PGID=1000 + - TZ=Europe/London + - WEB_PORT=5000 #optional default 5000 +``` + +#### Docker Parameters + +Container images are configured using parameters passed at runtime (such as those above). These parameters are separated by a colon and indicate `:` respectively. For example, `-p 8080:80` would expose port `80` from inside the container to be accessible from the host's IP on port `8080` outside the container. + +| Parameter | Function | +| :----: | --- | +| `-e PUID=1000` | for UserID | +| `-e PGID=1000` | for GroupID | +| `-e TZ=Europe/London` | Specify a timezone to use | +| `-e WEB_PORT=5000` | set the server port to expose, default to 5000, **optional** | + #### Using [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli) ```bash heroku login diff --git a/docker-compose.yml b/docker-compose.yml index 479b7f3..90ae719 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,25 @@ version: "3" services: - whoogle-search: - image: benbusby/whoogle-search - container_name: whoogle-search - ports: - - 5000:5000 - restart: unless-stopped +# ---------------------------------------- + whoogle-search: + container_name: whoogle-search + hostname: whoogle-search + # Uncomment to build from local + # build: + # dockerfile: Dockerfile + # context: . + # image: "whoogle-search" + image: "benbusby/whoogle-search" + restart: always + ports: + - "5000:5000" + volumes: + - path/to/config:/config + environment: + - PUID=${PUID} # User uid + - PGID=${PGID} # User gid + - TZ=${TZ} # TimeZone + - EXPOSE_PORT=5000 # Default port 5000 + - USER= # Optional + - PASSWORD= # Optional diff --git a/root/etc/cont-init.d/30-config b/root/etc/cont-init.d/30-config new file mode 100644 index 0000000..8fceb11 --- /dev/null +++ b/root/etc/cont-init.d/30-config @@ -0,0 +1,11 @@ +#!/usr/bin/with-contenv bash + +# make needed folder +mkdir -p \ + /config/ + +# permissions +chown -R abc:abc \ + /app +chown -R abc:abc \ + /config diff --git a/root/etc/services.d/whooglesearch/run b/root/etc/services.d/whooglesearch/run new file mode 100644 index 0000000..59b5aa8 --- /dev/null +++ b/root/etc/services.d/whooglesearch/run @@ -0,0 +1,19 @@ +#!/usr/bin/with-contenv bash + +ADDRESS=${ADDRESS:-0.0.0.0} +EXPOSE_PORT=${EXPOSE_PORT:-5000} +USER=${USER} +PASSWORD=${PASSWORD} + +cd / + +# Create User Authentication if specified +if [ -z "${USER}" ] && [ -z "${PASSWORD}" ]; then + echo "No User and Password Will be set for Basic authentication" + exec \ + s6-setuidgid abc python3 -um app --host "${ADDRESS}" --port "${EXPOSE_PORT}" +else + echo "Setting Up Basic Authentication with Username="$USER" Password="$PASSWORD"" + exec \ + s6-setuidgid abc python3 -um app --host "${ADDRESS}" --port "${EXPOSE_PORT}" --userpass "$USER":"$PASSWORD" +fi