Skip to content

Commit 831fe5e

Browse files
feat: build darwin amd64/arm64 Docker images (#200)
* feat: buid darwing amd64/arm64 Docker images * Update go/darwin-arm64/Makefile * Update go/darwin/Makefile * fix: typo * feat: build multiarch Docker image * fix: use production Docker images * fix: typo * fix: copy changes to darwinw-arm64 * fix: remove arg
1 parent 4792481 commit 831fe5e

File tree

5 files changed

+70
-27
lines changed

5 files changed

+70
-27
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
*.o
44
.idea
55
.vagrant
6+
.vscode
67
_obj
78
Dockerfile
89
.status.*
910
*.bck
1011
CHANGELOG.md
1112
npcap/lib/*.exe
13+

go/darwin-arm64/Dockerfile.tmpl

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
ARG REPOSITORY
22
ARG VERSION
33
ARG TAG_EXTENSION=''
4-
FROM docker.elastic.co/beats-dev/golang-crossbuild:llvm-apple${TAG_EXTENSION} AS BUILD_LLVM_APPLE
5-
6-
ARG REPOSITORY
7-
ARG VERSION
8-
ARG TAG_EXTENSION=''
4+
{{- if or (eq .DEBIAN_VERSION "10") (eq .DEBIAN_VERSION "11")}}
5+
FROM --platform=linux/amd64 docker.elastic.co/beats-dev/golang-crossbuild:llvm-apple-debian{{ .DEBIAN_VERSION }}-amd64 AS build-llvm-apple-amd64
6+
FROM --platform=linux/arm64 docker.elastic.co/beats-dev/golang-crossbuild:llvm-apple-debian{{ .DEBIAN_VERSION }}-arm64 AS build-llvm-apple-arm64
7+
# workaround to https://github.com/moby/moby/issues/34482
8+
ARG TARGETARCH
9+
ARG BUILDARCH
10+
FROM build-llvm-apple-${TARGETARCH} as build-llvm-apple
11+
ARG TARGETARCH
12+
ARG BUILDARCH
13+
RUN echo "Building ${TARGETARCH} on a ${BUILDARCH}"
14+
{{- end }}
915
FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-base${TAG_EXTENSION}
1016

17+
{{- if and (ne .DEBIAN_VERSION "10") (ne .DEBIAN_VERSION "11")}}
18+
RUN echo "This Docker image will work only with Debian >10" && exit 1
19+
{{- end }}
20+
1121
RUN \
1222
apt-get -o Acquire::Check-Valid-Until=false update \
1323
&& apt-get install -qq -y --no-install-recommends --allow-unauthenticated \
@@ -19,22 +29,18 @@ RUN \
1929
uuid-dev \
2030
&& rm -rf /var/lib/apt/lists/*
2131

22-
{{- if or (eq .DEBIAN_VERSION "10") (eq .DEBIAN_VERSION "11")}}
23-
COPY --from=BUILD_LLVM_APPLE /llvm-apple-Linux.tar.gz /tmp/llvm-apple-Linux.tar.gz
32+
COPY --from=build-llvm-apple /llvm-apple-Linux.tar.gz /tmp/llvm-apple-Linux.tar.gz
2433
RUN tar -xzf /tmp/llvm-apple-Linux.tar.gz --strip 1 -C /usr/local \
2534
&& rm /tmp/llvm-apple-Linux.tar.gz
26-
{{- else }}
27-
RUN echo "This Docker image will work only with Debian >10" && exit 1
28-
{{- end }}
2935

3036
ARG OSXCROSS_PATH=/usr/local/osxcross
31-
COPY --from=BUILD_LLVM_APPLE /osxcross.tar.gz /tmp/osxcross.tar.gz
37+
COPY --from=build-llvm-apple /osxcross.tar.gz /tmp/osxcross.tar.gz
3238
RUN tar -xzf /tmp/osxcross.tar.gz -C / \
3339
&& rm /tmp/osxcross.tar.gz
3440

3541
ENV PATH $PATH:$OSXCROSS_PATH/bin
3642
# Add osxcross libraries to the library PATH
37-
ENV LD_LIBRARY_PATH ${OSXCROSS_PATH}/lib:$LD_LIBRARY_PATH
43+
ENV LD_LIBRARY_PATH $OSXCROSS_PATH/lib:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
3844

3945
COPY rootfs /
4046

go/darwin-arm64/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
11
include ../Makefile.common
2+
3+
ifeq ($(DOCKER_MULTIARCH),1)
4+
DOCKER_CMD := $(SELF_DIR)/../.ci/scripts/buildx.sh
5+
6+
push:
7+
@echo "Already done by buildx (.ci/scripts/buildx.sh)."
8+
atomic-push:
9+
@echo "Already done by buildx (.ci/scripts/buildx.sh)."
10+
endif

go/darwin/Dockerfile.tmpl

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
{{- if or (eq .DEBIAN_VERSION "10") (eq .DEBIAN_VERSION "11")}}
21
ARG REPOSITORY
32
ARG VERSION
43
ARG TAG_EXTENSION=''
5-
FROM docker.elastic.co/beats-dev/golang-crossbuild:llvm-apple${TAG_EXTENSION} AS BUILD_LLVM_APPLE
6-
{{- end }}
74

8-
ARG REPOSITORY
9-
ARG VERSION
10-
ARG TAG_EXTENSION=''
5+
{{- if or (eq .DEBIAN_VERSION "10") (eq .DEBIAN_VERSION "11")}}
6+
FROM --platform=linux/amd64 docker.elastic.co/beats-dev/golang-crossbuild:llvm-apple-debian{{ .DEBIAN_VERSION }}-amd64 AS build-llvm-apple-amd64
7+
FROM --platform=linux/arm64 docker.elastic.co/beats-dev/golang-crossbuild:llvm-apple-debian{{ .DEBIAN_VERSION }}-arm64 AS build-llvm-apple-arm64
8+
# workaround to https://github.com/moby/moby/issues/34482
9+
ARG TARGETARCH
10+
ARG BUILDARCH
11+
FROM build-llvm-apple-${TARGETARCH} as build-llvm-apple
12+
ARG TARGETARCH
13+
ARG BUILDARCH
14+
RUN echo "Building ${TARGETARCH} on a ${BUILDARCH}"
15+
{{- end }}
1116
FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-base${TAG_EXTENSION}
1217

1318
RUN \
@@ -29,7 +34,7 @@ RUN \
2934

3035
{{- if or (eq .DEBIAN_VERSION "10") (eq .DEBIAN_VERSION "11")}}
3136
ARG OSXCROSS_PATH=/usr/local/osxcross
32-
COPY --from=BUILD_LLVM_APPLE /osxcross.tar.gz /tmp/osxcross.tar.gz
37+
COPY --from=build-llvm-apple /osxcross.tar.gz /tmp/osxcross.tar.gz
3338
RUN tar -xzf /tmp/osxcross.tar.gz -C / \
3439
&& rm /tmp/osxcross.tar.gz
3540
{{- else }}
@@ -51,23 +56,35 @@ RUN \
5156

5257
ENV PATH $PATH:$OSXCROSS_PATH/bin
5358
# Add osxcross libraries to the library PATH
54-
ENV LD_LIBRARY_PATH ${OSXCROSS_PATH}/lib:$LD_LIBRARY_PATH
59+
ENV LD_LIBRARY_PATH $OSXCROSS_PATH/lib:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
5560

5661
COPY rootfs /
5762

5863
# Basic test
5964
RUN cd / \
60-
&& o64-clang helloWorld.c -o helloWorld \
61-
&& file helloWorld \
62-
&& file helloWorld | grep -c 'Mach-O 64-bit x86_64'
65+
&& o64-clang helloWorld.c -o helloWorld.x86_64 \
66+
&& file helloWorld.x86_64 \
67+
&& file helloWorld.x86_64 | grep -c 'Mach-O 64-bit x86_64'
68+
69+
{{- if or (eq .DEBIAN_VERSION "10") (eq .DEBIAN_VERSION "11")}}
70+
RUN cd / \
71+
&& oa64-clang helloWorld.c -o helloWorld.arm64 \
72+
&& file helloWorld.arm64 \
73+
&& file helloWorld.arm64 | grep -c 'Mach-O 64-bit arm64'
74+
75+
RUN cd / \
76+
&& lipo -create -output helloWorld.universal helloWorld.x86_64 helloWorld.arm64 \
77+
&& file helloWorld.universal | grep 'Mach-O universal binary' \
78+
&& rm helloWorld.*
79+
{{- end }}
6380

6481
# MacOSX10.14 SDK does not have 32bits compiler
6582
{{- if and (ne .DEBIAN_VERSION "10") (ne .DEBIAN_VERSION "11")}}
6683
RUN cd / \
67-
&& o32-clang helloWorld.c -o helloWorld \
68-
&& file helloWorld \
69-
&& file helloWorld | grep -c 'Mach-O i386' \
70-
&& rm helloWorld.c helloWorld
84+
&& o32-clang helloWorld.c -o helloWorld.i368 \
85+
&& file helloWorld.i368 \
86+
&& file helloWorld.i368 | grep -c 'Mach-O i386' \
87+
&& rm helloWorld.*
7188
{{- end }}
7289

7390
# Build-time metadata as defined at http://label-schema.org.

go/darwin/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
11
include ../Makefile.common
2+
3+
ifeq ($(DOCKER_MULTIARCH),1)
4+
DOCKER_CMD := $(SELF_DIR)/../.ci/scripts/buildx.sh
5+
6+
push:
7+
@echo "Already done by buildx (.ci/scripts/buildx.sh)."
8+
atomic-push:
9+
@echo "Already done by buildx (.ci/scripts/buildx.sh)."
10+
endif

0 commit comments

Comments
 (0)