forked from kubebadges/kubebadges
-
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.
build: Refactor Dockerfile for multi-arch support and improved build …
…process
- Loading branch information
Showing
1 changed file
with
38 additions
and
12 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,31 +1,57 @@ | ||
# build flutter-web stage | ||
FROM neosu/flutter-web:3.13.9 AS flutter-web-builder | ||
# syntax=docker/dockerfile:1.4 | ||
|
||
## | ||
## 1) Build Flutter Web (amd64 seulement) | ||
## | ||
FROM --platform=linux/amd64 neosu/flutter-web:3.13.9 AS flutter-web-builder | ||
|
||
COPY ui /ui | ||
WORKDIR /ui | ||
COPY ui/ /ui/ | ||
|
||
RUN flutter pub get | ||
RUN flutter build web --dart-define=BUILD_TYPE=prod --tree-shake-icons --pwa-strategy none --web-renderer html --release | ||
RUN flutter build web \ | ||
--dart-define=BUILD_TYPE=prod \ | ||
--tree-shake-icons \ | ||
--pwa-strategy none \ | ||
--web-renderer html \ | ||
--release | ||
|
||
## | ||
## 2) Build Golang (multi-arch) | ||
## | ||
FROM --platform=$BUILDPLATFORM golang:1.21.3 AS go-builder | ||
|
||
# build golang stage | ||
FROM golang:1.21.3 AS go-builder | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
|
||
ENV CGO_ENABLED=0 \ | ||
GOOS=$TARGETOS \ | ||
GOARCH=$TARGETARCH | ||
|
||
WORKDIR /app | ||
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64 | ||
ADD go.mod . | ||
ADD go.sum . | ||
|
||
# On copie d'abord les go.mod / go.sum | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
# Copie du reste du code | ||
COPY . . | ||
|
||
# On copie les fichiers web compilés par Flutter | ||
COPY --from=flutter-web-builder /ui/build/web /app/web | ||
|
||
# Compilation Go | ||
RUN go build -a -ldflags="-w -s" -o /app/cmd/kubebadges/main ./cmd/kubebadges | ||
|
||
# production stage | ||
FROM alpine:latest | ||
## | ||
## 3) Image finale (multi-arch) | ||
## | ||
FROM --platform=$TARGETPLATFORM alpine:latest | ||
|
||
WORKDIR /app | ||
COPY --from=go-builder /app/cmd/kubebadges/main /app/main | ||
RUN chmod +x /app/main | ||
|
||
EXPOSE 8080 8090 | ||
|
||
CMD ["/app/main"] | ||
CMD ["/app/main"] |