-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
58 lines (47 loc) · 1.45 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#syntax=docker/dockerfile:1.7
FROM --platform=$BUILDPLATFORM golang:1.22.2-alpine as builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY cmd cmd
COPY internal internal
COPY *.go ./
# Set Golang build envs based on Docker platform string
ARG TARGETPLATFORM
RUN --mount=type=cache,target=/root/.cache <<EOT
set -eux
case "$TARGETPLATFORM" in
'linux/amd64') export GOARCH=amd64 ;;
'linux/arm/v6') export GOARCH=arm GOARM=6 ;;
'linux/arm/v7') export GOARCH=arm GOARM=7 ;;
'linux/arm64') export GOARCH=arm64 ;;
*) echo "Unsupported target: $TARGETPLATFORM" && exit 1 ;;
esac
export CGO_ENABLED=0
go build -ldflags='-w -s' -tags lambda.norpc -trimpath -o cloudwatch-slack-alerts .
EOT
FROM alpine:3.19 AS rie
WORKDIR /app
ARG TARGETPLATFORM
ARG RIE_VERSION=v1.18
RUN <<EOT
set -eux
case "$TARGETPLATFORM" in
'linux/amd64') export SUFFIX=x86_64 ;;
'linux/arm64') export SUFFIX=arm64 ;;
*) echo "Unsupported target: $TARGETPLATFORM" && exit 1 ;;
esac
wget \
-O aws-lambda-rie \
"https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/download/$RIE_VERSION/aws-lambda-rie-$SUFFIX"
chmod +x aws-lambda-rie
EOT
FROM gcr.io/distroless/static:nonroot AS base
WORKDIR /
COPY --from=builder /app/cloudwatch-slack-alerts .
ENTRYPOINT ["./cloudwatch-slack-alerts"]
FROM base AS local
COPY --from=rie /app/aws-lambda-rie .
ENTRYPOINT ["./aws-lambda-rie"]
CMD ["./cloudwatch-slack-alerts"]
FROM base