見出し画像

SearXNGをCloudRunでホスティングする

Assistant APIなどのFunction callingで検索を試す際に、SearXNGを気軽に動かせると嬉しいので。

ファイルを準備する

Dockerfile

FROM searxng/searxng:latest

ENV SEARXNG_BASE_URL=https://${SEARXNG_HOSTNAME:-localhost}/

COPY settings.yml /etc/searxng/settings.yml

CMD ["python3", "-m", "searx.webapp"]

settings.yml

  • リクエストリミットの設定なし

    • 正式に運用する場合はちゃんと考えたほうがよさそう。デフォルトだと結構厳しめのリミットになるのでここでは外している

  • 検索にHTML, JSONをサポート

    • 公開インスタンスはJSONサポートしてるケース少ない。Function Callingでの検索だとJSON APIがあると嬉しい。

  • redisはdisabled

    • なくても動く。使う場合はMemorystoreなどを用いることになりそう。

# see https://docs.searxng.org/admin/settings/settings.html#settings-use-default-settings
use_default_settings: true
server:
  # base_url is defined in the SEARXNG_BASE_URL environment variable, see .env and docker-compose.yml
  secret_key: ultrasecretkey # change this!
  limiter: false  # can be disabled for a private instance
  image_proxy: true
ui:
  static_use_hash: true
# redis:
#   url: redis://redis:6379/0
search:
  formats:
    - html
    - json

secret_keyを生成する必要があるので、以下のコマンドで生成して置き換える。

sed -i "s|ultrasecretkey|$(openssl rand -hex 32)|g" searxng/settings.yml

ビルドする

[PROJECT-ID]の部分を実際に利用するGoogle CloudのProject IDにする。

docker build -t gcr.io/[PROJECT-ID]/searxng --platform linux/x86_64 .

Artifact Registryにpushする

docker push gcr.io/[PROJECT-ID]/searxng

Cloud Runにデプロイする

REGIONは'asia-northeast1'とかでよさそう

gcloud run deploy searxng \
  --image gcr.io/[PROJECT-ID]/searxng \
  --platform managed \
  --region [REGION] \ 
  --allow-unauthenticated
動いた
Cloud Runの検索結果

Localで動かす

開発時はlocalで十分なので。

docker run -p 8080:8080 gcr.io/[PROJECT-ID]/searxng

http:localhost:8080 で動作する。

docker-composeで動くものもあるのでそっちが手っ取り早いかも。https://github.com/searxng/searxng-docker


この記事が気に入ったらサポートをしてみませんか?