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

Introduce go-smtp #28

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
38 changes: 22 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
name: CI

on: [push, pull_request]
on:
pull_request:
push:

jobs:
lint:
name: Lint
build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.14
- run: GO111MODULE=on go get honnef.co/go/tools/cmd/staticcheck
go-version: 1.19
- run: go vet ./...
- run: staticcheck ./...
- run: go build -v ./...
- run: go test -v ./...

test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- name: Docker login
if: startsWith(github.ref, 'refs/tags/v')
run: echo ${{ secrets.GH_TOKEN }} | docker login ghcr.io -u mabels --password-stdin

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
if: startsWith(github.ref, 'refs/tags/v')
with:
go-version: 1.14
- run: go test ./...
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

175 changes: 175 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
before:
hooks:
- go mod download
builds:
- env:
- CGO_ENABLED=0
id: "aws-smtp-relay"
ldflags:
- "-s -w -X main.Version='{{.Version}}' -X main.GitCommit={{.Commit}}"
# - freebsd
goos:
- linux
- windows
- darwin
goarch:
- arm
- amd64
- arm64
# - 386
goarm:
- "6"
- "7"
main: ./
binary: aws-smtp-relay
tags:
- release

archives:
- id: archive_id
name_template: >-
{{ .ProjectName }}_
{{- .Version }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- .Arm }}

checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

# .goreleaser.yaml
dockers:
- image_templates: ["ghcr.io/mabels/{{ .ProjectName }}:{{ .Version }}-amd64"]
use: buildx
goos: linux
goarch: amd64
dockerfile: Dockerfile
build_flag_templates:
- --platform=linux/amd64
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/mabels/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/mabels/{{ .ProjectName }}
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=APL2

- image_templates: ["ghcr.io/mabels/{{ .ProjectName }}:{{ .Version }}-arm64v8"]
use: buildx
dockerfile: Dockerfile
goos: linux
goarch: arm64
goarm: "8"
build_flag_templates:
- --platform=linux/arm64/v8
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/mabels/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/mabels/{{ .ProjectName }}
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=APL2

- image_templates: ["ghcr.io/mabels/{{ .ProjectName }}:{{ .Version }}-armv7"]
use: buildx
dockerfile: Dockerfile
goos: linux
goarch: arm
goarm: "7"
build_flag_templates:
- --platform=linux/arm/v7
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/mabels/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/mabels/{{ .ProjectName }}
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=APL2

- image_templates: ["ghcr.io/mabels/{{ .ProjectName }}:alpine-{{ .Version }}-amd64"]
use: buildx
goos: linux
goarch: amd64
dockerfile: Dockerfile.alpine
build_flag_templates:
- --platform=linux/amd64
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/mabels/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/mabels/{{ .ProjectName }}
- --label=org.opencontainers.image.version=alpine-{{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=APL2

- image_templates: ["ghcr.io/mabels/{{ .ProjectName }}:alpine-{{ .Version }}-arm64v8"]
use: buildx
dockerfile: Dockerfile.alpine
goos: linux
goarch: arm64
goarm: "8"
build_flag_templates:
- --platform=linux/arm64/v8
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/mabels/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/mabels/{{ .ProjectName }}
- --label=org.opencontainers.image.version=alpine-{{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=APL2

- image_templates: ["ghcr.io/mabels/{{ .ProjectName }}:alpine-{{ .Version }}-armv7"]
use: buildx
dockerfile: Dockerfile.alpine
goos: linux
goarch: arm
goarm: "7"
build_flag_templates:
- --platform=linux/arm/v7
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/mabels/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/mabels/{{ .ProjectName }}
- --label=org.opencontainers.image.version=alpine-{{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=APL2

docker_manifests:
- name_template: ghcr.io/mabels/{{ .ProjectName }}:{{ .Version }}
image_templates:
- ghcr.io/mabels/{{ .ProjectName }}:{{ .Version }}-amd64
- ghcr.io/mabels/{{ .ProjectName }}:{{ .Version }}-armv7
- ghcr.io/mabels/{{ .ProjectName }}:{{ .Version }}-arm64v8
- name_template: ghcr.io/mabels/{{ .ProjectName }}:latest
image_templates:
- ghcr.io/mabels/{{ .ProjectName }}:{{ .Version }}-amd64
- ghcr.io/mabels/{{ .ProjectName }}:{{ .Version }}-armv7
- ghcr.io/mabels/{{ .ProjectName }}:{{ .Version }}-arm64v8

- name_template: ghcr.io/mabels/{{ .ProjectName }}:alpine-{{ .Version }}
image_templates:
- ghcr.io/mabels/{{ .ProjectName }}:alpine-{{ .Version }}-amd64
- ghcr.io/mabels/{{ .ProjectName }}:alpine-{{ .Version }}-armv7
- ghcr.io/mabels/{{ .ProjectName }}:alpine-{{ .Version }}-arm64v8
- name_template: ghcr.io/mabels/{{ .ProjectName }}:alpine-latest
image_templates:
- ghcr.io/mabels/{{ .ProjectName }}:alpine-{{ .Version }}-amd64
- ghcr.io/mabels/{{ .ProjectName }}:alpine-{{ .Version }}-armv7
- ghcr.io/mabels/{{ .ProjectName }}:alpine-{{ .Version }}-arm64v8


21 changes: 5 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
FROM golang:alpine as build
# Define the target arch via docker build --platform and --build-arg arguments
ARG TARGETARCH
ARG GOARCH=$TARGETARCH
ARG GOARM
# Install git to be able to install dependencies
RUN apk --no-cache add git
WORKDIR /opt
COPY . .
# Disable CGO to build a statically compiled binary.
# ldflags explanation (see `go tool link`):
# -s disable symbol table
# -w disable DWARF generation
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /bin/aws-smtp-relay
FROM golang:alpine as build

FROM scratch

COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build /bin/aws-smtp-relay /bin/
USER 65534
COPY ./aws-smtp-relay /bin/

ENTRYPOINT ["aws-smtp-relay"]

6 changes: 6 additions & 0 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM golang:alpine

COPY ./aws-smtp-relay /bin/

ENTRYPOINT ["aws-smtp-relay"]

5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ PROJECT=aws-smtp-relay
BIN_PATH = $(GOPATH)/bin/$(PROJECT)

# Files that require a rebuild on change:
DEPS = internal/relay/relay.go main.go
DIRS = internal internal/auth internal/receiver internal/receiver/aws_ses internal/relay \
internal/relay/pinpoint internal/relay/config internal/relay/ses \
internal/relay/filter internal/relay/client
DEPS = main.go $(wildcard *.go $(foreach fd, $(DIRS), $(fd)/*.go))


# --- Main targets ---
Expand Down
47 changes: 38 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,43 @@
module github.com/blueimp/aws-smtp-relay

go 1.14
go 1.19

require (
github.com/aws/aws-sdk-go v1.38.61
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-sql-driver/mysql v1.5.0 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/mhale/smtpd v0.0.0-20210322105601-438c8edb069c
github.com/stretchr/testify v1.5.1 // indirect
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
github.com/aws/aws-sdk-go-v2/service/pinpointemail v1.12.4
github.com/aws/aws-sdk-go-v2/service/ses v1.15.3
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21
github.com/spf13/pflag v1.0.5
golang.org/x/crypto v0.6.0
)

require (
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.15 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.23 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.30 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.21 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.24 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.23 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.23 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.12.4 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.18.5 // indirect
)

require (
github.com/aws/aws-sdk-go-v2 v1.17.5 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.15
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.29 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.23 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.30.5
github.com/aws/aws-sdk-go-v2/service/sqs v1.20.4
github.com/aws/smithy-go v1.13.5 // indirect
github.com/emersion/go-smtp v0.16.0
github.com/google/uuid v1.3.0
github.com/jmespath/go-jmespath v0.4.0 // indirect
)

replace github.com/emersion/go-smtp v0.16.0 => github.com/mabels/go-smtp v0.0.0-20230331132253-992d2562fbaf

// replace github.com/emersion/go-smtp v0.16.0 => ../go-smtp
Loading