Last active
January 24, 2025 17:22
-
-
Save wolfeidau/9d4e6e738565a851bda0c4fe1a4039ec to your computer and use it in GitHub Desktop.
Example multi-stage build container used with lambda docker support
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
# | |
# 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}/ |
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
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