Build a Hybrid Application beyond x86

Why do we need to consider Multiarch hybrid applications?

Past

Present

https://www.extremeit.com/cinebench-r15-intel-xeon-96-core-vs-amd-epyc-128-core/epyc-vs-xeon-742x382/

Future

Introducing Instruction set Architecture (ISA)

ISA landscape today

IBM Z

  • Strengths: Handle Intensive IO operations, such as Credit card swipes.
  • Definition in Linux: s390x
  • Trivia: In z/architecture, the Z stands to Zero downtime.

x86

  • Strengths: General purpose computing, the defacto standard for all software.
  • Definition in Linux: x86_64, amd64
  • Trivia: Even Intel is the one who created x86 and licensed to other companies such as AMD and Cyrix, AMD is the one who defines x86_64, the 64-bit extension, after the limited success of IA_64 in the consumer, and intel ended up license AMD64 from AMD.

Power ISA

  • Strengths: with IBM power 10, IBM claims its main advantage is to provide faster AI inference.
  • Definition in Linux: ppc64el
  • Trivia: Power2 was the CPU used in Deepblue, the first machine to win chess, Kasparov. Also, Power7 was the CPU behind the machine that won the first Jeopardy

ARM

  • Strengths: Power efficiency.
  • Definition in Linux: aarch64
  • Trivia: according to Steve Furber, the principal designer on ARM, when they received the first chip, they tested the power consumption and found it Zero, he reviewed the wiring, thinking that the meter is not connected correctly it turned out they did not connect the CPU to the power supply at all, because of the faulty board, and it is running only on the power coming from the input signal.

Options to build multiarch container images

  • Do nothing; It will work
  • Build everything on its dedicated machine
  • Cross Build and Cross-compiling
  • Userspace emulation

Options 1: Do nothing it will work

podman run -it python python -c 'print("Hello world!")'
FROM python
buildah build-using-dockerfile -t ahmadhassan83/simplypy86 
podman push
podman run ahmadhassan83/simplypy86 python -c 'print("Hello World")'
standard_init_linux.go:219: exec user process caused: exec format error

Options 2: Build everything on its dedicated machine

Hercules s390x emulation

CPU: SHA256-hashing 500 MB
284.661 seconds
CPU: bzip2-compressing 500 MB
271.677 seconds
CPU: AES-encrypting 500 MB
19.429 seconds

Qemu s390x emulation

CPU: SHA256-hashing 500 MB
18.163 seconds
CPU: bzip2-compressing 500 MB
66.803 seconds
CPU: AES-encrypting 500 MB
38.001 seconds

IBM Z Virtual machine on KVM

CPU: SHA256-hashing 500 MB
2.532 seconds
CPU: bzip2-compressing 500 MB
6.933 seconds
CPU: AES-encrypting 500 MB
0.351 seconds

Option 3: Cross Build and Cross-compiling

FROM python
buildah build-using-dockerfile --override-arch arm64  -t ahmadhassan83/simplypyarm  .
standard_init_linux.go:219: exec user process caused: exec format error
#include <stdio.h>int main() {
printf("Hello World!\n");
return 0;
}
aarch64-linux-gnu-gcc test.c -o test.aarch64
sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
FROM ubuntu
COPY test.aarch64 /usr/bin/test
CMD ["test"]
buildah build-using-dockerfile --override-arch arm64  -t ahmadhassan83/simple  .
podman push ahmadhassan83/simplec
FROM ubuntu
COPY test.aarch64 /usr/bin/test
RUN chmod 777 /usr/bin/test
CMD ["test"]
ahmed@ubuntu:~/simple$ buildah build-using-dockerfile --override-arch arm64  -t ahmadhassan83/simplec  .
STEP 1: FROM ubuntu
Getting image source signatures
Copying blob a970164f39c1 skipped: already exists
Copying blob e9c66f1fb5a2 skipped: already exists
Copying blob 94362ba2c285 [--------------------------------------] 0.0b / 0.0b
Copying config 1c28a15891 done
Writing manifest to image destination
Storing signatures
STEP 2: COPY test.aarch64 /usr/bin/test
STEP 3: RUN chmod 777 /usr/bin/test
standard_init_linux.go:211: exec user process caused "exec format error"
error building at STEP "RUN chmod 777 /usr/bin/test": error while running runtime: exit status 1
ERRO exit status 1

Option 4: User space emulation

sudo podman run --rm --privileged multiarch/qemu-user-static --reset -p yes

Testing Environment.

FROM ubuntu
RUN apt update
RUN apt -y install default-libmysqlclient-dev libulfius-dev uwsc gcc
COPY rest.c /root
WORKDIR /root
RUN gcc rest.c -o rest -L/usr/lib/`uname -m`-linux-gnu/libulfius.so -lulfius `mysql_config --cflags --libs`
ENTRYPOINT ["/root/rest"]
  • Kubernetes Cluster on ARM64 using VMware ESXi as Hypervisor
  • Mysql on ARM64 on Arm64 Virtual Machines
  • Single node Kubernetes Cluster and Mysql on x86 VM
  • Build the container image for AMD64 and ARM64
  • Push the container image to Docker Hub.
  • Create a manifest
  • Push the manifest
buildah bud --override-arch amd64 --os linux/amd64 -t ahmadhassan83/rest-arm64 .
buildah bud --override-arch amd64 --os linux/amd64 -t ahmadhassan83/rest-amd64 .
podman push ahmadhassan83/rest-arm64
podman push ahmadhassan83/rest-amd64
podman manifest create offeringapp
podman manifest add --arch arm64 offeringapp ahmadhassan83/rest-arm64
podman manifest add --arch amd64 offeringapp ahmadhassan83/rest-amd64
podman manifest push --all offeringapp docker://docker.io/ahmadhassan83/offeringapp:latest
archive/tar: invalid tar header: unknown
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx create --name mybuilder
docker buildx use mybuilder
docker buildx inspect --bootstrap
docker buildx build --platform linux/arm64,linux/amd64   --tag ahmadhassan83/myapprest . --push

Handling Databases

Automated Pipeline using Github actions.

name: ci

on:
push:

jobs:
buildx:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
-
name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build with buildx
run: |
docker buildx build --platform linux/arm64,linux/amd64 --tag ahmadhassan83/myapprest . --push

Conclusion

My current setup for ARM64

Raspberry PI 4 running VMware ESXi.

VMware ESXi Cluster

Using Lens IDE to Manage and operate two Kubernetes Clusters on x86 and ARM64

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store