Skip to content

Commit

Permalink
chore: dockerfile -> build.dockerfile; fix powerpc64le name
Browse files Browse the repository at this point in the history
  • Loading branch information
2moe committed Mar 28, 2024
1 parent 95849f5 commit 1a5b62f
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[options]
# Architecture = auto
Architecture = powerpc64
Architecture = powerpc64le
37 changes: 33 additions & 4 deletions src/cross-build-pacman/build
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,61 @@ local -A tmm_arch_map=(
ppc64 ppc64
loong64 loong64
i686 386
x64 amd64,x86_64
arm64 arm64,aarch64
)
get_region() {
language=$LANG[(ws^.^)1]
region=$language[(ws^_^)2]

# if region.is_empty()
if ((! #region)) {
region=US
}
print $region
}
main_repo=ghcr.io/2cd/pacman-static:cache
for tmm_arch oci_arch (${(kv)tmm_arch_map}) {
for tmm_arch archs (${(kv)tmm_arch_map}) {
if [[ ${ARCHIMG_TMM_ARCH} != $tmm_arch ]] {
continue
}
arch_arr=(${(s^,^)archs})
oci_arch=$arch_arr[1]
os_arch=$arch_arr[2]
if ((! #os_arch)) {
os_arch=$oci_arch
}

case $tmm_arch {
(i*86) repo_arch=x86 ;;
(i*86) repo_arch=x86 ;;
(*) repo_arch=$tmm_arch ;;
}

repo=${main_repo}-$repo_arch
args=(
build
--progress=plain
--file $src_dir/Dockerfile
#
--tag $repo
--build-arg
ARCH=$tmm_arch

--build-arg
OS_ARCH=$os_arch

--build-arg
REGION=$(get_region)

--platform=linux/$oci_arch
--file
)
case $tmm_arch {
(x64|arm64) args+=$src_dir/get.dockerfile ;;
(*) args+=$src_dir/build.dockerfile ;;
}

args+=$context
docker $args
docker push $repo
# docker push $repo
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ ARG ARCH
FROM ghcr.io/2cd/arch-dev:${ARCH} as dev
USER 0:0

ARG MAKECFG=makepkg.conf
COPY <<'NODEBUG' /tmp/_${MAKECFG}
ARG MK_CFG=makepkg.conf
ARG TMP_CFG=/tmp/_${MK_CFG}
COPY <<'NO_DEBUG' ${TMP_CFG}
OPTIONS+=('!debug')
MAKEFLAGS="-j$(nproc)"
NODEBUG
NO_DEBUG

ARG CFG=/etc/${MK_CFG}
RUN <<EOF
cat /tmp/_${MAKECFG} >> /etc/${MAKECFG}
cat /etc/${MAKECFG}
cat ${TMP_CFG} >> ${CFG}
cat ${CFG}
EOF

USER user:wheel
Expand All @@ -26,9 +28,11 @@ set -feo pipefail
$cmd
tar -xvf p.tgz
cd aur-pacman-static/
# sudo pacman -Sy
pacman-install openssl clang ||:
sed -E "/aarch64/ s@^(arch=).*@\1('riscv64' 'loong64' 'powerpc' 'powerpc64' 'powerpc64le' 'i486' 'i686' 'pentium4' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64')@" -i PKGBUILD
sudo pacman -Sy
# pacman-install openssl clang ||:

archs=('riscv64' 'loong64' 'powerpc' 'powerpc64' 'powerpc64le' 'i486' 'i686' 'pentium4' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64')
sed -E "/aarch64/ s@^(arch=).*@\1($archs)@" -i PKGBUILD
makepkg -s --noconfirm --skippgpcheck
sudo mkdir -p /app
sudo cp pkg/pacman-static/usr/bin/pacman-*static /app
Expand Down
53 changes: 53 additions & 0 deletions src/cross-build-pacman/get.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# syntax=docker/dockerfile:1
FROM --platform=${BUILDPLATFORM} ghcr.io/2moe/zsh-static as zsh-host
FROM ghcr.io/2moe/zsh-static as zsh
FROM --platform=${BUILDPLATFORM} curlimages/curl as pacman-app
# build-args:
ARG OS_ARCH
ARG REGION
COPY --from=zsh-host /opt/bin/zsh /app/
USER 0:0
# -----------------
RUN <<GET_PACMAN
#!/app/zsh
set -fexo pipefail

download() {
case $REGION {
(CN) local mirror_url=https://mirrors.tuna.tsinghua.edu.cn/arch4edu/${OS_ARCH}/ ;;
(*) local mirror_url=https://repository.arch4edu.org/${OS_ARCH}/ ;;
}
pkg=$(
awk_args=(
-F 'href='
'/pacman-static/ && !/\.sig|debug/ {
pkg_html = $2
} END {
split(pkg_html, pkg_arr, "\"")
print(pkg_arr[2])
}'
)
curl -L $mirror_url | awk $awk_args
)

case $pkg {
(pacman-static-*tar.*) ;;
(*) pkg=pacman-static-6.1.0-1-${OS_ARCH}.pkg.tar.zst ;;
}
curl -Lo $pkg ${mirror_url}${pkg}
}

extract_pkg() {
mkdir -p tmp
apk add libarchive-tools
bsdtar -C tmp -xf $pkg
for bin (pacman-static pacman-conf-static) {
mv -vf tmp/usr/bin/$bin /app/
}
}
download
extract_pkg
GET_PACMAN

FROM zsh
COPY --from=pacman-app /app/* /opt/bin/
6 changes: 3 additions & 3 deletions src/docker/build
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ for tmm_arch arch (${(kv)tmm_arch_map}) {
--build-arg
)
case $tmm_arch {
x64*) tmm_arch_v0=x64 ;;
i*86) tmm_arch_v0=x86 ;;
*) tmm_arch_v0=$tmm_arch;;
(x64*) tmm_arch_v0=x64 ;;
(i*86) tmm_arch_v0=x86 ;;
(*) tmm_arch_v0=$tmm_arch;;
}
args+=TMM_ARCH_V0=$tmm_arch_v0

Expand Down
51 changes: 2 additions & 49 deletions src/pacman-static/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,57 +1,10 @@
# syntax=docker/dockerfile:1
FROM ghcr.io/2cd/arch-slim:x64 as arch
FROM ghcr.io/2moe/zsh-static as zsh

# -----------------
# -----------------
FROM curlimages/curl as pacman-static
COPY --from=zsh /opt/bin/zsh /app/
USER 0:0
# build-args:
ARG OS_ARCH
ARG REGION
# -----------------
RUN <<GET_PACMAN
#!/app/zsh
set -fexo pipefail

download() {
case $REGION {
(CN) local mirror_url=https://mirrors.tuna.tsinghua.edu.cn/arch4edu/${OS_ARCH}/ ;;
(*) local mirror_url=https://repository.arch4edu.org/${OS_ARCH}/ ;;
}
pkg=$(
awk_args=(
-F 'href='
'/pacman-static/ && !/\.sig|debug/ {
pkg_html = $2
} END {
split(pkg_html, pkg_arr, "\"")
print(pkg_arr[2])
}'
)
curl -L $mirror_url | awk $awk_args
)

case $pkg {
(pacman-static-*tar.*) ;;
(*) pkg=pacman-static-6.1.0-1-${OS_ARCH}.pkg.tar.zst ;;
}
curl -Lo $pkg ${mirror_url}${pkg}
}

extract_pkg() {
mkdir -p tmp
apk add libarchive-tools
bsdtar -C tmp -xf $pkg
for bin (pacman-static pacman-conf-static) {
mv -vf tmp/usr/bin/$bin /app/
}
}
download
extract_pkg
GET_PACMAN

ARG ARCH
FROM ghcr.io/2moe/pacman-static:cache-${ARCH} as pacman-static
# -----------------
# -----------------
FROM zsh as ca-certs
Expand Down

0 comments on commit 1a5b62f

Please sign in to comment.