diff --git a/.env.template b/.env.template new file mode 100644 index 0000000..325288b --- /dev/null +++ b/.env.template @@ -0,0 +1,12 @@ +# Elasticsearch environment variables +# This file will be copied to /app/data/.env during installation + +# Java memory settings - leave empty to auto-configure based on container limits +ES_JAVA_HEAP= + +# Security settings - DO NOT CHANGE +ES_JAVA_HOME=/app/data/jdk +ES_PATH_CONF=/app/data/config + +# Certificate password - DO NOT CHANGE +CERT_PASSWORD=cloudron diff --git a/Dockerfile b/Dockerfile index bc55616..bed94a6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM cloudron/base:4.0.0 +FROM cloudron/base:5.0.0 -# Install dependencies and OpenJDK 17 +# Install dependencies RUN apt-get update && \ apt-get install -y software-properties-common && \ add-apt-repository -y ppa:openjdk-r/ppa && \ @@ -18,7 +18,7 @@ RUN apt-get update && \ dnsutils \ openjdk-17-jdk -# Set environment variables +# Set Elasticsearch version ENV ELASTIC_VERSION=8.17.3 ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 @@ -33,7 +33,7 @@ RUN mkdir -p /usr/share/elasticsearch && \ mv /usr/share/elasticsearch-${ELASTIC_VERSION}/* /usr/share/elasticsearch/ && \ rm -rf /usr/share/elasticsearch-${ELASTIC_VERSION} elasticsearch-${ELASTIC_VERSION}-linux-x86_64.tar.gz -# Create necessary directories for data and configuration +# Create necessary directories RUN mkdir -p /app/data/{elasticsearch,logs,config,secrets,jdk/bin,run} && \ chown -R elasticsearch:elasticsearch /app/data @@ -41,10 +41,13 @@ RUN mkdir -p /app/data/{elasticsearch,logs,config,secrets,jdk/bin,run} && \ COPY elasticsearch.yml /app/elasticsearch.yml COPY start.sh /app/start.sh COPY stop.sh /app/stop.sh + +# Set permissions RUN chmod +x /app/start.sh /app/stop.sh -# Add healthcheck +# Health check HEALTHCHECK --interval=15s --timeout=10s --start-period=120s --retries=5 \ CMD curl -fs -u elastic:$(cat /app/data/secrets/elastic_password) http://localhost:9200/_cluster/health?pretty || exit 1 +# Command to run CMD ["/app/start.sh"] \ No newline at end of file diff --git a/package.sh b/package.sh index 97226a1..d6092c5 100755 --- a/package.sh +++ b/package.sh @@ -6,10 +6,10 @@ mkdir -p build rm -rf build/* # Copy all files to the build directory -cp -r CloudronManifest.json Dockerfile .env start.sh stop.sh README.md logo.png build/ +cp -r CloudronManifest.json Dockerfile .env.template elasticsearch.yml start.sh stop.sh README.md logo.png build/ # Create the package cd build -cloudron package +cloudron build --set-repository andreasdueren/elasticsearch-cloudron --tag latest echo "Package created successfully!" \ No newline at end of file diff --git a/start.sh b/start.sh index 6a7c65f..7052ed6 100644 --- a/start.sh +++ b/start.sh @@ -1,8 +1,23 @@ #!/bin/bash set -e -# Source environment variables (if the file exists) -[ -f /app/.env ] && source /app/.env || echo "No .env file found, using default environment variables" +# Check and create .env file if it doesn't exist +if [ ! -f /app/data/.env ]; then + echo "Creating default .env file..." + cp /app/.env.template /app/data/.env + chown elasticsearch:elasticsearch /app/data/.env + chmod 600 /app/data/.env +fi + +# Load environment variables from .env file if it exists +if [ -f /app/data/.env ]; then + echo "Loading environment variables from .env file..." + set -o allexport + source /app/data/.env + set +o allexport +else + echo "No .env file found, using default environment variables" +fi # Set constants ES_HOME=/usr/share/elasticsearch