diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index aaf69c3..e6a7a4b 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -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: | diff --git a/Dockerfile b/Dockerfile index b341f46..242c357 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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. @@ -26,4 +30,4 @@ WORKDIR /home/mailhog ENTRYPOINT ["MailHog"] # Expose the SMTP and HTTP ports: -EXPOSE 1025 8025 +EXPOSE 1025 8025 \ No newline at end of file