Optimize codebase: Refactor start.sh, clean up elasticsearch.yml, and streamline Dockerfile

This commit is contained in:
Andreas Düren
2025-03-16 17:42:28 +01:00
parent 43f3babba5
commit e538faa594
3 changed files with 197 additions and 329 deletions

View File

@ -1,23 +1,28 @@
FROM cloudron/base:4.0.0
# Install dependencies
RUN apt-get update && apt-get install -y \
# Install dependencies and OpenJDK 17
RUN apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository -y ppa:openjdk-r/ppa && \
apt-get update && \
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
unzip \
wget \
default-jre \
iproute2 \
net-tools \
iputils-ping \
dnsutils
dnsutils \
openjdk-17-jdk
# Set environment variables
ENV ELASTIC_VERSION=8.17.3
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
# Create elasticsearch user and group with dynamic ID allocation
# Create elasticsearch user and group
RUN groupadd elasticsearch && \
useradd -g elasticsearch -s /bin/bash elasticsearch
@ -26,27 +31,21 @@ RUN mkdir -p /usr/share/elasticsearch && \
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTIC_VERSION}-linux-x86_64.tar.gz && \
tar -xzf elasticsearch-${ELASTIC_VERSION}-linux-x86_64.tar.gz -C /usr/share/ && \
mv /usr/share/elasticsearch-${ELASTIC_VERSION}/* /usr/share/elasticsearch/ && \
rm -rf /usr/share/elasticsearch-${ELASTIC_VERSION} && \
rm elasticsearch-${ELASTIC_VERSION}-linux-x86_64.tar.gz
rm -rf /usr/share/elasticsearch-${ELASTIC_VERSION} elasticsearch-${ELASTIC_VERSION}-linux-x86_64.tar.gz
# Set up directories
RUN mkdir -p /app/data/elasticsearch && \
mkdir -p /app/data/logs && \
mkdir -p /app/data/config && \
mkdir -p /app/data/secrets
# Create necessary directories for data and configuration
RUN mkdir -p /app/data/{elasticsearch,logs,config,secrets,jdk/bin,run} && \
chown -R elasticsearch:elasticsearch /app/data
# Copy configuration files
COPY elasticsearch.yml /app/data/config/elasticsearch.yml.orig
COPY elasticsearch.yml /app/elasticsearch.yml
COPY .env /app/.env
COPY start.sh /app/start.sh
COPY stop.sh /app/stop.sh
# Make scripts executable
RUN chmod +x /app/start.sh /app/stop.sh
# Add healthcheck
HEALTHCHECK --interval=10s --timeout=5s --start-period=60s --retries=3 \
CMD curl -f -u elastic:$(cat /app/data/secrets/elastic_password 2>/dev/null || echo "cloudron") http://localhost:9200 || exit 1
HEALTHCHECK --interval=15s --timeout=10s --start-period=120s --retries=5 \
CMD curl -fs -u elastic:$(cat /app/data/secrets/elastic_password 2>/dev/null || echo "cloudron") http://localhost:9200/_cluster/health?pretty || exit 1
CMD ["/app/start.sh"]