Skip to content

Instantly share code, notes, and snippets.

@wolfeidau
Last active December 29, 2022 22:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolfeidau/9d4e6e738565a851bda0c4fe1a4039ec to your computer and use it in GitHub Desktop.
Save wolfeidau/9d4e6e738565a851bda0c4fe1a4039ec to your computer and use it in GitHub Desktop.
Example multi-stage build container used with lambda docker support
#
# Based on https://docs.docker.com/develop/develop-images/multistage-build/
#
FROM public.ecr.aws/amazonlinux/amazonlinux:latest AS builder
WORKDIR /src
RUN yum install go -y
RUN yum install make -y
ADD . /src
#
# make build will output binaries to dist/ with a naming standard following $(name)-lambda
#
# NOTE: add a target to vendor code eg. `go mod vendor` before running build to save downloading deps in the container.
RUN make build
#
# Using a seperate container for running the service means your code isn't shipped to production, only the binaries are copied.
#
FROM public.ecr.aws/lambda/go:latest
#
# copy all the build lambda functions to
#
COPY --from=builder /src/dist/*-lambda ${LAMBDA_TASK_ROOT}/
GIT_HASH := $(shell git rev-parse --short HEAD)
LDFLAGS := -ldflags="-s -w -X main.commit=${GIT_HASH}"
build:
@echo "--- build all the things"
@mkdir -p dist
@go build $(LDFLAGS) -trimpath -o dist ./cmd/...
.PHONY: build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment