-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
/info
route to return build info (#206)
- Loading branch information
Showing
4 changed files
with
67 additions
and
4 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,16 +1,19 @@ | ||
.PHONY: build clean deploy remove test | ||
|
||
.PHONY: build | ||
build: | ||
./script/build.sh | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf ./bin ./vendor | ||
|
||
.PHONY: deploy | ||
deploy: clean build | ||
sls deploy --verbose | ||
|
||
.PHONY: remove | ||
remove: clean | ||
sls remove --verbose | ||
|
||
.PHONY: test | ||
test: | ||
go test -race -covermode=atomic ./... |
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,35 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/aws/aws-lambda-go/events" | ||
"github.com/aws/aws-lambda-go/lambda" | ||
"github.com/harryzcy/mailbox/internal/util/apiutil" | ||
) | ||
|
||
var ( | ||
version = "dev" | ||
commit = "n/a" | ||
buildDate = "n/a" | ||
) | ||
|
||
func handler(ctx context.Context, req events.APIGatewayV2HTTPRequest) (apiutil.Response, error) { | ||
body, err := json.Marshal(map[string]string{ | ||
"version": version, | ||
"commit": commit, | ||
"build": buildDate, | ||
}) | ||
if err != nil { | ||
fmt.Printf("marshal failed: %v\n", err) | ||
return apiutil.NewErrorResponse(http.StatusInternalServerError, "internal error"), nil | ||
} | ||
return apiutil.NewSuccessJSONResponse(string(body)), nil | ||
} | ||
|
||
func main() { | ||
lambda.Start(handler) | ||
} |
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,16 +1,31 @@ | ||
#!/bin/bash | ||
|
||
BUILD_COMMIT=$(git rev-parse --short HEAD) | ||
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | ||
BUILD_VERSION=$(git describe --tags --always) | ||
|
||
ENVIRONMENT="env GOOS=linux GOARCH=amd64" | ||
|
||
apiFuncs=("list" "get" "getRaw" "getContent" "read" "trash" "untrash" "delete" "create" "save" "send") | ||
|
||
for i in "${!apiFuncs[@]}"; | ||
do | ||
func="${apiFuncs[$i]}" | ||
env GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o bin/api/emails/"${func}" api/emails/"${func}"/* | ||
${ENVIRONMENT} go build -ldflags="-s -w" -o bin/api/emails/"${func}" api/emails/"${func}"/* | ||
cp bin/api/emails/"${func}" bin/bootstrap | ||
zip -j bin/"${func}".zip bin/bootstrap | ||
done | ||
|
||
env GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o bin/functions/emailReceive functions/emailReceive/* | ||
${ENVIRONMENT} go build -ldflags="-s -w \ | ||
-X 'main.version=${BUILD_VERSION}' \ | ||
-X 'main.commit=${BUILD_COMMIT}' \ | ||
-X 'main.buildDate=${BUILD_DATE}' \ | ||
" \ | ||
-o bin/api/info api/info/* | ||
cp bin/api/info bin/bootstrap | ||
zip -j bin/info.zip bin/bootstrap | ||
|
||
${ENVIRONMENT} go build -ldflags="-s -w" -o bin/functions/emailReceive functions/emailReceive/* | ||
cp bin/functions/emailReceive bin/bootstrap | ||
zip -j bin/emailReceive.zip bin/bootstrap | ||
rm bin/bootstrap |
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