We build a docker image for snapcraft on arm64 architecture using the following docker file
### snapcraft installation start via builder image###
FROM ubuntu:22.04 as builder
## setup apt and install packages
RUN DEBIAN_FRONTEND="noninteractive" apt-get update -y
RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y \
curl \
jq \
squashfs-tools
ENV UBUNTU_STORE_ARCH=arm64
# Grab the core20 snap (which snapcraft uses as a base) from the stable channel
# and unpack it in the proper place.
# RUN snap download core20 --basename=core20
RUN curl -L $(curl -H 'X-Ubuntu-Series: 16' -H 'X-Ubuntu-Architecture: arm64' 'https://api.snapcraft.io/api/v1/snaps/details/core20' | jq '.download_url' -r) --output core20.snap
RUN mkdir -p /snap/core20
RUN unsquashfs -d /snap/core20/current core20.snap
# Grab the core22 snap (which snapcraft uses as a base) from the stable channel
# and unpack it in the proper place.
# RUN snap download core22 --basename=core22
RUN curl -L $(curl -H 'X-Ubuntu-Series: 16' -H 'X-Ubuntu-Architecture: arm64' 'https://api.snapcraft.io/api/v1/snaps/details/core22' | jq '.download_url' -r) --output core22.snap
RUN mkdir -p /snap/core22
RUN unsquashfs -d /snap/core22/current core22.snap
# Grab the snapcraft snap from the stable channel and unpack it in the proper place
# RUN snap download snapcraft --basename=snapcraft --channel=6.x/stable
RUN curl -L -H 'Snap-CDN: none' $(curl -H 'X-Ubuntu-Series: 16' -H 'X-Ubuntu-Architecture: arm64' 'https://api.snapcraft.io/api/v1/snaps/details/snapcraft?channel=7.x/stable' | jq '.download_url' -r) --output snapcraft.snap
# RUN curl -L -H 'Snap-CDN: none' $(curl -H 'X-Ubuntu-Series: 16' -H 'X-Ubuntu-Architecture: arm64' 'https://api.snapcraft.io/api/v1/snaps/details/snapcraft?channel=6.x/stable' | jq '.download_url' -r) --output snapcraft.snap
RUN mkdir -p /snap/snapcraft
RUN unsquashfs -d /snap/snapcraft/current snapcraft.snap
# Fix Python3 installation: Make sure we use the interpreter from
# the snapcraft snap:
RUN unlink /snap/snapcraft/current/usr/bin/python3
RUN ln -s /snap/snapcraft/current/usr/bin/python3.* /snap/snapcraft/current/usr/bin/python3
RUN echo /snap/snapcraft/current/lib/python3.*/site-packages >> /snap/snapcraft/current/usr/lib/python3/dist-packages/site-packages.pth
# Create a snapcraft runner
RUN mkdir -p /snap/bin
RUN echo "#!/bin/sh" > /snap/bin/snapcraft
RUN snap_version="$(awk '/^version:/{print $2}' /snap/snapcraft/current/meta/snap.yaml)" && echo "export SNAP_VERSION=\"$snap_version\"" >> /snap/bin/snapcraft
RUN echo 'exec "$SNAP/usr/bin/python3" "$SNAP/bin/snapcraft" "$@"' >> /snap/bin/snapcraft
RUN chmod +x /snap/bin/snapcraft
# Multi-stage build, only need the snaps from the builder. Copy them one at a
# time so they can be cached.
################ Ubuntu image ################
FROM ubuntu:22.04
COPY --from=builder /snap/core20 /snap/core20
COPY --from=builder /snap/core22 /snap/core22
COPY --from=builder /snap/snapcraft /snap/snapcraft
COPY --from=builder /snap/bin/snapcraft /snap/bin/snapcraft
# Generate locale
RUN DEBIAN_FRONTEND="noninteractive" apt-get update -y
RUN DEBIAN_FRONTEND="noninteractive" apt install -y \
sudo \
snapd \
locales
RUN locale-gen en_US.UTF-8
# Set the proper environment
ENV LANG="en_US.UTF-8"
ENV LANGUAGE="en_US:en"
ENV LC_ALL="en_US.UTF-8"
ENV PATH="/snap/bin:$PATH"
ENV SNAP="/snap/snapcraft/current"
ENV SNAP_NAME="snapcraft"
ENV SNAP_ARCH="arm64"
# check snapcraft installation
RUN snapcraft --help
The docker build command runs successfully. On runtime, we use snapcraft in desctuctive mode and get the error
Failed to refresh package list: failed to run apt update.
We are running the container as non-root user.
It seems to be an issue w.r.t. to apt update and sudo.
Remark: The same docker image based on Ubuntu focal on arm64 runs just fine.
Remark: The same docker image based on Ubuntu jammy on amd64 runs just fine.