-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
14 additions
and
32 deletions.
There are no files selected for viewing
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
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 |