Skip to content

Commit

Permalink
Merge pull request #126 from dokku/josegonzalez-patch-1
Browse files Browse the repository at this point in the history
Use a newer builder for golang
  • Loading branch information
josegonzalez authored Dec 7, 2023
2 parents 337ca5e + c1e0349 commit 8ffaa10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ lambda-builder build --generate-image --builder dotnet

#### Building an image

A docker image can be produced from the generated artifact by specifying the `--generate-image` flag. This also allows for multiple `--label` flags as well as specifying a single image tag via either `-t` or `--tag`:
A docker image can be produced from the generated artifact by specifying the `--generate-image` flag. This also allows for multiple `--label` flags as well as specifying a single image tag via either `-t` or `--tag`:

```shell
# will write a lambda.zip in the specified path
Expand Down Expand Up @@ -111,7 +111,7 @@ aws lambda invoke --endpoint http://localhost:9001 --no-sign-request --function-
curl -d '{}' http://localhost:9001/2015-03-31/functions/function.handler/invocations

# the function can also be invoked directly from a container if desired
docker run --rm "lambda-builder/$APP:latest" function.handler '{"name": "World"}'
docker run --rm "lambda-builder/$APP:latest" function.handler '{"name": "World"}'
```

#### Generating a Procfile
Expand Down Expand Up @@ -141,7 +141,9 @@ Internally, `lambda-builder` detects a given language and builds the app accordi
- dotnet6
- dotnetcore3.1
- `go`
- default build image: `lambci/lambda:build-go1.x`
- default build image:
- With `go.mod`: `golang:1.21-bookworm`
- Without `go.mod`: `golang:1.17-buster`
- requirement: `go.mod` or `main.go`
- runtimes:
- provided.al2
Expand Down
15 changes: 13 additions & 2 deletions builders/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ type GoBuilder struct {

func NewGoBuilder(config Config) (GoBuilder, error) {
var err error
config.BuilderBuildImage, err = getBuildImage(config, "lambci/lambda:build-go1.x")
defaultBuilder := "golang:1.21-bookworm"
if !io.FileExistsInDirectory(config.WorkingDirectory, "go.mod") {
defaultBuilder = "golang:1.17-bullseye"
}

config.BuilderBuildImage, err = getBuildImage(config, defaultBuilder)
if err != nil {
return GoBuilder{}, err
}
Expand Down Expand Up @@ -79,11 +84,12 @@ install-gomod() {
go mod download 2>&1 | indent
else
puts-step "Missing go.mod, downloading dependencies via go get"
go env -w GO111MODULE=off
go get
fi
puts-step "Compiling via go build"
go build -o bootstrap main.go 2>&1 | indent
CGO_ENABLED=0 go build -o bootstrap main.go 2>&1 | indent
}
hook-pre-compile() {
Expand Down Expand Up @@ -111,6 +117,11 @@ hook-package() {
return
fi
if ! command -v zip >/dev/null 2>&1; then
puts-step "Installing zip dependency for packaging"
apt update && apt install -y --no-install-recommends zip
fi
puts-step "Creating package at lambda.zip"
zip -q -r lambda.zip bootstrap
mv lambda.zip /var/task/lambda.zip
Expand Down

0 comments on commit 8ffaa10

Please sign in to comment.