Skip to content

Commit

Permalink
Merge pull request #135 from elisasre/feature/lambda
Browse files Browse the repository at this point in the history
add build all target for lambdas
  • Loading branch information
jauru authored Apr 15, 2024
2 parents 90feec5 + eca0245 commit 13e8705
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ jobs:
working-directory: ./godemo
- run: mage go:crossBuild
working-directory: ./godemo
- run: mage lambda:buildAll
working-directory: ./godemo
- run: mage docker:build
working-directory: ./godemo
- run: mage docker:push
Expand Down Expand Up @@ -87,6 +89,7 @@ jobs:
- run: test -x godemo/target/bin/windows/amd64/godemo
- run: test -f godemo/target/bin/windows/amd64/godemo.sha256
- run: test -f godemo/target/testbin/godemo
- run: test -f godemo/target/bin/linux/amd64/lambda/godemo/bootstrap
- run: test -d godemo/target/tests/cover/unit/
- run: test -d godemo/target/tests/cover/int/
- run: test -f godemo/target/tests/cover/combined/cover.txt
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jobs:
working-directory: ./godemo
- run: mage go:crossBuild
working-directory: ./godemo
- run: mage lambda:buildAll
working-directory: ./godemo
- run: mage go:sbom
working-directory: ./godemo
- run: mage docker:build
Expand Down Expand Up @@ -95,6 +97,7 @@ jobs:
- run: test -f godemo/target/bin/windows/amd64/godemo.sha256
- run: test -f godemo/target/bin/windows/amd64/godemo.bom.json
- run: test -f godemo/target/testbin/godemo
- run: test -f godemo/target/bin/linux/amd64/lambda/godemo/bootstrap
- run: test -d godemo/target/tests/cover/unit/
- run: test -d godemo/target/tests/cover/int/
- run: test -f godemo/target/tests/cover/combined/cover.txt
Expand Down
3 changes: 3 additions & 0 deletions godemo/magefiles/mage.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
swaggo "github.com/elisasre/mageutil/swaggo/target"
//mage:import
golang "github.com/elisasre/mageutil/golang/target"
//mage:import
lambda "github.com/elisasre/mageutil/lambda/target"
)

const AppName = "godemo"
Expand All @@ -48,4 +50,5 @@ func init() {
swaggo.OutputDir = "docs"
golang.BuildTarget = "./cmd/godemo"
golang.BuildMatrix = append(golang.BuildMatrix, goutil.BuildPlatform{OS: "windows", Arch: "amd64"})
lambda.BuildTargets = []string{"./cmd/godemo"}
}
43 changes: 43 additions & 0 deletions lambda/lambda.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package lambda

import (
"context"
"os"
"path"
"path/filepath"

"github.com/elisasre/mageutil/golang"
"github.com/magefile/mage/sh"
)

// BuildAll builds lambda bootstrap binaries and calculates sha sums for them.
func BuildAll(ctx context.Context, buildTargets []string, goarch string) error {
for _, target := range buildTargets {
err := Build(ctx, target, goarch)
if err != nil {
return err
}
}
return nil
}

// Build builds lambda bootstrap binary and calculates sha sum for it.
func Build(ctx context.Context, target string, goarch string) error {
info, err := golang.WithSHA(golang.BuildForPlatform(ctx, "linux", goarch, target))
if err != nil {
return err
}

src := filepath.Dir(info.BinPath)
dst := path.Join(src, "lambda", filepath.Base(target))
if err := os.MkdirAll(dst, 0o755); err != nil {
return err
}

dst = path.Join(dst, "bootstrap")
err = sh.Copy(dst, info.BinPath)
if err != nil {
return err
}
return nil
}
24 changes: 24 additions & 0 deletions lambda/target/lambda.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Package target exposes Lambda targets that can be imported in magefile using [import syntax].
// When using this package the user has to set target.BuildTargets.
//
// [import syntax]: https://magefile.org/importing/
package target

import (
"context"

"github.com/elisasre/mageutil/lambda"
"github.com/magefile/mage/mg"
)

var (
BuildTargets = []string{}
GOARCH = "amd64"
)

type Lambda mg.Namespace

// BuildAll builds lambda bootstrap binaries and calculates sha sums for them.
func (Lambda) BuildAll(ctx context.Context) error {
return lambda.BuildAll(ctx, BuildTargets, GOARCH)
}

0 comments on commit 13e8705

Please sign in to comment.