Skip to content

Commit

Permalink
ci: pack parted
Browse files Browse the repository at this point in the history
  • Loading branch information
2moe committed Apr 11, 2024
1 parent 403099a commit b060300
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 3 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/pack-parted.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: pack parted & sfdisk
# auto-task.start-build-time = ?

on:
# schedule:
# - cron: '30 20 20 */2 *'
push:
# branches: ["build"]
paths:
- .github/workflows/pack-parted.yml
- assets/parted/Dockerfile

jobs:
build:
strategy:
fail-fast: false
matrix:
builder: ["alpine:edge"]
arch: [ "x64", "x86", "s390x", "ppc64le", "armv7a", "arm64"]
include:
- arch: x64
oci_arch: amd64
# builder: ["alpine:edge"]
- arch: x86
oci_arch: 386
- arch: s390x
oci_arch: s390x
- arch: ppc64le
oci_arch: ppc64le
- arch: armv7a
oci_arch: arm/v7
- arch: arm64
oci_arch: arm64

- arch: mipsle
oci_arch: mipsle
builder: ["ghcr.io/2cd/debian:bookworm-mipsle"]
- arch: mipsbe
oci_arch: mips
builder: ["ghcr.io/2cd/debian:buster-mipsbe"]

runs-on: ubuntu-latest
defaults:
run:
shell: zsh --pipefail -fex {0}
env:
DOCKER_DIR: assets/parted

steps:
- name: install zsh
shell: sh -e {0}
run: ${{ vars.INSTALL_ZSH }}

- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/checkout@v4
with:
ref: build

- name: Build and push
uses: docker/build-push-action@v5
with:
context: ${{env.DOCKER_DIR}}
push: true
tags: ghcr.io/2cd/pkgs:parted-${{matrix.arch}}
build-args: |
TMM_ARCH=${{matrix.arch}}
BUILDER=${{matrix.builder}}
91 changes: 91 additions & 0 deletions assets/parted/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# syntax=docker/dockerfile:1

ARG BUILDER
ARG TMM_ARCH

FROM --platform=${BUILDPLATFORM} ghcr.io/2moe/zsh-static as zsh
FROM ghcr.io/2moe/zsh-static:${TMM_ARCH} as zsh_target
# ----------
FROM --platform=${BUILDPLATFORM} alpine:edge as patcher
RUN apk add patchelf
# ----------
FROM --platform=${TARGETPLATFORM} ${BUILDER} as builder
COPY --link --from=zsh /opt/bin/zsh /bin
WORKDIR /app/bin

RUN <<'INSTALL_PARTED'
#!/bin/zsh -fex
mkdir -p ../{lib,share}
pkg_mgr=apk
if (($+commands[apt-get])) {
apt-get update
pkg_mgr=dpkg
}
apt_i() {
apt-get install -y $*
}
for i (parted partprobe sfdisk) {
if [[ $i != partprobe ]] {
case $pkg_mgr {
(dpkg) apt_i $i || apt_i fdisk ;;
(apk) apk add $i ;;
}
hash -r
}
bin=$commands[$i]
cp -L $bin .

local -A map=($(
ldd $i | awk '{
printf("%s\n%s\n", $1, $(NF - 1))
}')
)
local -p i map

for src dst (${(kv)map}) {
case ${dst:t} {
(linux-vdso.so.*) continue ;;
}

cp -fL $dst ../lib/ ||:

lib_file=../lib/${src:t}

if [[ ! -e $lib_file ]] {
ln -svf ${dst:t} $lib_file
}
}
files=(../lib/ld-*-*.so.*)
print -R ${files[1]:t} > ../share/interpreter.txt
}
INSTALL_PARTED

FROM patcher as patched
COPY --link --from=zsh /opt/bin/zsh /bin
COPY --from=builder /app /app
WORKDIR /app/bin
RUN <<'PATCH_ELF'
#!/bin/zsh -fex
interpreter=$(< ../share/interpreter.txt)
vendor_dir=/var/lib/tmm/vendor
for i (parted partprobe sfdisk) {
patchelf --set-interpreter ${vendor_dir}/lib/$interpreter $i
patchelf --set-rpath ${vendor_dir}/lib:.:../lib $i ||:
tmpfile=$(mktemp)
> $tmpfile <<'XBIN'
#!/bin/sh
env LD_PRELOAD="" LD_LIBRARY_PATH="_VENDOR_/lib" "_VENDOR_/bin/_BIN_" "$@"
XBIN
sed -e "s@_VENDOR_@$vendor_dir@g" -e "s@_BIN_@$i@" -i $tmpfile
install -Dm755 $tmpfile ../xbin/$i
unlink $tmpfile
}
PATCH_ELF

# FROM patcher
FROM zsh_target
ARG VENDOR=/var/lib/tmm/vendor
COPY --from=patched /app ${VENDOR}
WORKDIR /bin
RUN ln -svf /opt/bin/busybox /bin/sh
WORKDIR ${VENDOR}/xbin
28 changes: 25 additions & 3 deletions assets/vm-minimal/libexec/resize-partition
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
#!/usr/bin/env zsh
set -fexo pipefail
# Depends: e2fsprogs-extra | e2fsprogs, sfdisk | fdisk (>= 2.26.2) | libfdisk1, parted (>= 3.2-17), awk, coreutils, util-linux
# Depends: e2fsprogs-extra | e2fsprogs, sfdisk | fdisk (>= 2.29) | libfdisk1, parted (>= 3.2-17), awk, coreutils, util-linux
# Recommends: btrfs-progs, mount
# ----------------
sfdisk=/sbin/sfdisk
resize2fs=/usr/sbin/resize2fs
sfdisk=/sbin/sfdisk
parted=/usr/sbin/parted
vendored_bin_dir=/var/lib/tmm/vendor/xbin

# fix ubuntu 15.04 ~ 16.10 & debian 8
#
# Use **VENDORED** binary as jessie's dependencies are too old.
() {
local pkg bin
for pkg (sfdisk parted) {
bin=${vendored_bin_dir}/$pkg
if [[ -e $bin ]] {
#
case $pkg {
(sfdisk) sfdisk=$bin ;;
(parted)
parted=$bin
# skip_check_parted=true
;;
}
}
}

}
# ----------------
# ----------------
typeset -x LC_ALL=C
Expand Down Expand Up @@ -130,7 +152,7 @@ if ((! $#disk_node_arr)) {
exit
}

partprobe
partprobe || ${vendored_bin_dir}/partprobe

# resize_file_system
() {
Expand Down

0 comments on commit b060300

Please sign in to comment.