Installing Elasticsearch on Fly.io

Hiya

I’m pretty new to this so please explain like i’m 5!

I’ve got a docker file with this inside:

# install Elasticsearch
RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - && \
    echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-7.x.list && \
    apt-get update && \
    apt-get install -y elasticsearch

# copy Elasticsearch configuration files
COPY elasticsearch.yml /etc/elasticsearch/elasticsearch.yml
COPY jvm.options /etc/elasticsearch/jvm.options

However when running fly deploy I’m getting this issue:

Error failed to fetch an image or build from source: error building: failed to compute cache key: "/jvm.options" not found: not found

What I’m trying to do is deploy elastic search to the server so I can use my Rubygem Searchkick

Any help here would be great, anything I’m doing wrong etc etc

Error failed to fetch an image or build from source: error building: failed to compute cache key: "/jvm.options" not found: not found

Let me translate that error message into English for you. What it is saying is that a file named jvm.options can’t be found on your development machine in the root directory of your application. Perhaps you have this file in your config directory?

Hiya

I was just about to update this to say I’ve done a few changes:

I’ve changed my whole docker file to be this instead:

# Install system packages needed by Elasticsearch
RUN apt-get update && apt-get install -y apt-transport-https gnupg && \
    apt-get update && apt-get install -y wget
# Install Elasticsearch
RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - && \
    echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-7.x.list && \
    apt-get update && apt-get install -y elasticsearch && \
    service elasticsearch start

# Configure Elasticsearch
RUN sed -i 's/#cluster.name: my-application/cluster.name: my-application/' /etc/elasticsearch/elasticsearch.yml && \
    sed -i 's/#network.host: 192.168.0.1/network.host: 0.0.0.0/' /etc/elasticsearch/elasticsearch.yml && \
    sed -i 's/#http.port: 9200/http.port: 9200/' /etc/elasticsearch/elasticsearch.yml && \
    echo "discovery.type: single-node" >> /etc/elasticsearch/elasticsearch.yml

# Start Elasticsearch
CMD ["elasticsearch"]

However it seems like elasticsearch doesn’t want to start (it doesn’t error out either) So when i go to the ruby console on fly and do an order.reindex it states 9200 is refused

Yea, that’s not going to work. But easily fixed. See: Running Multiple Processes Inside A Fly.io App · Fly Docs

It looks like its more feasible to run elasticsearch on its own server then? if that’s the case I’ve been attempting this but run into errors crying about resource issues alot. Don’t suppose you have any ideas? Maybe its not possible to fun on fly or?

2023-02-23T19:56:45.087 app[5762bd9b] phx [info] bootstrap check failure [1] of [4]: max file descriptors [10240] for elasticsearch process is too low, increase to at least [65535]

2023-02-23T19:56:45.087 app[5762bd9b] phx [info] bootstrap check failure [2] of [4]: max number of threads [3878] for user [elasticsearch] is too low, increase to at least [4096]

2023-02-23T19:56:45.087 app[5762bd9b] phx [info] bootstrap check failure [3] of [4]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

2023-02-23T19:56:45.087 app[5762bd9b] phx [info] bootstrap check failure [4] of [4]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

You would need to set ulimits in the Docker image.

If it were me, I’d just use their Docker image. It probably handles most of this: Install Elasticsearch with Docker | Elasticsearch Guide [8.6] | Elastic