-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from eexit/aws-lambda
AWS Lambda support via Serverless
- Loading branch information
Showing
13 changed files
with
499 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.env* | ||
.git* | ||
http2smtp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,11 @@ jobs: | |
name: Unit tests + coverage | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Go 1.x | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ^1.15 | ||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v2 | ||
- name: Get dependencies | ||
run: go get -v -t -d ./... | ||
- name: Build | ||
|
@@ -34,19 +33,19 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: golangci-lint | ||
- name: Lint the codebase | ||
uses: golangci/golangci-lint-action@v2 | ||
with: | ||
version: v1.34 | ||
publish: | ||
if: contains(github.ref, 'refs/tags/') | ||
name: Docker publish | ||
runs-on: ubuntu-latest | ||
if: contains(github.ref, 'refs/tags/') | ||
needs: [ tests, lint ] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
- uses: docker/setup-qemu-action@v1 | ||
- uses: docker/setup-buildx-action@v1 | ||
- name: Login to DockerHub | ||
uses: docker/login-action@v1 | ||
with: | ||
|
@@ -58,6 +57,7 @@ jobs: | |
- name: Build and push | ||
uses: docker/build-push-action@v2 | ||
with: | ||
platforms: linux/amd64 | ||
build-args: version=${{ steps.tagref.outputs.tag }}+${{ github.sha }} | ||
tags: '${{ github.repository }}:${{ steps.tagref.outputs.tag }},${{ github.repository }}:latest' | ||
push: true | ||
|
@@ -67,3 +67,29 @@ jobs: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
repository: ${{ github.repository }} | ||
release-bin: | ||
name: Release binaries | ||
if: contains(github.ref, 'refs/tags/') | ||
needs: [ tests, lint ] | ||
runs-on: ubuntu-latest | ||
env: | ||
CGO_ENABLED: 0 | ||
strategy: | ||
matrix: | ||
target: [http2smtp, http2smtp-lambda] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Retrieve tag | ||
id: tagref | ||
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} | ||
- uses: wangyoucao577/[email protected] | ||
with: | ||
github_token: ${{ secrets.GH_TOKEN }} | ||
goos: linux | ||
goarch: amd64 | ||
goversion: '1.15' | ||
project_path: cmd/${{ matrix.target }} | ||
binary_name: ${{ matrix.target }} | ||
extra_files: LICENSE README.md | ||
release_tag: ${{ steps.tagref.outputs.tag }} | ||
ldflags: -X github.com/eexit/http2smtp/internal/api.Version=${{ steps.tagref.outputs.tag }}+${{ github.sha }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.env | ||
coverage.txt | ||
http2smtp | ||
.serverless |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
URL=https://api.github.com/repos/eexit/http2smtp/releases/latest | ||
|
||
.DEFAULT: usage | ||
|
||
usage: | ||
@echo '+-------------------------------------------------------------------+' | ||
@echo '| Make Usage |' | ||
@echo '+-------------------------------------------------------------------+' | ||
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "|- \033[33m%-15s\033[0m -> %s\n", $$1, $$2}' | ||
|
||
install-sls: ## Installs serverless (via NPM) | ||
npm install -g serverless --ignore-scripts --loglevel error | ||
|
||
config: ## Prints the resolved stack config | ||
sls print --verbose | ||
|
||
download: ## Gets the latest version of the binary | ||
curl -sL $(URL) | jq -r '.assets[].browser_download_url' | grep lambda | grep -v md5 | xargs wget -qO- | tar xvz http2smtp-lambda | ||
|
||
deploy: ## Deploys the stack | ||
sls deploy --verbose | ||
|
||
remove: ## Removes the stack | ||
sls remove --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# :zap: http2smtp for AWS Lambda | ||
|
||
Deploy in 3 commands (assuming you already have a SMTP server deployed). | ||
|
||
## Usage | ||
|
||
``` | ||
$ make | ||
+-------------------------------------------------------------------+ | ||
| Make Usage | | ||
+-------------------------------------------------------------------+ | ||
|- config -> Prints the resolved stack config | ||
|- deploy -> Deploys the stack | ||
|- download -> Gets the latest version of the binary | ||
|- install-sls -> Installs serverless (via NPM) | ||
|- remove -> Removes the stack | ||
``` | ||
|
||
## Deploying | ||
|
||
- Install [serverless](https://www.serverless.com/) [yourself](https://www.serverless.com/framework/docs/getting-started/) or run `make install-sls` | ||
- Edit the `serverless.yml` file with the [wished configuration](https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml/) | ||
- Run `make download && make deploy` | ||
|
||
### Deploying a specific version | ||
|
||
If you wish to download a specific version of http2smtp, you can prefix the download URL as env var prior calling `make download`: | ||
|
||
```bash | ||
$ URL=https://api.github.com/repos/eexit/http2smtp/releases/tags/v1.2.3 make download | ||
``` | ||
|
||
Then deploy using `make deploy`. |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"math/rand" | ||
"os" | ||
"time" | ||
|
||
"github.com/aws/aws-lambda-go/lambda" | ||
"github.com/awslabs/aws-lambda-go-api-proxy/httpadapter" | ||
"github.com/eexit/http2smtp/internal/api" | ||
"github.com/eexit/http2smtp/internal/converter" | ||
"github.com/eexit/http2smtp/internal/env" | ||
"github.com/eexit/http2smtp/internal/smtp" | ||
"github.com/kelseyhightower/envconfig" | ||
"github.com/rs/zerolog" | ||
) | ||
|
||
func main() { | ||
rand.Seed(time.Now().UTC().UnixNano()) | ||
|
||
var e env.Bag | ||
envconfig.MustProcess("", &e) | ||
|
||
level, err := zerolog.ParseLevel(e.LogLevel) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
logger := zerolog.New(os.Stdout). | ||
Level(level). | ||
With(). | ||
Timestamp(). | ||
Str("version", api.Version). | ||
Logger() | ||
|
||
smtpClient := smtp.New(e.SMTPAddr, logger) | ||
|
||
converterProvider := converter.NewProvider( | ||
converter.NewRFC5322(), | ||
converter.NewSparkPost(), | ||
) | ||
|
||
app := api.New(e, logger, smtpClient, converterProvider) | ||
adapter := httpadapter.New(app.Wrap(app.Mux())) | ||
|
||
lambda.StartHandler(lambda.NewHandler(adapter.ProxyWithContext)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
service: http2smtp-lambda | ||
frameworkVersion: '2' | ||
useDotenv: true | ||
|
||
provider: | ||
name: aws | ||
runtime: go1.x | ||
|
||
package: | ||
exclude: | ||
- ./** | ||
include: | ||
- http2smtp-lambda | ||
|
||
functions: | ||
proxy: | ||
handler: http2smtp-lambda | ||
memorySize: 128 | ||
environment: | ||
SMTP_ADDR: 'smtp:25' | ||
LOG_LEVEL: debug | ||
events: | ||
- http: | ||
path: '{proxy+}' | ||
method: any |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.