Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wait-for-it.sh to Docker image #291

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ FROM golang:alpine

# Install MailHog:
RUN apk --no-cache add --virtual build-dependencies \
bash \
git \
wget \
&& mkdir -p /root/gocode \
&& export GOPATH=/root/gocode \
&& go get github.com/mailhog/MailHog \
Expand All @@ -19,6 +21,10 @@ RUN apk --no-cache add --virtual build-dependencies \
# https://github.com/boot2docker/boot2docker/issues/581
RUN adduser -D -u 1000 mailhog

# Download wait-for-it.sh
RUN wget https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should pin to a specific version to make it deterministic; as that repository hasn't tagged releases, you could pin to the commit currently matching "master";

RUN wget https://raw.githubusercontent.com/vishnubob/wait-for-it/81b1373f17855a4dc21156cfe1694c31d7d1792e/wait-for-it.sh \

And this should be in a separate stage, because wget is only needed to download the script, and should not be in the final image, as it's not needed at runtime. This PR also needs a rebase, as it's based on an outdated version of the Dockerfile (which was rewritten to a multi-stage build in 9c830be (#317))

#
# MailHog Dockerfile
#

FROM alpine AS waitforit
RUN apk --no-cache add wget
RUN wget https://raw.githubusercontent.com/vishnubob/wait-for-it/81b1373f17855a4dc21156cfe1694c31d7d1792e/wait-for-it.sh \
 && chmod a+x wait-for-it.sh


FROM golang:alpine as builder

# Install MailHog:
RUN apk --no-cache add --virtual build-dependencies \
git \
&& mkdir -p /root/gocode \
&& export GOPATH=/root/gocode \
&& go get github.com/mailhog/MailHog

FROM alpine:3
RUN apk --no-cache add bash
# Add mailhog user/group with uid/gid 1000.
# This is a workaround for boot2docker issue #581, see
# https://github.com/boot2docker/boot2docker/issues/581
RUN adduser -D -u 1000 mailhog

COPY --from=waitforit /wait-for-it.sh  /
COPY --from=builder /root/gocode/bin/MailHog /usr/local/bin/

USER mailhog

WORKDIR /home/mailhog

ENTRYPOINT ["MailHog"]

# Expose the SMTP and HTTP ports:
EXPOSE 1025 8025

however having to add bash just for this script seems like a bit too much; perhaps instead a more minimal script should be written that does just the things that this image needs or, as I mentioned in an earlier comment, MailHog itself should really have an option to do the retries.

Altogether, I'm not sure if this script should really be part of the default image, as it's not used by default (especially with the added bash dependency)

&& chmod a+x wait-for-it.sh

USER mailhog

WORKDIR /home/mailhog
Expand Down
12 changes: 12 additions & 0 deletions docs/DEPLOY.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ To mount the Maildir to the local filesystem, you can use a volume:

docker run -d -e "MH_STORAGE=maildir" -v $PWD/maildir:/maildir -p 1025:1025 -p 8025:8025 mailhog/mailhog

#### MongoDB

You can run MailHog with a MongoDB for persisting messages. In order to prevent MailHog from falling back to in-memory storage, you can override the default Docker entrypoint with the `wait-for-it.sh` command.

**docker-compose.yml**

services:
mailhog:
entrypoint: ["wait-for-it.sh", "mongo-db-host:27017", "--strict", "--timeout=120", "--", "MailHog"]

This example waits 120s until a connection to the MongoDB can be established before starting MailHog. Please see https://github.com/vishnubob/wait-for-it for usage.

### Elastic Beanstalk

You can deploy MailHog using [AWS Elastic Beanstalk](http://aws.amazon.com/elasticbeanstalk/).
Expand Down