Local snapcraft build behind http proxy

I am currently in a situation where I have to build a package with snapcraft when forced to go through a corporate proxy. I always get stuck at some point where snapcraft tries to access the snap store. I currently do these settings ahead of snapcraft (don’t know if all of them are required):

export http_proxy="http://192.169.1.1:8888"
export https_proxy="http://192.169.1.1:8888"

sudo snap set system proxy.http="http://192.169.1.1:8888"
sudo snap set system proxy.https="http://192.169.1.1:8888"

sudo snap set multipass proxy.http="http://192.169.1.1:8888"
sudo snap set multipass proxy.https="http://192.169.1.1:8888"

…and also add on the snapcraft command line:

snapcraft --http-proxy="http://192.169.1.1:8888" --https-proxy="http://192.169.1.1:8888"

It does make a lot of progress actually, downloading .deb packages etc., but ultimately fails at this step:

error: cannot install "snapd": persistent network error: Post
       https://api.snapcraft.io/v2/snaps/refresh: dial tcp: lookup api.snapcraft.io: Temporary
       failure in name resolution
An error occurred when trying to execute 'sudo -H -i env SNAPCRAFT_BUILD_ENVIRONMENT=managed-host HOME=/root SNAPCRAFT_HAS_TTY=True http_proxy=http://192.169.1.1:8888 https_proxy=http://192.169.1.1:8888 snap install --channel stable snapd' with 'multipass': returned exit code 1.

This issue seems to be related, but here the problem is with apt, which seems to work for me:

I am out of ideas, can somebody help?

Kind regards
Julius

you could try using lxd instead of multipass …

Thanks for the suggestion, I tried it and the mileage is similar. Apt stuff works fine, but in the end this happens:

Unpacking apt-transport-https (1.6.12ubuntu0.1) ...
Setting up apt-transport-https (1.6.12ubuntu0.1) ...
Waiting for network to be ready...
Failed to setup networking.
error: cannot install "snapd": Post https://api.snapcraft.io/v2/snaps/refresh: dial tcp: lookup
       api.snapcraft.io on [fe80::216:3eff:fe25:e4de%39]:53: read udp
       [fe80::216:3eff:fef7:50bf%eth0]:60848->[fe80::216:3eff:fe25:e4de%eth0]:53: read: connection
       refused
An error occurred when trying to execute 'snap install --channel stable snapd' with 'LXD': returned exit code 1.

I set the proxy that lxd uses like this:

lxc config set core.proxy_http="http://192.169.1.1:8888"
lxc config set core.proxy_https="http://192.169.1.1:8888"
1 Like

I meanwhile succeeded by running this command (as mentioned in the first error message I posted) on the host system:

sudo -H -i env SNAPCRAFT_BUILD_ENVIRONMENT=managed-host HOME=/root SNAPCRAFT_HAS_TTY=True http_proxy=http://192.169.1.1:8888 https_proxy=http://192.169.1.1:8888 snap install --channel stable snapd

Does this make sense? I was somehow under the impression that this would need to run inside the multipass instance. And why does it succeed if I run it, but not if snapcraft runs it?

@julius I think you are hitting a bug that has a fix available (though not yet merged).

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

Can you try snap refresh snapcraft --channel edge/pr-3343 and see if it solves it for you?

FWIW, what you would need to do is configure snapd proxy inside the build container, something like:

lxc exec snapcraft-<project-name> snap set system proxy.http="http://192.169.1.1:8888"
lxc exec snapcraft-<project-name> snap set system proxy.https="http://192.169.1.1:8888"`

Hi CJ, thanks, thats good news! I will check it out.

FYI, at the moment it works in my own development environment (where I put myself behind a proxy to simulate the setup in a customer environment), but it does not work on the customer site. It fails when accessing the snap store (to probably check for updates of core18 etc.).

Anyway, maybe your suggestion fixes it. In the end, my mileage was better with multipass, is this the equivalent commands?:

multipass exec snapcraft-<project-name> snap set system proxy.http="http://192.169.1.1:8888"
multipass exec snapcraft-<project-name> snap set system proxy.https="http://192.169.1.1:8888"`

You would need to add “sudo” for multipass, e.g.:
multipass exec snapcraft- sudo snap set system proxy.http=“http://192.169.1.1:8888

It sounds like you are having trouble building a package with snapcraft when you are forced to go through a corporate proxy. You have tried a few different things but still have problems. I’m sorry to hear that you are having trouble. One thing you might want to try is using a different proxy server. If you are using a corporate proxy, they may be blocking access to the snap store. You could try using a different proxy server like UK socks proxy or VPN to see if that makes a difference. Another thing you might want to try is building the package on a different computer. If you can build the package on a different computer, that would probably be the easiest way to fix the problem.