Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git
Dockerfile
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.rsa
*.pkg*
*.gz
src
pkg
packages
33 changes: 21 additions & 12 deletions APKBUILD
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# Maintainer: Sasha Gerrand <alpine-pkgs@sgerrand.com>

pkgname="glibc"
pkgver="2.35"
_pkgrel="0"
pkgver="2.39"
pkgrel="1"
pkgdesc="GNU C Library compatibility layer"
arch="x86_64"
arch="aarch64"
url="https://github.com/sgerrand/alpine-pkg-glibc"
license="LGPL"
source="https://github.com/sgerrand/docker-glibc-builder/releases/download/$pkgver-$_pkgrel/glibc-bin-$pkgver-$_pkgrel-x86_64.tar.gz
source="./glibc-bin-$pkgver.tar.gz
ld.so.conf"
subpackages="$pkgname-bin $pkgname-dev $pkgname-i18n"
triggers="$pkgname-bin.trigger=/lib:/usr/lib:/usr/glibc-compat/lib"

package() {
mkdir -p "$pkgdir/lib" "$pkgdir/usr/glibc-compat/lib/locale" "$pkgdir"/usr/glibc-compat/lib64 "$pkgdir"/etc
mkdir -p "$pkgdir/lib" "$pkgdir/usr/glibc-compat/lib/locale" "$pkgdir"/usr/glibc-compat/lib64 "$pkgdir"/etc
cp -a "$srcdir"/usr "$pkgdir"
cp "$srcdir"/ld.so.conf "$pkgdir"/usr/glibc-compat/etc/ld.so.conf
rm "$pkgdir"/usr/glibc-compat/etc/rpc
Expand All @@ -25,8 +24,23 @@ package() {
rm -rf "$pkgdir"/usr/glibc-compat/lib/audit
rm -rf "$pkgdir"/usr/glibc-compat/share
rm -rf "$pkgdir"/usr/glibc-compat/var
ln -s /usr/glibc-compat/lib/ld-linux-x86-64.so.2 ${pkgdir}/lib/ld-linux-x86-64.so.2
ln -s /usr/glibc-compat/lib/ld-linux-x86-64.so.2 ${pkgdir}/usr/glibc-compat/lib64/ld-linux-x86-64.so.2

# 根据架构设置符号链接
case "$arch" in
x86_64)
ln -s /usr/glibc-compat/lib/ld-linux-x86_64.so.2 ${pkgdir}/lib/ld-linux-x86_64.so.2
ln -s /usr/glibc-compat/lib/ld-linux-x86_64.so.2 ${pkgdir}/usr/glibc-compat/lib64/ld-linux-x86_64.so.2
;;
aarch64)
ln -s /usr/glibc-compat/lib/ld-linux-aarch64.so.1 ${pkgdir}/lib/ld-linux-aarch64.so.1
ln -s /usr/glibc-compat/lib/ld-linux-aarch64.so.1 ${pkgdir}/usr/glibc-compat/lib64/ld-linux-aarch64.so.1
;;
*)
echo "not support: $arch"
exit 1
;;
esac

ln -s /usr/glibc-compat/etc/ld.so.cache ${pkgdir}/etc/ld.so.cache
}

Expand All @@ -43,8 +57,3 @@ i18n() {
mkdir -p "$subpkgdir"/usr/glibc-compat
cp -a "$srcdir"/usr/glibc-compat/share "$subpkgdir"/usr/glibc-compat
}

sha512sums="
0aff0ec76f4d341957a792b8635c0770148eba9a5cb64f9bbd85228c14d9cb93c1a402063cab533a9f536f5f7be92c27bc5be8ed13c2b4f7aa416510c754d071 glibc-bin-2.35-0-x86_64.tar.gz
2912f254f8eceed1f384a1035ad0f42f5506c609ec08c361e2c0093506724a6114732db1c67171c8561f25893c0dd5c0c1d62e8a726712216d9b45973585c9f7 ld.so.conf
"
75 changes: 75 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Stage 1: use docker-glibc-builder build glibc.tar.gz
FROM ubuntu:22.04 AS builder
LABEL maintainer="Sasha Gerrand <github+docker-glibc-builder@sgerrand.com>"
# 支持传递 GLIBC_VERSION 参数
ARG GLIBC_VERSION=2.39
ENV DEBIAN_FRONTEND=noninteractive \
GLIBC_VERSION=${GLIBC_VERSION} \
PREFIX_DIR=/usr/glibc-compat
RUN apt-get -q update \
&& apt-get -qy install \
bison \
build-essential \
gawk \
gettext \
openssl \
python3 \
texinfo \
wget
COPY configparams /glibc-build/configparams
COPY builder /builder
RUN /builder

# Stage 2: use docker-alpine-abuild package apk and keys
FROM alpine:3.20 AS packager
ARG GLIBC_VERSION=2.39
ARG ALPINE_VERSION=3.20
ARG TARGETARCH
RUN apk --no-cache add alpine-sdk coreutils cmake sudo bash \
&& adduser -G abuild -g "Alpine Package Builder" -s /bin/ash -D builder \
&& echo "builder ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
&& mkdir /packages \
&& chown builder:abuild /packages
COPY ./abuilder /bin/
USER builder
ENV PACKAGER="glibc@gliderlabs.com"
RUN abuild-keygen -na && sudo cp /home/builder/.abuild/${PACKAGER}-*.rsa.pub /etc/apk/keys/
WORKDIR /home/builder/package
COPY --from=builder /glibc-bin-${GLIBC_VERSION}.tar.gz /home/builder/package/
COPY . /home/builder/package/

ENV REPODEST=/packages
RUN case "$TARGETARCH" in \
amd64) export TARGET_ARCH="x86_64" ;; \
arm64) export TARGET_ARCH="aarch64" ;; \
*) echo "Unsupported architecture: $TARGETARCH" && exit 1 ;; \
esac && \
sed -i "s/^pkgver=.*/pkgver=${GLIBC_VERSION}/" APKBUILD && \
sed -i "s/^arch=.*$/arch=\"${TARGET_ARCH}\"/" APKBUILD && \
abuild checksum && abuilder -r && cp /packages/builder/${TARGET_ARCH}/*.apk /tmp/

# Stage 3: apk add apk, build alpine-glibc
FROM alpine:3.20
ARG GLIBC_VERSION=2.39
ARG TARGETARCH
ENV GLIBC_VERSION=${GLIBC_VERSION}
ENV PACKAGER="glibc@gliderlabs.com"

RUN case "$TARGETARCH" in \
amd64) export LD_LINUX_PATH="/lib/ld-linux-x86_64.so.2" ;; \
arm64) export LD_LINUX_PATH="/lib/ld-linux-aarch64.so.1" ;; \
*) echo "Unsupported architecture: $TARGETARCH" && exit 1 ;; \
esac

# 复制公钥和 glibc APK 包
COPY --from=packager /tmp/*.apk /tmp/
COPY --from=packager /home/builder/.abuild/${PACKAGER}-*.pub /etc/apk/keys/

# 安装 glibc APK
RUN apk add --no-cache gcompat && rm -rf ${LD_LINUX_PATH} && \
apk add --no-cache --force-overwrite /tmp/glibc-${GLIBC_VERSION}-*.apk && \
apk add --no-cache /tmp/glibc-bin-${GLIBC_VERSION}-*.apk && \
apk add --no-cache /tmp/glibc-i18n-${GLIBC_VERSION}-*.apk && \
rm -rf /tmp/*.apk

CMD ["/bin/sh"]
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This is the [GNU C Library](https://gnu.org/software/libc/) as a Alpine Linux pa

See the [releases page](https://github.com/sgerrand/alpine-pkg-glibc/releases) for the latest download links. If you are using tools like `localedef` you will need the `glibc-bin` and `glibc-i18n` packages in addition to the `glibc` package.

## Build

docker buildx build --platform linux/arm64,linux/amd64 --build-arg GLIBC_VERSION=2.39 -t alpine-glibc:2.39 .

## Installing

The current installation method for these packages is to pull them in using `wget` or `curl` and install the local file with `apk`:
Expand Down
24 changes: 24 additions & 0 deletions abuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env ash

set -e

main() {
RSA_FILE=$(ls /home/builder/.abuild/${PACKAGER}-*.rsa | head -n 1)
export PACKAGER_PRIVKEY="$RSA_FILE"

mkdir -p "$REPODEST" /home/builder/.abuild
abuild-apk update
[ "$RSA_PRIVATE_KEY" ] && {
echo -e "$RSA_PRIVATE_KEY" >"/home/builder/.abuild/$RSA_PRIVATE_KEY_NAME"
export PACKAGER_PRIVKEY="/home/builder/.abuild/$RSA_PRIVATE_KEY_NAME"
}
ls -lh /home/builder/.abuild
echo "PACKAGE_PRIVKEY ${PACKAGER_PRIVKEY}"
sudo chown -R builder:abuild /home/builder/package
sudo chown -R builder:abuild $REPODEST

# exec abuild -r clean
exec abuild "$@"
}

main "$@"
28 changes: 28 additions & 0 deletions builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -eo pipefail
[[ "$TRACE" ]] && set -x

main() {
declare version="${1:-$GLIBC_VERSION}" prefix="${2:-$PREFIX_DIR}"

: "${version:?}" "${prefix:?}"

{
wget -qO- "https://ftpmirror.gnu.org/libc/glibc-$version.tar.gz" |
tar zxf -
mkdir -p /glibc-build && cd /glibc-build
"/glibc-$version/configure" \
--prefix="$prefix" \
--libdir="$prefix/lib" \
--libexecdir="$prefix/lib" \
--enable-multi-arch \
--enable-stack-protector=strong
make --jobs=4 && make install
tar --dereference --hard-dereference -zcf "/glibc-bin-$version.tar.gz" "$prefix"
} >&2

# [[ $STDOUT ]] && cat "/glibc-bin-$version.tar.gz"
}

main "$@"
5 changes: 5 additions & 0 deletions configparams
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
slibdir=/usr/glibc-compat/lib
rtlddir=/usr/glibc-compat/lib
sbindir=/usr/glibc-compat/bin
rootsbindir=/usr/glibc-compat/bin
build-programs=yes