11# Download stage for Real-ESRGAN models
2- FROM alpine:3.19 AS downloader
2+ FROM --platform=$BUILDPLATFORM ubuntu:24.04 AS downloader
33WORKDIR /download
44ARG REALESRGAN_URL="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-ubuntu.zip"
5- RUN apk add --no-cache wget unzip \
6- && mkdir -p upscaler \
7- && wget -q "${REALESRGAN_URL}" -O upscaler/realesrgan.zip \
8- && unzip -j upscaler/realesrgan.zip "*models*" -d upscaler/models-realesrgan \
9- && rm -rf upscaler/*.zip
5+ RUN --mount=type=cache,target=/download/cache,id=realesrgan-download \
6+ apt-get update && apt-get install -y wget unzip && \
7+ if [ ! -f /download/cache/realesrgan.zip ]; then \
8+ mkdir -p /download/cache && \
9+ wget -q "${REALESRGAN_URL}" -O /download/cache/realesrgan.zip; \
10+ fi && \
11+ mkdir -p upscaler && \
12+ cp /download/cache/realesrgan.zip upscaler/ && \
13+ unzip -j upscaler/realesrgan.zip "*models*" -d upscaler/models-realesrgan && \
14+ rm -rf upscaler/*.zip
1015
1116# Base compiler stage with common dependencies
12- FROM alpine:3.19 AS compiler-base
13- RUN apk add --no-cache git vulkan-headers vulkan-loader-dev glslang cmake make gcc g++
17+ FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx
18+ FROM --platform=$BUILDPLATFORM ubuntu:24.04 AS compiler-base
19+ COPY --from=xx / /
20+ RUN apt-get update -y && apt-get install -y \
21+ git \
22+ cmake \
23+ make \
24+ lld \
25+ clang \
26+ pkg-config \
27+ crossbuild-essential-arm64 \
28+ libgcc-12-dev-arm64-cross \
29+ libc6-dev-arm64-cross \
30+ glslang-tools
31+
32+ ARG TARGETPLATFORM
33+ RUN xx-apt-get install -y libvulkan-dev
1434
1535# Compile stage for waifu2x
16- FROM compiler-base AS waifu2x-compiler
36+ FROM --platform=$BUILDPLATFORM compiler-base AS waifu2x-compiler
1737WORKDIR /app
18- RUN git clone --depth 1 https://github.com/nihui/waifu2x-ncnn-vulkan.git waifu2x-ncnn-vulkan
38+ RUN --mount=type=cache,target=/root/.cache/git \
39+ git clone --depth 1 https://github.com/nihui/waifu2x-ncnn-vulkan.git waifu2x-ncnn-vulkan
1940WORKDIR /app/waifu2x-ncnn-vulkan
20- RUN git submodule update --init --recursive \
41+ RUN --mount=type=cache,target=/root/.cache/git \
42+ git submodule update --init --recursive \
2143 && mkdir build && cd build \
22- && cmake ../src && cmake --build . -j "$(nproc)"
44+ && cmake -DNCNN_SSE2=OFF \
45+ $(xx-clang --print-cmake-defines) ../src && cmake --build . -j "$(nproc)"
2346
2447# Compile stage for Real-ESRGAN
25- FROM compiler-base AS realesrgan-compiler
48+ FROM --platform=$BUILDPLATFORM compiler-base AS realesrgan-compiler
2649WORKDIR /app
27- RUN git clone --depth 1 https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan Real-ESRGAN-ncnn-vulkan
50+ RUN --mount=type=cache,target=/root/.cache/git \
51+ git clone --depth 1 https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan Real-ESRGAN-ncnn-vulkan
2852WORKDIR /app/Real-ESRGAN-ncnn-vulkan
29- RUN sed -i 's|git@github.com:|https://github.com/|g' .gitmodules \
53+ RUN --mount=type=cache,target=/root/.cache/git \
54+ sed -i 's|git@github.com:|https://github.com/|g' .gitmodules \
3055 && git submodule update --init --recursive \
3156 && mkdir build && cd build \
32- && cmake ../src && cmake --build . -j "$(nproc)"
57+ && cmake -DNCNN_SSE2=OFF \
58+ $(xx-clang --print-cmake-defines) ../src && cmake --build . -j "$(nproc)"
3359
3460# Build stage for web application
35- FROM oven/bun:1-alpine AS webbuilder
61+ FROM --platform=$BUILDPLATFORM oven/bun:1-alpine AS webbuilder
3662WORKDIR /app/web
3763COPY web/package.json web/bun.lockb ./
3864RUN bun install --frozen-lockfile
3965COPY web/ .
40- ARG NODE_ENV=production
41- ENV NODE_ENV=${NODE_ENV}
4266RUN bun run build
4367
4468# Build stage for Go API
45- FROM golang:1.22-alpine AS apibuilder
69+ FROM --platform=$BUILDPLATFORM golang:1.22-alpine AS apibuilder
70+ COPY --from=xx / /
4671WORKDIR /app
4772COPY go.* ./
4873RUN go mod download
4974COPY . .
50- RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o miyo cmd/main.go
51-
52- # Final stage
53- FROM alpine:3.19 AS runner
54-
5575ARG TARGETPLATFORM
76+ RUN xx-go --wrap
77+ RUN CGO_ENABLED=0 go build -ldflags="-s -w" -a -installsuffix cgo -o miyo cmd/main.go
5678
57- RUN apk update && \
58- if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
59- apk add --no-cache libgomp vulkan-tools mesa-vulkan-ati mesa-vulkan-layers libgcc; \
60- else \
61- apk add --no-cache libgomp vulkan-tools mesa-vulkan-ati mesa-vulkan-intel mesa-vulkan-layers libgcc; \
62- fi
79+ # Final stage
80+ FROM ubuntu:24.04 AS runner
81+ RUN apt-get update && apt-get install -y --no-install-recommends \
82+ libgomp1 \
83+ vulkan-tools \
84+ mesa-vulkan-drivers \
85+ vulkan-validationlayers \
86+ && rm -rf /var/lib/apt/lists/*
6387
6488WORKDIR /app
6589
@@ -69,5 +93,5 @@ COPY --from=downloader /download/upscaler/. upscaler/
6993COPY --from=apibuilder /app/miyo .
7094COPY --from=apibuilder /app/out out/
7195COPY --from=webbuilder /app/dist dist/
72- EXPOSE 9452
96+ EXPOSE 9452/tcp
7397CMD ["/app/miyo" ]
0 commit comments