From ad164ac7f2055ac9061cc6a06eafed68d9365d4d Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Thu, 1 Jun 2023 19:32:12 -0300 Subject: [PATCH] Make image smaller, use the correct platform --- template/crystal/Dockerfile | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/template/crystal/Dockerfile b/template/crystal/Dockerfile index d3ffda0..6d41aaa 100644 --- a/template/crystal/Dockerfile +++ b/template/crystal/Dockerfile @@ -1,30 +1,28 @@ -FROM crystallang/crystal:1.8.0 as builder +FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/of-watchdog:0.9.10 as watchdog +FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine as build -RUN apt update \ - && apt install -y curl \ - && echo "Pulling watchdog binary from Github." \ - && curl -sSL https://github.com/openfaas/faas/releases/download/0.9.6/fwatchdog > /usr/bin/fwatchdog \ - && chmod +x /usr/bin/fwatchdog +RUN apk add crystal shards WORKDIR /home/app COPY . . COPY function/shard.yml shard.yml RUN shards install -RUN crystal build main.cr -o handler --release - -FROM crystallang/crystal:1.8.0 -RUN apt install ca-certificates +RUN crystal build main.cr -o handler --release --static +RUN strip handler +FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine as ship # Add non root user -RUN adduser app -RUN mkdir -p /home/app +# Add non root user +RUN addgroup -S app && adduser app -S -G app +RUN chown app /home/app WORKDIR /home/app -COPY --from=builder /usr/bin/fwatchdog . -COPY --from=builder /home/app/function/ . -COPY --from=builder /home/app/handler . +COPY --from=build /home/app/function/ . +COPY --from=build /home/app/handler . +COPY --from=watchdog /fwatchdog /home/app/fwatchdog +RUN chmod +x /home/app/fwatchdog RUN chown -R app /home/app