toy / image_optim_pack

Precompiled binaries for image_optim
https://github.com/toy/image_optim
Other
77 stars 13 forks source link

Debian [ARM64] `jpeg-recompress` and `oxipng` require `/lib64/ld-linux-x86-64.so.2` #26

Closed the-teacher closed 1 year ago

the-teacher commented 1 year ago

MacOS, M1 pro processor

For documenting a case, without expectation for a solution. Task can be closed anytime.

Technically I build Debian, but for ARM

# docker build -t images.arm64 -f Dockerfile --build-arg BUILDPLATFORM="linux/arm64" ../
# docker push images.arm64
# docker run -ti images.arm64 bash

Dockerfile

FROM ghcr.io/toy/image_optim:20230129-debian as image_optim

# Debian GNU/Linux 11 (bullseye)
FROM --platform=$BUILDPLATFORM ruby:3.2
ARG BUILDPLATFORM
RUN echo "$BUILDPLATFORM" > /BUILDPLATFORM

RUN apt-get update

# Can be installed via apt-get
RUN apt-get install -y \
    advancecomp \
    gifsicle \
    jhead \
    jpegoptim \
    libjpeg-progs \
    optipng \
    pngcrush \
    pngquant

# Next things I copy from `image_optim` to save efforts

# It is fine
COPY --from=image_optim /usr/local/bin/pngout          /usr/bin/
# /lib64/ld-linux-x86-64.so.2
COPY --from=image_optim /usr/local/bin/jpeg-recompress /usr/bin/
# /lib64/ld-linux-x86-64.so.2
COPY --from=image_optim /usr/local/bin/oxipng          /usr/bin/
# oxipng -v
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

ld-linux-x86-64.so.2 exists for amd/386, but can not be installed for arm64 platform.

https://packages.debian.org/search?searchon=contents&keywords=ld-linux-x86-64.so.2

So, for now I do not see options to install jpeg-recompress and oxipng on debian under arm64

the-teacher commented 1 year ago

Stupid things like

root@c0bf955fee2a:/tmp# ln -s  /lib/ld-linux-aarch64.so.1 /lib64/ld-linux-x86-64.so.2
root@c0bf955fee2a:/tmp# oxipng -v
qemu-x86_64: /lib64/ld-linux-x86-64.so.2: Invalid ELF image for this architecture

give nothing

toy commented 1 year ago

I think building everything using make docker-build should work, did you try it?

the-teacher commented 1 year ago

@toy No I didn't try. I do not know what exactly you mean.

the-teacher commented 1 year ago

Looks like you mean makefile from your project. Now I see it. Looks like I need to have docker in a target container to and to run your Makefile. I will try

the-teacher commented 1 year ago

Btw, I even tried install oxipng via brew and to copy it to Debian arm64 container. Of course it didn't work :D But I was very curious about it

the-teacher commented 1 year ago

Ok. jpeg-recompress works if fully compile it under arm64

oxipng is next to check

#
# docker build -t jpeg-recompress -f Dockerfile --build-arg BUILDPLATFORM="linux/arm64" .
# docker -ti run jpeg-recompress bash

FROM --platform=$BUILDPLATFORM debian:bullseye
ARG BUILDPLATFORM

ENV LD_LIBRARY_PATH=/usr/local/lib
WORKDIR /tmp

RUN apt-get update && apt-get install -y build-essential cmake nasm bash findutils
RUN apt-get install -y wget

COPY extract ./
ENV CPATH=/usr/local/include

# libmozjpeg
RUN wget https://github.com/mozilla/mozjpeg/archive/v4.1.1.tar.gz
RUN mv v4.1.1.tar.gz libmozjpeg-4.1.1.tar.gz

RUN mkdir -p build/libmozjpeg
RUN tar -C build/libmozjpeg --strip-components=1 -xzf libmozjpeg-4.1.1.tar.gz

RUN cd build/libmozjpeg && cmake -DPNG_SUPPORTED=0 . && make install

# jpegarchive
RUN wget https://github.com/danielgtaylor/jpeg-archive/archive/v2.2.0.tar.gz
RUN mv v2.2.0.tar.gz jpegarchive-2.2.0.tar.gz

RUN mkdir -p build/jpegarchive
RUN tar -C build/jpegarchive --strip-components=1 -xzf jpegarchive-2.2.0.tar.gz

RUN cd build/jpegarchive && CFLAGS=-fcommon make install

# cat /etc/os-release

# PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
# NAME="Debian GNU/Linux"
# VERSION_ID="11"
# VERSION="11 (bullseye)"
# VERSION_CODENAME=bullseye
# ID=debian
# HOME_URL="https://www.debian.org/"
# SUPPORT_URL="https://www.debian.org/support"
# BUG_REPORT_URL="https://bugs.debian.org/"

# uname -m

# aarch64
the-teacher commented 1 year ago

Ok. After I recompiled everything manually with BUILDPLATFORM="linux/arm64" . and moved compiled files to a tagert container with linux/arm64 - I found that it started to work.

Now I'm going to cleanup my project's Dockerfile and have flash royal for Debian amd/arm

my Dockerfile for experiments.

#
# docker build -t image_processors -f Dockerfile --build-arg BUILDPLATFORM="linux/arm64" .
# docker -ti run image_processors bash

FROM --platform=$BUILDPLATFORM debian:bullseye
ARG BUILDPLATFORM

ENV LD_LIBRARY_PATH=/usr/local/lib
WORKDIR /tmp

RUN apt-get update && apt-get install -y build-essential cmake nasm bash findutils
RUN apt-get install -y wget

COPY extract ./
ENV CPATH=/usr/local/include

# libmozjpeg
RUN wget https://github.com/mozilla/mozjpeg/archive/v4.1.1.tar.gz
RUN mv v4.1.1.tar.gz libmozjpeg-4.1.1.tar.gz

RUN mkdir -p build/libmozjpeg
RUN tar -C build/libmozjpeg --strip-components=1 -xzf libmozjpeg-4.1.1.tar.gz

RUN cd build/libmozjpeg && cmake -DPNG_SUPPORTED=0 . && make install

# jpegarchive
RUN wget https://github.com/danielgtaylor/jpeg-archive/archive/v2.2.0.tar.gz
RUN mv v2.2.0.tar.gz jpegarchive-2.2.0.tar.gz

RUN mkdir -p build/jpegarchive
RUN tar -C build/jpegarchive --strip-components=1 -xzf jpegarchive-2.2.0.tar.gz

RUN cd build/jpegarchive && CFLAGS=-fcommon make install

# oxipng
FROM  rust:1 as oxipng
RUN apt-get update && apt-get install -y build-essential

RUN wget https://github.com/shssoichiro/oxipng/archive/refs/tags/v8.0.0.tar.gz
RUN mv v8.0.0.tar.gz oxipng-v8.0.0.tar.gz

RUN mkdir -p build/oxipng
RUN tar -C build/oxipng --strip-components=1 -xzf oxipng-v8.0.0.tar.gz
RUN cd build/oxipng && cargo build --release && install -c target/release/oxipng /usr/local/bin
# cargo --version
# cargo 1.67.0 (8ecd4f20a 2023-01-10)