-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
117 lines (103 loc) · 3.81 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Golang docker image options
ARG GO_IMAGE=buster
ARG GO_VERSION=1.20.5
# Libtool arguments
ARG LIBTOOL_VERSION=2.4.6_3
ARG LIBTOOL_SUM=9e4b12c13734a5f1b72dfd48aa71faa8fd81bbf2d16af90d1922556206caecc3
# Packages repository as dependencies to build
ARG REPO_URL=https://github.com/vxcontrol/vxbuild-cross/releases/download/v0.0.0
# Mac OS SDK used to osxcross
ARG OSX_SDK=MacOSX10.15.sdk
ARG OSX_SDK_SUM=d97054a0aaf60cb8e9224ec524315904f0309fbbbac763eb7736bdfbdad6efc8
# osxcross arguments
ARG OSX_VERSION_MIN=10.12
ARG OSX_CODENAME=catalina
ARG OSX_CROSS_COMMIT=bee9df60f169abdbe88d8529dbcc1ec57acf656d
ARG OSX_CROSS_REQUIREMENTS="libssl-dev libxml2-dev zlib1g-dev"
# Preparing base part of target image
FROM golang:${GO_VERSION}-${GO_IMAGE} AS base
ARG APT_MIRROR
RUN sed -ri "s/(httpredir|deb).debian.org/${APT_MIRROR:-deb.debian.org}/g" /etc/apt/sources.list \
&& sed -ri "s/(security).debian.org/${APT_MIRROR:-security.debian.org}/g" /etc/apt/sources.list
ENV OSX_CROSS_PATH=/osxcross
# Pulling and checking SDK tarball
FROM base AS osx-sdk
ARG OSX_SDK
ARG OSX_SDK_SUM
ARG REPO_URL
ADD ${REPO_URL}/${OSX_SDK}.tar.xz "${OSX_CROSS_PATH}/tarballs/${OSX_SDK}.tar.xz"
RUN echo "${OSX_SDK_SUM}" "${OSX_CROSS_PATH}/tarballs/${OSX_SDK}.tar.xz" | sha256sum -c -
# Preparing of osxcross build
FROM base AS osx-cross-base
ARG OSX_CROSS_REQUIREMENTS
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -qq && apt-get install -y -q --no-install-recommends \
clang \
cmake \
llvm \
libc++-dev \
file \
patch \
vim \
jq \
git \
xz-utils \
${OSX_CROSS_REQUIREMENTS} \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
RUN git config --global --add safe.directory '*'
# Building osxcross
FROM osx-cross-base AS osx-cross
ARG OSX_CROSS_COMMIT
WORKDIR "${OSX_CROSS_PATH}"
RUN git clone https://github.com/tpoechtrager/osxcross.git . \
&& git checkout -q "${OSX_CROSS_COMMIT}" \
&& rm -rf ./.git
COPY --from=osx-sdk "${OSX_CROSS_PATH}/." "${OSX_CROSS_PATH}/"
ARG OSX_VERSION_MIN
RUN UNATTENDED=yes OSX_VERSION_MIN=${OSX_VERSION_MIN} OCDEBUG=1 ./build.sh
RUN rm -rf "${OSX_CROSS_PATH}/tarballs/*"
# Adding libtool to osxcross
FROM base AS libtool
ARG LIBTOOL_VERSION
ARG LIBTOOL_SUM
ARG OSX_CODENAME
ARG OSX_SDK
ARG REPO_URL
ADD ${REPO_URL}/libtool-${LIBTOOL_VERSION}.${OSX_CODENAME}.bottle.tar.gz "${OSX_CROSS_PATH}/tarballs/libtool-${LIBTOOL_VERSION}.tar.gz"
RUN echo "${LIBTOOL_SUM}" "${OSX_CROSS_PATH}/tarballs/libtool-${LIBTOOL_VERSION}.tar.gz" | sha256sum -c -
RUN mkdir -p "${OSX_CROSS_PATH}/target/SDK/${OSX_SDK}/usr/"
RUN gzip -dc "${OSX_CROSS_PATH}/tarballs/libtool-${LIBTOOL_VERSION}.tar.gz" | tar xf - \
-C "${OSX_CROSS_PATH}/target/SDK/${OSX_SDK}/usr/" \
--strip-components=2 \
"libtool/${LIBTOOL_VERSION}/include/" \
"libtool/${LIBTOOL_VERSION}/lib/"
# Making the final image with goreleaser and osxcross
FROM --platform=linux/arm64/v8 osx-cross-base AS final-arm64
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -qq && apt-get install -y -q --no-install-recommends \
libltdl-dev \
gcc-multilib-i686-linux-gnu \
g++-multilib-i686-linux-gnu \
gcc-multilib-x86-64-linux-gnu \
g++-multilib-x86-64-linux-gnu \
gcc-mingw-w64 \
g++-mingw-w64 \
parallel \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
FROM --platform=linux/amd64 osx-cross-base AS final-amd64
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -qq && apt-get install -y -q --no-install-recommends \
libltdl-dev \
gcc-multilib \
g++-multilib \
gcc-mingw-w64 \
g++-mingw-w64 \
parallel \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
###################
# multiarch build stage
###################
FROM final-${TARGETARCH} as final
COPY --from=osx-cross "${OSX_CROSS_PATH}/." "${OSX_CROSS_PATH}/"
COPY --from=libtool "${OSX_CROSS_PATH}/." "${OSX_CROSS_PATH}/"
ENV PATH=${OSX_CROSS_PATH}/target/bin:$PATH