Ant (and others?) fails using Docker image

Not sure this is the place for bug reporting, but the github doesn’t have the “Issues”.

Anyways, when running snapcraft in the docker image, it tries to install the required ant and dependencies. However, it doesn’t do an apt update and will fail with several 404 errors. For example, the libglib2.0-0 package is now in the repo as 2.48.2-0ubuntu4.1 instead of the 2.48.2-0ubuntu4 the image is looking for.

I assume this will be an issue when installing other plugins using stale apt data.

1 Like

Yes. snapcraft in Docker image is broken.

I don’t think that the image is broken, rather that the docs should be clearer in how to use the docker container.

When using the docker image to run snapcraft, one should always run apt update before running snapcraft, otherwise the sources from the image will be out of date and snapcraft when it goes to download packages will fail.

Why the image is not shipped with apt-get update command by default?

1 Like

The image doesn’t ship with a default command to run, so it just runs the inherited CMD or ENTRYPOINT from the ubuntu:16.04 docker image, which is just a shell.

That doesn’t answer the question why not to add apt update && snapcraft call as a default CMD?

I’ll let the snapcrafters team comment, as I don’t work on snapcraft…

It would make sense if that was the default behavior, but for my use cases I would want to be able to override that to not just always run apt update && snapcraft as sometimes I would want it to run something like snapcraft clean some-part && snapcraft

Perhaps some sort of entrypoint.sh script that by default runs apt update && snapcraft, but if you give it arguments then runs those commands in a shell instead like:

#!/bin/bash -e

if [ $# -ne 0 ]; then
    "$@"
else
    apt update
    snapcraft
fi

On the second thought if snapcraft is calling apt-get install then it should call apt update too. Or else install fails when snapcraft image gets stale.

1 Like

Well snapcraft doesn’t actually call apt install except for build-packages.

I don’t remember the exact internals but for stage-packages it just stages the packages into folders without actually installing them on the host, this way it doesn’t ever need sudo (which snapcraft would need in order to call apt update).

Yes, it fails.

And fails for build-packages.

So where is the code for build-packages to patch it with an extra apt-get update call?

I don’t think it’s enough to just patch the bit of snapcraft that handles build-packages to just also call apt update before calling apt install, as other operations that snapcraft does when building a snap need to use apt something-something as well, which can fail if the cache is out of date.

I think the ideal solution is to implement a default command for the snapcraft docker image rather than have snapcraft call apt update before every single apt operation snapcraft does, as then it would constantly need to use sudo with snapcraft, which is undesirable for local development.

You’re free to propose such a PR at the snapcraft github here: https://github.com/snapcore/snapcraft
As mentioned I don’t work on snapcraft and so I don’t know where such a PR would go nor do I have the time to propose it myself unfortunately.

I can not locate the code that handles apt install part. Can you?

Took me 20 minutes.

Now working on a patch.

An hour later I’ve got a patch.

https://github.com/snapcore/snapcraft/pull/2389

1 Like