Is it possible to build and test my project in docker container with s390x architecture?

Hi all. I would like to build and test my project for s390x architecture.
What is supposed way to do that on CircleCI?
As I understand it is not allowed that docker container would have architecture other than amd64.
If it is already described somewhere in documentation give me a reference please.

EDIT: As I understand it now one of the ways would be to run my docker container with s390x architecture inside linux machine image. So I will try this way but if you have any suggestions or examples feel free to share them with me.

You mean using emulation with QEMU? Because circleci does not provide s390x machines.

To use QEMU, you’d do (you can test it locally on your Linux PC):

docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
sudo docker run --rm -it --platform linux/s390x s390x/ubuntu:22.04 uname -a

So in your yaml, you should use a Linux x86 machine and run your s390x docker image with QEMU like this:

      image: ubuntu-2004:current

      - checkout
      - run:
          command: |
            docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
            docker run --rm --platform linux/s390x \
              bash -c '(
                set -ex
                in the container

I haven’t tried it myself in CircleCI, but this is how you usually do it. There might an orb that makes this prettier, not sure.

Needless to say, this is going to be very slow, since you’re emulating s390x on an Intel-based machine.

@RealNC Thank you very much. I have already solved my problem in the same way as you suggest.

  1. Cd to directory with my Dockerfile with this content:
FROM ubuntu@sha256:c18eff699e090d6b0336dda55b9f83cbbdf126100aa06d16de4fc58e2fa740df

RUN apt update && apt upgrade -y \
    && apt-get install -y build-essential libssl-dev \
    && apt-get install -y ninja-build \
    && apt install git -y
RUN apt install wget -y \
    && cd /tmp \
    && wget \
    && tar -zxvf cmake-3.23.1.tar.gz \
    && cd cmake-3.23.1 \
    && ./bootstrap \
    && make \
    && make install \
    && cd /tmp \
    && rm -rf * \
    && apt-get purge --auto-remove wget -y \
    && apt-get clean \
    && apt-get autoclean
LABEL description="This image derived from official ubuntu 22.04 and in addition contains build-essential tools(gcc 11.2.0), cmake-3.23.1, ninja and git"
RUN mkdir -p /home/projects

WORKDIR /home/projects

and build and push to dockerhub image for s390x architecture: docker buildx build --platform linux/s390x --tag rokodev/ubuntu2204-dev:1.0 --push .

  1. Then add to my .circleci/config.yml new job to build and run tests using docker image created in previous step:
version: 2.1

      image: ubuntu-2004:202201-01
    resource_class: large
      - run: printenv
      - run:
          name: Login to Dockerhub
          command: |
            echo "$DOCKERHUB_PULL_TOKEN" | docker login --username $DOCKERHUB_LOGIN --password-stdin
      - run:
          name: Enable run containers with different architectures
          command: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
      - run:
          name: Run docker container for s390x
          command: docker run -it -d --platform linux/s390x --name ubuntu_z rokodev/ubuntu2204-dev:1.0
      - run:
          name: Checkout sources
          command: |
            docker exec -it ubuntu_z bash -c "git clone -b ${CIRCLE_BRANCH} --single-branch ${CLONE_URL}"
      - run:
          name: Configure, build and test ninja-gnu-Debug
          command: |
            docker exec -it ubuntu_z bash -c "cd $CIRCLE_PROJECT_REPONAME; cmake --preset=ninja-gnu-Debug"
            docker exec -it ubuntu_z bash -c "cd $CIRCLE_PROJECT_REPONAME; cmake --build --preset=ninja-gnu-Debug"
            docker exec -it ubuntu_z bash -c "cd $CIRCLE_PROJECT_REPONAME; ctest --preset=ninja-gnu-Debug"
      - run:
          name: Configure, build and test ninja-gnu-Release
          command: |
            docker exec -it ubuntu_z bash -c "cd $CIRCLE_PROJECT_REPONAME; cmake --preset=ninja-gnu-Release"
            docker exec -it ubuntu_z bash -c "cd $CIRCLE_PROJECT_REPONAME; cmake --build --preset=ninja-gnu-Release"
            docker exec -it ubuntu_z bash -c "cd $CIRCLE_PROJECT_REPONAME; ctest --preset=ninja-gnu-Release"

      - ubuntu_s390x:
            - roko
                - develop

Yes, this is not so fast(in my case 09:30 minutes for s390x vs 1:30 for x86) but it works which makes me very happy)
This is reference to my final .circleci/config.yml file: rabbit/config.yml at master · rokoDev/rabbit · GitHub . Its not perfect but just in case this information could be useful for someone I leave it here.

Just in case you didn’t know, and since you’re already enabling DOCKER_BUILDKIT, you might as well get rid of the old way of executing RUN commands with all the \ && annoyance, and instead use the #syntax directive to enable “heredoc” support in RUN statements, with set -ex taking care of printing each command when it’s executed and exiting immediately when a command fails. This makes it easier to write RUN commands that look like proper scripts:

# syntax=docker/dockerfile:1.4
FROM ubuntu@sha256:c18eff699e090d6b0336dda55b9f83cbbdf126100aa06d16de4fc58e2fa740df

    set -ex
    apt update
    apt upgrade -y
    apt-get install -y \
        build-essential \
        git \
        libssl-dev \
        ninja-build \
1 Like

@RealNC thank you again. I didn’t know about that.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.