From 533b7d6b26ce9feb8106d9f51e56cd534ed15b65 Mon Sep 17 00:00:00 2001 From: Ryan McKern Date: Wed, 3 Jan 2024 21:56:25 -0800 Subject: [PATCH] Use AL2 build image instead of golang/debian MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the forced static compilation and use AL2 as a build environment, not just a runtime environment. This coincidentally also makes the lambda container smaller, so 🎉. --- Dockerfile.lambda | 22 ++++++++++++++++++---- Makefile | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Dockerfile.lambda b/Dockerfile.lambda index 61866a6..25a22dc 100644 --- a/Dockerfile.lambda +++ b/Dockerfile.lambda @@ -1,18 +1,32 @@ # Fetch or build all required binaries -FROM golang:1.21-bookworm as builder + +FROM public.ecr.aws/lambda/provided:al2 as builder + +ADD https://go.dev/dl/go1.21.5.linux-amd64.tar.gz /tmp/go1.21.5.linux-amd64.tar.gz ARG VERSION_REF RUN test -n "${VERSION_REF}" ENV SRC github.com/segmentio/kubeapply +ENV PATH=/usr/local/go/bin:/root/go/bin:/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin -RUN apt-get update && apt-get install --no-install-recommends --yes \ +RUN yum install -y \ curl \ + git \ + gzip \ + make \ + tar \ unzip \ + which \ wget COPY . /go/src/${SRC} -RUN cd /usr/local/bin && /go/src/${SRC}/scripts/pull-deps.sh + +RUN cd /usr/local \ + && tar xf /tmp/go1.21.5.linux-amd64.tar.gz \ + && cd /usr/local/bin \ + && go env \ + && /go/src/${SRC}/scripts/pull-deps.sh WORKDIR /go/src/${SRC} @@ -24,7 +38,7 @@ RUN make kubeapply-lambda VERSION_REF=${VERSION_REF} && \ # Copy into final image from builder FROM public.ecr.aws/lambda/provided:al2 -RUN yum install -y git unzip +RUN yum install -y git unzip && yum clean all # Not sure if awscli is needed for running lambda, but keeping it here for now RUN curl https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip \ diff --git a/Makefile b/Makefile index 8577ef6..7c9256f 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ ifndef VERSION_REF VERSION_REF ?= $(shell git describe --tags --always --dirty="-dev") endif -LDFLAGS := -ldflags='-linkmode "external" -extldflags "-static" -s -w -X "main.VersionRef=$(VERSION_REF)"' +LDFLAGS := -ldflags='-s -w -X "main.VersionRef=$(VERSION_REF)"' export GOFLAGS := -trimpath GOFILES = $(shell find . -iname '*.go' | grep -v -e vendor -e _modules -e _cache -e /data/)