-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathDockerfile
80 lines (65 loc) · 2.28 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# syntax=docker/dockerfile:1.4
ARG OUTPUT_DIR
ARG VERSION
ARG PACKAGE_NAME="getml-community-$VERSION-$TARGETARCH-$TARGETOS"
ARG BUILD_OR_COPY_ARTIFACTS="build"
FROM --platform=$BUILDPLATFORM golang:1.22 AS cli-build
ARG TARGETOS
ARG TARGETARCH
ARG VERSION
WORKDIR /cli/src
COPY src/getml-app/src .
RUN --mount=type=cache,target=/go/pkg/mod/ \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /cli/build/getml-cli -ldflags "-X main.version=$VERSION" . \
&& mkdir /cli/release \
&& cp /cli/build/getml-cli /cli/release/getml-cli
FROM scratch AS cli
ARG PACKAGE_NAME
COPY --from=cli-build /cli/release/getml-cli $PACKAGE_NAME/getML
FROM scratch AS export
ARG PACKAGE_NAME
COPY --from=cli / .
COPY --from=engine-package . .
COPY LICENSE.txt INSTALL.md $PACKAGE_NAME
COPY src/package-build-imports $PACKAGE_NAME
FROM --platform=$BUILDPLATFORM python:3.11-slim AS python-base
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG PACKAGE_NAME
ARG VERSION
WORKDIR /python-api/src
RUN pip install hatch
COPY src/python-api/ .
RUN echo $VERSION > getml/VERSION
RUN hatch build -t wheel
RUN mkdir -p /python-api/src/getml/.getML
FROM python-base AS python-base-arm64
ARG WHEEL_PLATFORM="manylinux_2_28_aarch64"
# HACK: Remove the any platform wheel on one of the branches
# to avoid multi-platform artifact name collision
RUN if [ "$TARGETPLATFORM" != "$BUILDPLATFORM" ]; then rm -rf dist/*.whl; fi
FROM python-base AS python-base-amd64
ARG WHEEL_PLATFORM="manylinux_2_28_x86_64"
RUN if [ "$TARGETPLATFORM" != "$BUILDPLATFORM" ]; then rm -rf dist/*.whl; fi
FROM python-base-$TARGETARCH AS python-build-artifacts
COPY --from=export /$PACKAGE_NAME getml/.getML/$PACKAGE_NAME
FROM python-base-$TARGETARCH AS python-copy-artifacts
ARG OUTPUT_DIR
COPY $OUTPUT_DIR/$PACKAGE_NAME getml/.getML/$PACKAGE_NAME
FROM python-${BUILD_OR_COPY_ARTIFACTS}-artifacts AS python-build
RUN hatch build -t wheel
FROM scratch AS python
COPY --from=python-build python-api/src/dist python-api
FROM alpine AS archive-build
ARG PACKAGE_NAME
COPY --from=export / /
RUN mkdir /out
RUN tar czf /out/$PACKAGE_NAME.tar.gz $PACKAGE_NAME
WORKDIR /out
RUN sha256sum $PACKAGE_NAME.tar.gz > $PACKAGE_NAME.tar.gz.sha256
FROM scratch AS archive
COPY --from=archive-build /out/ .
FROM scratch AS all
COPY --from=export / .
COPY --from=python / .
COPY --from=archive / .