Skip to content

Commit

Permalink
feat: optimize for arm build
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmoysrt committed Feb 6, 2024
1 parent 403e934 commit b119528
Showing 1 changed file with 14 additions and 32 deletions.
46 changes: 14 additions & 32 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
FROM golang:1.21.3-bullseye AS builder

# Env setup
ENV CGO_ENABLED="0"
# Setup workdir
WORKDIR /build
# Copy source code
# build stage
FROM --platform=$BUILDPLATFORM golang:1.21.6-bookworm AS build-env
ENV CGO_ENABLED=1
WORKDIR /src
COPY . .

# Fetch dependencies
RUN go mod download

RUN GOOS=linux go build -ldflags="-s -w" -o app .

# Runner stage
FROM debian:bullseye-slim AS runner

# Build Args
ARG BINARY_NAME="app"
ARG START_COMMAND="./app"

# Setup workdir
WORKDIR /user

# Copy binary
COPY --from=builder /build/app .

# Create entrypoint
RUN echo "./app" > /user/entrypoint.sh
RUN chmod +x /user/entrypoint.sh

# Setup Entrypoint
ENTRYPOINT ["sh", "-c", "/user/entrypoint.sh"]
RUN --mount=type=cache,target=/root/.cache/go-build go build -o goapp .

# final stage
FROM --platform=$BUILDPLATFORM ubuntu:22.04
RUN mkdir /app
RUN mkdir /data
WORKDIR /app
COPY --from=build-env /src/goapp /app/goapp
RUN apt-get update && apt-get install -y ca-certificates
ENTRYPOINT /app/goapp

0 comments on commit b119528

Please sign in to comment.