From 86115c794b70890f2bc0c097b59e526c9dd0b89c Mon Sep 17 00:00:00 2001 From: Yash Singh Date: Tue, 5 Aug 2025 12:32:22 +0000 Subject: [PATCH] Optimized Dockerfile and docker-compose.yml Added a dedicated run.sh script for cleaner entrypoint handling. Also updated docker-compose.yml by adding a healthcheck for the database service and removing the unnecessary 'command' section from app definition. --- Dockerfile | 25 +++++++++++-------------- docker-compose.yml | 10 +++------- run.sh | 7 +++++++ 3 files changed, 21 insertions(+), 21 deletions(-) create mode 100755 run.sh diff --git a/Dockerfile b/Dockerfile index 783f4287..75329bcc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,24 +3,21 @@ FROM alpine:latest # Install dependencies RUN apk --no-cache add ca-certificates tzdata shadow su-exec -# Set the working directory +# Set working directory WORKDIR /listmonk -# Copy only the necessary files -COPY listmonk . -COPY config.toml.sample config.toml - -# Copy the entrypoint script +# Copy binaries and configs +COPY listmonk run.sh config.toml config.toml.sample queries.sql schema.sql permissions.json ./ COPY docker-entrypoint.sh /usr/local/bin/ -# Make the entrypoint script executable -RUN chmod +x /usr/local/bin/docker-entrypoint.sh +# Copy static assets +COPY static/ ./static/ +COPY i18n/ ./i18n/ +COPY frontend/dist/ ./frontend/dist/ + +# Make scripts executable +RUN chmod +x /usr/local/bin/docker-entrypoint.sh ./run.sh -# Expose the application port EXPOSE 9000 -# Set the entrypoint -ENTRYPOINT ["docker-entrypoint.sh"] - -# Define the command to run the application -CMD ["./listmonk"] +ENTRYPOINT ["./run.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 86fb47cf..6269348f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ x-db-credentials: &db-credentials # Use the default services: # listmonk app app: - image: listmonk/listmonk:latest + image: yashsingh/listmonk-init:latest container_name: listmonk_app restart: unless-stopped ports: @@ -15,12 +15,8 @@ services: - listmonk hostname: listmonk.example.com # Recommend using FQDN for hostname depends_on: - - db - command: [sh, -c, "./listmonk --install --idempotent --yes --config '' && ./listmonk --upgrade --yes --config '' && ./listmonk --config ''"] - # --config (file) param is set to empty so that listmonk only uses the env vars (below) for config. - # --install --idempotent ensures that DB installation happens only once on an empty DB, on the first ever start. - # --upgrade automatically runs any DB migrations when a new image is pulled. - + db: + condition: service_healthy environment: # The same params as in config.toml are passed as env vars here. LISTMONK_app__address: 0.0.0.0:9000 LISTMONK_db__user: *db-user diff --git a/run.sh b/run.sh new file mode 100755 index 00000000..9d5f17b6 --- /dev/null +++ b/run.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# Run database installation only once +./listmonk --install --idempotent --yes + +# Then start the actual application +./listmonk