From 5cc50eb522ed28d50440ddedead82e125832be2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ky=C3=A2ne=20Pichou?= Date: Fri, 13 Oct 2017 14:12:30 +0200 Subject: [PATCH] Use best practices for Dockerfiles (#180) --- app/Dockerfile | 21 +++++++++-------- app/{docker-entry.sh => entrypoint.sh} | 0 db/Dockerfile | 25 +++++++++++++++------ db/{docker-entrypoint1.sh => entrypoint.sh} | 2 ++ db/setup-wale.sh | 4 ---- web/Dockerfile | 7 +++--- web/{docker-entry.sh => entrypoint.sh} | 0 7 files changed, 34 insertions(+), 25 deletions(-) rename app/{docker-entry.sh => entrypoint.sh} (100%) mode change 100644 => 100755 rename db/{docker-entrypoint1.sh => entrypoint.sh} (94%) rename web/{docker-entry.sh => entrypoint.sh} (100%) diff --git a/app/Dockerfile b/app/Dockerfile index 48430d9..37c75de 100644 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -13,7 +13,7 @@ RUN apt-get update \ curl \ jq \ netcat \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin # Get Mattermost RUN mkdir -p /mattermost/data \ @@ -22,15 +22,14 @@ RUN mkdir -p /mattermost/data \ && cp /mattermost/config/config.json /config.json.save \ && rm -rf /mattermost/config/config.json -# Configure entrypoint -COPY docker-entry.sh / -# Set permission (TODO should be removed and replace by a chmod on the file in the repository ?) -RUN chmod +x /docker-entry.sh -ENTRYPOINT ["/docker-entry.sh"] - -EXPOSE 80 - -VOLUME /mattermost/data - +# Configure entrypoint and command +COPY entrypoint.sh / +ENTRYPOINT ["/entrypoint.sh"] WORKDIR /mattermost/bin CMD ["platform"] + +# Expose port 80 of the container +EXPOSE 80 + +# Use a volume for the data directory +VOLUME /mattermost/data diff --git a/app/docker-entry.sh b/app/entrypoint.sh old mode 100644 new mode 100755 similarity index 100% rename from app/docker-entry.sh rename to app/entrypoint.sh diff --git a/db/Dockerfile b/db/Dockerfile index 4cdb272..4ed3221 100644 --- a/db/Dockerfile +++ b/db/Dockerfile @@ -1,18 +1,29 @@ FROM postgres:9.4 +# Install some packages to use WAL RUN apt-get update \ - && apt-get install -y python-dev libffi-dev libssl-dev lzop pv daemontools curl build-essential \ + && apt-get install -y \ + build-essential \ + curl \ + daemontools \ + libffi-dev \ + libssl-dev \ + lzop \ + pv \ + python-dev \ && curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | python \ && pip install 'wal-e<1.0.0' \ - && apt-get remove -y build-essential python-dev \ + && apt-get remove -y \ + build-essential \ + python-dev \ && apt-get autoremove -y \ && apt-get clean \ - && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + && rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin /tmp/* /var/tmp/* +# Add wale script COPY setup-wale.sh /docker-entrypoint-initdb.d/ -COPY docker-entrypoint1.sh / -RUN chmod +x /docker-entrypoint1.sh - -ENTRYPOINT ["/docker-entrypoint1.sh"] +# Add and configure entrypoint and command +COPY entrypoint.sh / +ENTRYPOINT ["/entrypoint.sh"] CMD ["postgres"] diff --git a/db/docker-entrypoint1.sh b/db/entrypoint.sh similarity index 94% rename from db/docker-entrypoint1.sh rename to db/entrypoint.sh index 67d085a..a134f0e 100755 --- a/db/docker-entrypoint1.sh +++ b/db/entrypoint.sh @@ -30,6 +30,7 @@ if [ "$1" = 'postgres' ]; then if [ "${!v}" = "" ]; then echo "$v is required for Wal-E but not set. Skipping Wal-E setup." update_conf + # Run the postgresql entrypoint . /docker-entrypoint.sh exit fi @@ -47,5 +48,6 @@ if [ "$1" = 'postgres' ]; then ARCHIVE_MODE=on update_conf + # Run the postgresql entrypoint . /docker-entrypoint.sh fi diff --git a/db/setup-wale.sh b/db/setup-wale.sh index 7f2584f..2cbe9fe 100755 --- a/db/setup-wale.sh +++ b/db/setup-wale.sh @@ -5,7 +5,3 @@ echo "wal_level = $WAL_LEVEL" >> $PGDATA/postgresql.conf echo "archive_mode = $ARCHIVE_MODE" >> $PGDATA/postgresql.conf echo "archive_command = 'envdir /etc/wal-e.d/env /usr/local/bin/wal-e wal-push %p'" >> $PGDATA/postgresql.conf echo "archive_timeout = $ARCHIVE_TIMEOUT" >> $PGDATA/postgresql.conf - -# no cron in the image, use systemd timer on host instead -#su - postgres -c "crontab -l | { cat; echo \"0 3 * * * /usr/bin/envdir /etc/wal-e.d/env /usr/local/bin/wal-e backup-push /var/lib/postgresql/data\"; } | crontab -" -#su - postgres -c "crontab -l | { cat; echo \"0 4 * * * /usr/bin/envdir /etc/wal-e.d/env /usr/local/bin/wal-e delete --confirm retain 7\"; } | crontab -" diff --git a/web/Dockerfile b/web/Dockerfile index 4038b66..c6db45f 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -1,9 +1,10 @@ FROM nginx:mainline +# Remove default configuration and add our custom Nginx configuration files RUN rm /etc/nginx/conf.d/default.conf COPY ./mattermost /etc/nginx/sites-available/ COPY ./mattermost-ssl /etc/nginx/sites-available/ -COPY docker-entry.sh / -RUN chmod +x /docker-entry.sh -ENTRYPOINT /docker-entry.sh +# Add and setup entrypoint +COPY entrypoint.sh / +ENTRYPOINT ["/entrypoint.sh"] diff --git a/web/docker-entry.sh b/web/entrypoint.sh similarity index 100% rename from web/docker-entry.sh rename to web/entrypoint.sh