Skip to content

Commit 6f7a5c5

Browse files
authored
Build Aarch64 executable on centos:8 (#314)
Also, move default docker build args to build_x86_64_executable.sh
1 parent 166c291 commit 6f7a5c5

File tree

4 files changed

+61
-25
lines changed

4 files changed

+61
-25
lines changed

exe-requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# requirements for the standalone executable
2-
pyinstaller==4.0
2+
pyinstaller==4.0; platform.machine == "x86_64"
3+
# aarch64 requires a later version due to the use of a newer centos version.
4+
# see https://github.com/pyinstaller/pyinstaller/issues/5540
5+
pyinstaller==4.10; platform.machine == "aarch64"
36
staticx==0.12.1

pyi.Dockerfile

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
# parts are copied from Dockerfile
22

33
# these need to be defined before any FROM - otherwise, the ARGs expand to empty strings.
4-
5-
# pyspy & rbspy, using the same builder for both pyspy and rbspy since they share build dependencies - rust:latest 1.52.1
6-
ARG RUST_BUILDER_VERSION=@sha256:9c106c1222abe1450f45774273f36246ebf257623ed51280dbc458632d14c9fc
7-
# perf - ubuntu:16.04
8-
ARG PERF_BUILDER_UBUNTU=@sha256:d7bb0589725587f2f67d0340edb81fd1fcba6c5f38166639cf2a252c939aa30c
9-
# phpspy - ubuntu:20.04
10-
ARG PHPSPY_BUILDER_UBUNTU=@sha256:cf31af331f38d1d7158470e095b132acd126a7180a54f263d386da88eb681d93
11-
# async-profiler glibc - centos:7, see explanation in Dockerfile
12-
ARG AP_BUILDER_CENTOS=@sha256:0f4ec88e21daf75124b8a9e5ca03c37a5e937e0e108a255d890492430789b60e
13-
# async-profiler musl build
14-
ARG AP_BUILDER_ALPINE=@sha256:69704ef328d05a9f806b6b8502915e6a0a4faa4d72018dc42343f511490daf8a
15-
# burn - golang:1.16.3
16-
ARG BURN_BUILDER_GOLANG=@sha256:f7d3519759ba6988a2b73b5874b17c5958ac7d0aa48a8b1d84d66ef25fa345f1
17-
# bcc & gprofiler - centos:7
18-
# CentOS 7 image is used to grab an old version of `glibc` during `pyinstaller` bundling.
19-
# this will allow the executable to run on older versions of the kernel, eventually leading to the executable running on a wider range of machines.
20-
ARG GPROFILER_BUILDER=@sha256:0f4ec88e21daf75124b8a9e5ca03c37a5e937e0e108a255d890492430789b60e
21-
# pyperf - ubuntu 20.04
22-
ARG PYPERF_BUILDER_UBUNTU=@sha256:cf31af331f38d1d7158470e095b132acd126a7180a54f263d386da88eb681d93
4+
# see build_x86_64_executable.sh and build_aarch64_executable.sh which define these.
5+
ARG RUST_BUILDER_VERSION
6+
ARG PERF_BUILDER_UBUNTU
7+
ARG PHPSPY_BUILDER_UBUNTU
8+
ARG AP_BUILDER_CENTOS
9+
ARG AP_BUILDER_ALPINE
10+
ARG BURN_BUILDER_GOLANG
11+
ARG GPROFILER_BUILDER
12+
ARG PYPERF_BUILDER_UBUNTU
2313

2414
# pyspy & rbspy builder base
2515
FROM rust${RUST_BUILDER_VERSION} AS pyspy-rbspy-builder-common
@@ -100,6 +90,14 @@ RUN ./bcc_helpers_build.sh
10090
# bcc & gprofiler
10191
FROM centos${GPROFILER_BUILDER} AS build-stage
10292

93+
# fix repo links for CentOS 8, and enable powertools (required to download glibc-static)
94+
RUN if grep -q "CentOS Linux 8" /etc/os-release ; then \
95+
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*; \
96+
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*; \
97+
yum install -y dnf-plugins-core; \
98+
dnf config-manager --set-enabled powertools; \
99+
fi
100+
103101
# bcc part
104102
# TODO: copied from the main Dockerfile... but modified a lot. we'd want to share it some day.
105103

@@ -142,7 +140,7 @@ WORKDIR /app
142140

143141
RUN yum install -y epel-release
144142
RUN yum install -y gcc python3 curl python3-pip patchelf python3-devel upx
145-
# needed for aarch64
143+
# needed for aarch64 (for staticx)
146144
RUN if [ $(uname -m) = "aarch64" ]; then yum install -y glibc-static zlib-devel.aarch64; fi
147145
# needed for aarch64, scons & wheel are needed to build staticx
148146
RUN if [ $(uname -m) = "aarch64" ]; then python3 -m pip install 'wheel==0.37.0' 'scons==4.2.0'; fi
@@ -155,6 +153,13 @@ COPY granulate-utils/granulate_utils granulate-utils/granulate_utils
155153
RUN python3 -m pip install -r requirements.txt
156154

157155
COPY exe-requirements.txt exe-requirements.txt
156+
# build on centos:8 of Aarch64 requires -lnss_files and -lnss_dns. the files are missing but the symbols
157+
# seem to be provided from another archive (e.g libc.a), so this "fix" bypasses the ld error of "missing -lnss..."
158+
# see https://github.com/JonathonReinhart/staticx/issues/219
159+
RUN if grep -q "CentOS Linux 8" /etc/os-release ; then \
160+
! test -f /lib64/libnss_files.a && ar rcs /lib64/libnss_files.a && \
161+
! test -f /lib64/libnss_dns.a && ar rcs /lib64/libnss_dns.a; \
162+
fi
158163
RUN python3 -m pip install -r exe-requirements.txt
159164

160165
# copy PyPerf and stuff

scripts/build_aarch64_executable.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ UBUNTU_VERSION=@sha256:82becede498899ec668628e7cb0ad87b6e1c371cb8a1e597d83a47fac
1010
# rust 1.54.0
1111
RUST_VERSION=@sha256:33a923c30700bb627d1389b6819cfb18af2a585b2901df045924eba1ac0a9c30
1212
# centos 7
13-
CENTOS_VERSION=@sha256:43964203bf5d7fe38c6fca6166ac89e4c095e2b0c0a28f6c7c678a1348ddc7fa
13+
CENTOS7_VERSION=@sha256:43964203bf5d7fe38c6fca6166ac89e4c095e2b0c0a28f6c7c678a1348ddc7fa
14+
# centos 8
15+
CENTOS8_VERSION=@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
1416
# golang 1.16.3
1517
GOLANG_VERSION=@sha256:f7d3519759ba6988a2b73b5874b17c5958ac7d0aa48a8b1d84d66ef25fa345f1
1618
# alpine 3.14.2
@@ -22,8 +24,8 @@ docker buildx build --platform=linux/arm64 \
2224
--build-arg PYPERF_BUILDER_UBUNTU=$UBUNTU_VERSION \
2325
--build-arg PERF_BUILDER_UBUNTU=$UBUNTU_VERSION \
2426
--build-arg PHPSPY_BUILDER_UBUNTU=$UBUNTU_VERSION \
25-
--build-arg AP_BUILDER_CENTOS=$CENTOS_VERSION \
27+
--build-arg AP_BUILDER_CENTOS=$CENTOS7_VERSION \
2628
--build-arg AP_BUILDER_ALPINE=$ALPINE_VERSION \
2729
--build-arg BURN_BUILDER_GOLANG=$GOLANG_VERSION \
28-
--build-arg GPROFILER_BUILDER=$CENTOS_VERSION \
30+
--build-arg GPROFILER_BUILDER=$CENTOS8_VERSION \
2931
. -f pyi.Dockerfile --output type=local,dest=build/aarch64/

scripts/build_x86_64_executable.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,31 @@
55
#
66
set -euo pipefail
77

8+
# pyspy & rbspy, using the same builder for both pyspy and rbspy since they share build dependencies - rust:latest 1.52.1
9+
RUST_BUILDER_VERSION=@sha256:9c106c1222abe1450f45774273f36246ebf257623ed51280dbc458632d14c9fc
10+
# perf - ubuntu:16.04 (IIRC for older glibc, to support older kernels)
11+
UBUNTU_VERSION_1604=@sha256:d7bb0589725587f2f67d0340edb81fd1fcba6c5f38166639cf2a252c939aa30c
12+
# phpspy & pyperf - ubuntu:20.04
13+
UBUNTU_VERSION=@sha256:cf31af331f38d1d7158470e095b132acd126a7180a54f263d386da88eb681d93
14+
# async-profiler glibc - centos:7
15+
AP_BUILDER_CENTOS=@sha256:0f4ec88e21daf75124b8a9e5ca03c37a5e937e0e108a255d890492430789b60e
16+
# async-profiler musl - alpine
17+
AP_BUILDER_ALPINE=@sha256:69704ef328d05a9f806b6b8502915e6a0a4faa4d72018dc42343f511490daf8a
18+
# burn - golang:1.16.3
19+
BURN_BUILDER_GOLANG=@sha256:f7d3519759ba6988a2b73b5874b17c5958ac7d0aa48a8b1d84d66ef25fa345f1
20+
# bcc & gprofiler - centos:7
21+
# CentOS 7 image is used to grab an old version of `glibc` during `pyinstaller` bundling.
22+
# this will allow the executable to run on older versions of the kernel, eventually leading to the executable running on a wider range of machines.
23+
GPROFILER_BUILDER=@sha256:0f4ec88e21daf75124b8a9e5ca03c37a5e937e0e108a255d890492430789b60e
24+
825
mkdir -p build/x86_64
9-
DOCKER_BUILDKIT=1 docker build -f pyi.Dockerfile --output type=local,dest=build/x86_64/ .
26+
DOCKER_BUILDKIT=1 docker build -f pyi.Dockerfile --output type=local,dest=build/x86_64/ \
27+
--build-arg RUST_BUILDER_VERSION=$RUST_BUILDER_VERSION \
28+
--build-arg PYPERF_BUILDER_UBUNTU=$UBUNTU_VERSION \
29+
--build-arg PERF_BUILDER_UBUNTU=$UBUNTU_VERSION_1604 \
30+
--build-arg PHPSPY_BUILDER_UBUNTU=$UBUNTU_VERSION \
31+
--build-arg AP_BUILDER_CENTOS=$AP_BUILDER_CENTOS \
32+
--build-arg AP_BUILDER_ALPINE=$AP_BUILDER_ALPINE \
33+
--build-arg BURN_BUILDER_GOLANG=$BURN_BUILDER_GOLANG \
34+
--build-arg GPROFILER_BUILDER=$GPROFILER_BUILDER \
35+
.

0 commit comments

Comments
 (0)