Skip to content

Commit

Permalink
Rebuild mailhog every time, using latest go version
Browse files Browse the repository at this point in the history
Avoid potential vulns introduced by go
  • Loading branch information
schnatterer committed Oct 27, 2023
1 parent 501ced9 commit 6989ef5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create tags
id: create-tag
- name: Download latest MailHog release
run: |
# Find latest release (same as "go install github.com/mailhog/MailHog@latest" in Dockerfile)
# Find latest release
VERSION="$( curl -s -H "Authorization: bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/mailhog/mailhog/releases/latest" | jq -r '.tag_name')"
VERSION_DATE="$VERSION-$(date +'%Y-%m-%d')"
GHCR_IMAGE=ghcr.io/${{ github.repository_owner }}/mailhog
TAGS="${GHCR_IMAGE}:latest,${GHCR_IMAGE}:${VERSION},${GHCR_IMAGE}:${VERSION_DATE}"
echo "TAGS=${TAGS}" | tee -a $GITHUB_ENV
echo "VERSION=${VERSION}" | tee -a $GITHUB_ENV
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
build-args: VERSION=${{ env.VERSION }}
push: true
tags: ${{ env.TAGS }}
labels: |
Expand Down
26 changes: 15 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#
# MailHog Dockerfile
#
FROM golang:1-alpine as builder
ARG VERSION

FROM golang:1.18-alpine as builder
RUN apk --no-cache add make jq curl

RUN mkdir -p /root/gocode
ENV GOPATH=/root/gocode

WORKDIR $GOPATH/src/github.com/mailhog/MailHog
RUN curl -L https://github.com/mailhog/MailHog/archive/refs/tags/${VERSION}.tar.gz | tar -xz --strip-components=1

ENV GO111MODULE="off"
ENV CGO_ENABLED=0
ENV GOOS=linux
RUN go build -ldflags "-X main.version=$VERSION" -o $GOPATH/bin/MailHog

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

FROM alpine:3
# Add mailhog user/group with uid/gid 1000.
Expand All @@ -26,4 +30,4 @@ WORKDIR /home/mailhog
ENTRYPOINT ["MailHog"]

# Expose the SMTP and HTTP ports:
EXPOSE 1025 8025
EXPOSE 1025 8025

0 comments on commit 6989ef5

Please sign in to comment.