Best Way to Build Balena Images in Gitlab CI

Hello!

I use Balena to deploy software to Jetson TX2 devices. Our Docker images are hosted in GItlab, and I would like a way to build the docker image in the Gitlab CI system. However, I can’t seem to get ROS to install correctly.

My gitlab CI config is this:

image: "docker:19"

docker_image:
  services:
    - docker:dind
  script:
    - cd $CI_PROJECT_DIR/src/payload
    - docker build --file Dockerfile.baseImage --tag CIimage

However, when I run it, I get the following error:

Unpacking ros-melodic-ros-base (1.4.1-0bionic.20200531.064541) ...
[2759](https://gitlab.com/br_consultants/consultants_repo/-/jobs/669069689#L2759)Errors were encountered while processing:
[2760](https://gitlab.com/br_consultants/consultants_repo/-/jobs/669069689#L2760) /tmp/apt-dpkg-install-PLJoTI/051-humanity-icon-theme_0.6.15_all.deb
[2761](https://gitlab.com/br_consultants/consultants_repo/-/jobs/669069689#L2761)E: Sub-process /usr/bin/dpkg returned an error code (1)
[2762](https://gitlab.com/br_consultants/consultants_repo/-/jobs/669069689#L2762)The command '/bin/sh -c apt-get install -y ros-melodic-ros-base' returned a non-zero code: 100
[2764](https://gitlab.com/br_consultants/consultants_repo/-/jobs/669069689#L2764)ERROR: Job failed: exit code 100

I’ve currently been using the FROM balenalib/aarch64-ubuntu:bionic image and I’ve surrounded my installation calls with the RUN [ “cross-build-start” ] and RUN [ “cross-build-end” ] commands.

Which I thought would handle the emulation. Any advice on what I’m doing wrong?

Hi @keenanbedrock,

I build a bunch of images from Balena base images using gitlab CI without too much incident. Take a look at my gitlab CI config[1]. Of particular interest I think are the environment variables which I set near the top.

Be careful if you are using gitlab’s shared runners that qemu-based emulated builds seem to be much slower and use a lot more ram. I’ve also managed to run the builder out of disk space before, which is why I have my own runners.

Hope that helps.
James.

1: https://gitlab.com/jimsy/balena-erlang/-/blob/master/.gitlab-ci.yml

Thanks yeah that was super helpful!

10/10 recommend your own runners. Gitlab’s cross-architecture CI files are tricky to set up (as mentioned above). We just have a farm of Raspberry Pi’s and I’m working on getting a TX2 into the runner fleet as well. It’s well worth it.

I did that a few days ago and went for building the images with docker buildx, “buildx” is a plugin for docker to build images in different architectures

gitlab-ci.yml exemple (for a runner using the host docker daemon with buildx installed):

build:
  tags:
    - buildx
  image: jdrouet/docker-with-buildx:stable
  before_script:
    - echo $REGISTRY_TOKEN | docker login --username $REGISTRY_USERNAME --password-stdin
  script:
    - docker buildx build
      --platform linux/aarch64
      --cache-from type=registry,ref=my-org/my-image:my-tag-cache
      --cache-to type=registry,ref=my-org/my-image:my-tag-cache,mode=max
      --push
      --tag my-org/my-image:my-tag-latest
      --tag my-org/my-image:my-tag-$CI_COMMIT_SHA
      .