Skip to content

Commit 1549eb0

Browse files
authored
add searxng (#27)
* init searxng * debug searxng * debug permission issue * debug docker img * update docs
1 parent 5fff32b commit 1549eb0

14 files changed

+575
-2
lines changed

.github/workflows/build-docker.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ on:
44
push:
55
branches: [ "main" ]
66
paths-ignore: [ "*.md" ]
7-
87
pull_request:
98
branches: [ "main" ]
109
paths-ignore: [ "*.md" ]
11-
1210
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab
1311

12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
14+
cancel-in-progress: true
1415

1516
env:
1617
BUILDKIT_PROGRESS: "plain" # Full logs for CI build.
@@ -73,6 +74,16 @@ jobs:
7374
- run: |
7475
source ./tool.sh && build_image openresty latest docker_openresty/Dockerfile && push_image
7576
77+
## OpenResty as gateway
78+
qpod_searxng:
79+
name: 'searxng'
80+
runs-on: ubuntu-latest
81+
steps:
82+
- uses: actions/checkout@v4
83+
- run: |
84+
source ./tool.sh && build_image searxng latest docker_searxng/searxng.Dockerfile && push_image
85+
86+
7687
## DevBox - base
7788
qpod_base-dev:
7889
name: 'developer,base-dev'

docker_devbox/work/start-caddy.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
[ $BASH ] && [ -f /etc/profile ] && [ -z $ENTER_PROFILE ] && . /etc/profile
3+
4+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
6+
URL_PREFIX=${JUPYTERHUB_SERVICE_PREFIX:-"/"} exec /usr/local/bin/caddy run --config /etc/caddy/Caddyfile
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
[ $BASH ] && [ -f /etc/profile ] && [ -z $ENTER_PROFILE ] && . /etc/profile
3+
4+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
6+
LOG_FORMAT=json exec supervisord -c /etc/supervisord/supervisord.conf

docker_searxng/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SearxNG
2+
3+
## Start standalone version with docker-compose
4+
5+
**Notice**: remember to check the `SEARXNG_BASE_URL` and `SEARXNG_HOSTNAME` environment variable in the config file.
6+
7+
Make sure the `SEARXNG_BASE_URL` variables points to a URL prefix that users use to open webpage in browser.
8+
9+
```bash
10+
cd demo
11+
12+
# export SEARXNG_HOSTNAME="http://localhost:81"
13+
docker-compose -f ./docker-compose.searxng-standalone.yml up -d
14+
```
15+
16+
## Debug with Docker
17+
18+
```bash
19+
docker run -d --rm \
20+
--name=svc-searxng \
21+
--hostname=svc-searxng \
22+
-p 8000:8000 \
23+
-e SEARXNG_HOSTNAME=":8000" \
24+
-e SEARXNG_BASE_URL=https://${localhost:8000}/ \
25+
-e UWSGI_WORKERS=${SEARXNG_UWSGI_WORKERS:-4} \
26+
-e UWSGI_THREADS=${SEARXNG_UWSGI_THREADS:-4} \
27+
qpod/searxng
28+
29+
docker exec -it svc-searxng bash
30+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
networks:
2+
net-searxng:
3+
4+
services:
5+
svc-searxng:
6+
container_name: svc-searxng
7+
image: docker.io/qpod/searxng:latest
8+
restart: unless-stopped
9+
networks:
10+
- net-searxng
11+
ports:
12+
- "8000:8000"
13+
# volumes:
14+
# - ./searxng/settings.yml:/etc/searxng/settings.yml:rw
15+
# - ./searxng/limiter.toml:/etc/searxng/limiter.toml:rw
16+
# - ./searxng/Caddyfile:/etc/searxng/Caddyfile:rw
17+
# - ./searxng/supervisord.conf:/etc/searxng/supervisord.conf:rw
18+
environment:
19+
- SEARXNG_BASE_URL=https://${SEARXNG_HOSTNAME:-localhost:8000}/
20+
- SEARXNG_HOSTNAME=${SEARXNG_HOSTNAME:-http://localhost:8000}
21+
- SEARXNG_TLS=${LETSENCRYPT_EMAIL:-internal}
22+
- UWSGI_WORKERS=${SEARXNG_UWSGI_WORKERS:-4}
23+
- UWSGI_THREADS=${SEARXNG_UWSGI_THREADS:-4}
24+
# user: root
25+
# command: ["/opt/searxng/start-supervisord.sh"]
26+
# command: ["tail", "-f", "/dev/null"]
27+
# cap_drop: ["ALL"]
28+
# cap_add: ["AUDIT_WRITE", "CHOWN", "SETGID", "SETUID", "NET_BIND_SERVICE"]
29+
logging:
30+
driver: "json-file"
31+
options:
32+
max-size: "1m"
33+
max-file: "1"

docker_searxng/searxng.Dockerfile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Distributed under the terms of the Modified BSD License.
2+
3+
ARG BASE_NAMESPACE
4+
ARG BASE_IMG="base"
5+
6+
FROM ${BASE_NAMESPACE:+$BASE_NAMESPACE/}${BASE_IMG}
7+
8+
COPY work /tmp/searxng
9+
10+
RUN set -eux \
11+
&& SEARXNG_GID=977 && SEARXNG_UID=977 \
12+
&& addgroup -gid ${SEARXNG_GID} searxng \
13+
&& adduser -uid ${SEARXNG_UID} --disabled-password --home /opt/searxng -shell /bin/bash --ingroup searxng searxng \
14+
&& usermod -aG root searxng \
15+
&& apt-get -qq update -yq --fix-missing && apt-get -qq install -yq --no-install-recommends \
16+
libxslt-dev zlib1g-dev libffi-dev libssl-dev \
17+
&& pip install -U pyyaml uwsgi \
18+
&& cd /opt/searxng \
19+
&& git config --global --add safe.directory /opt/searxng \
20+
&& git init && git remote add origin https://github.com/searxng/searxng \
21+
&& git fetch && git checkout -t origin/master \
22+
&& pip install --use-pep517 --no-build-isolation -e . \
23+
&& mv /tmp/searxng/* /opt/searxng && ln -sf /opt/searxng/etc /etc/searxng \
24+
&& ln -sf /opt/searxng /usr/local/ \
25+
# ----------------------------- Install supervisord
26+
&& source /opt/utils/script-setup-sys.sh && setup_supervisord \
27+
# ----------------------------- Install caddy
28+
&& source /opt/utils/script-setup-net.sh && setup_caddy \
29+
# Clean up and display components version information...
30+
&& fix_permission searxng /opt/searxng/ \
31+
&& chmod +x /opt/searxng/*.sh \
32+
&& chmod -R ugo+rws /var/log /var/run \
33+
&& list_installed_packages && install__clean
34+
35+
ENV SEARXNG_HOSTNAME="http://localhost:8000"
36+
ENV SEARXNG_TLS=internal
37+
38+
ENV SEARXNG_BASE_URL=https://${SEARXNG_HOSTNAME:-localhost}/
39+
ENV SEARXNG_SETTINGS_PATH="/etc/searxng/settings.yml"
40+
ENV UWSGI_SETTINGS_PATH="/opt/searxng/dockerfiles/uwsgi.ini"
41+
ENV UWSGI_WORKERS=4
42+
ENV UWSGI_THREADS=4
43+
44+
ENTRYPOINT ["tini", "-g", "--"]
45+
46+
# '-c' option make bash commands are read from string.
47+
# If there are arguments after the string, they are assigned to the positional parameters, starting with $0.
48+
# '-o pipefail' prevents errors in a pipeline from being masked.
49+
# If any command in a pipeline fails, that return code will be used as the return code of the whole pipeline.
50+
# '--login': make bash first reads and executes commands from the file /etc/profile, if that file exists.
51+
# After that, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.
52+
SHELL ["/bin/bash", "--login", "-o", "pipefail", "-c"]
53+
WORKDIR /opt/searxng
54+
CMD ["/opt/searxng/start-supervisord.sh"]
55+
EXPOSE 8080 9001 8000

docker_searxng/work/etc/Caddyfile

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# ref: https://github.com/searxng/searxng-docker/blob/master/Caddyfile
2+
{
3+
admin off
4+
}
5+
6+
{$SEARXNG_HOSTNAME} {
7+
log {
8+
output discard
9+
}
10+
11+
# tls {$SEARXNG_TLS}
12+
13+
@api {
14+
path /config
15+
path /healthz
16+
path /stats/errors
17+
path /stats/checker
18+
}
19+
20+
@static {
21+
path /static/*
22+
}
23+
24+
@notstatic {
25+
not path /static/*
26+
}
27+
28+
@imageproxy {
29+
path /image_proxy
30+
}
31+
32+
@notimageproxy {
33+
not path /image_proxy
34+
}
35+
36+
header {
37+
# Enable HTTP Strict Transport Security (HSTS) to force clients to always connect via HTTPS
38+
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
39+
40+
# Enable cross-site filter (XSS) and tell browser to block detected attacks
41+
X-XSS-Protection "1; mode=block"
42+
43+
# Prevent some browsers from MIME-sniffing a response away from the declared Content-Type
44+
X-Content-Type-Options "nosniff"
45+
46+
# Disable some features
47+
Permissions-Policy "accelerometer=(),ambient-light-sensor=(),autoplay=(),camera=(),encrypted-media=(),focus-without-user-activation=(),geolocation=(),gyroscope=(),magnetometer=(),microphone=(),midi=(),payment=(),picture-in-picture=(),speaker=(),sync-xhr=(),usb=(),vr=()"
48+
49+
# Disable some features (legacy)
50+
Feature-Policy "accelerometer 'none';ambient-light-sensor 'none'; autoplay 'none';camera 'none';encrypted-media 'none';focus-without-user-activation 'none'; geolocation 'none';gyroscope 'none';magnetometer 'none';microphone 'none';midi 'none';payment 'none';picture-in-picture 'none'; speaker 'none';sync-xhr 'none';usb 'none';vr 'none'"
51+
52+
# Referer
53+
Referrer-Policy "no-referrer"
54+
55+
# X-Robots-Tag
56+
X-Robots-Tag "noindex, noarchive, nofollow"
57+
58+
# Remove Server header
59+
-Server
60+
}
61+
62+
header @api {
63+
Access-Control-Allow-Methods "GET, OPTIONS"
64+
Access-Control-Allow-Origin "*"
65+
}
66+
67+
# Cache
68+
header @static {
69+
# Cache
70+
Cache-Control "public, max-age=31536000"
71+
defer
72+
}
73+
74+
header @notstatic {
75+
# No Cache
76+
Cache-Control "no-cache, no-store"
77+
Pragma "no-cache"
78+
}
79+
80+
# CSP (see http://content-security-policy.com/ )
81+
header @imageproxy {
82+
Content-Security-Policy "default-src 'none'; img-src 'self' data:"
83+
}
84+
85+
header @notimageproxy {
86+
Content-Security-Policy "upgrade-insecure-requests; default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; form-action 'self' https://github.com/searxng/searxng/issues/new; font-src 'self'; frame-ancestors 'self'; base-uri 'self'; connect-src 'self' https://overpass-api.de; img-src 'self' data: https://*.tile.openstreetmap.org; frame-src https://www.youtube-nocookie.com https://player.vimeo.com https://www.dailymotion.com https://www.deezer.com https://www.mixcloud.com https://w.soundcloud.com https://embed.spotify.com"
87+
}
88+
89+
# SearXNG
90+
handle {
91+
encode zstd gzip
92+
93+
reverse_proxy localhost:8080 {
94+
header_up X-Forwarded-Port {http.request.port}
95+
header_up X-Forwarded-Proto {http.request.scheme}
96+
header_up X-Real-IP {remote_host}
97+
}
98+
}
99+
100+
}

docker_searxng/work/etc/limiter.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This configuration file updates the default configuration file
2+
# See https://github.com/searxng/searxng/blob/master/searx/limiter.toml
3+
4+
[botdetection.ip_limit]
5+
# activate link_token method in the ip_limit method
6+
link_token = true

docker_searxng/work/etc/settings.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# see https://docs.searxng.org/admin/settings/settings.html#settings-use-default-settings
2+
use_default_settings: true
3+
server:
4+
# base_url is defined in the SEARXNG_BASE_URL environment variable, see .env and docker-compose.yml
5+
secret_key: "ultrasecretkey" # change this!
6+
image_proxy: true
7+
limiter: false # can be disabled for a private instance, requires redis when enabled
8+
ui:
9+
static_use_hash: true
10+
# redis:
11+
# url: redis://redis:6379/0

0 commit comments

Comments
 (0)