$ docker run -it -v /home/anatoli/experiment:/home/anatoli/experiment -w /home/anatoli/experiment snapcore/snapcraft:stable snapcraft push filename.snap
...
Preparing to push 'filename.snap' to the store.
No valid credentials found. Have you run "snapcraft login"?
Invalid credentials: Root macaroon not in the config file. Have you run "snapcraft login"?
I guess login info doesn’t persist between runs. Is there a way to fix that?
Well of course not, you’re starting a new container each time you run docker run. This is more of a Docker-specific problem and unrelated to snapcraft, but I’ll still try to help. Docker containers are by default stateless, so they don’t remember anything between multiple launches. You could try:
$ docker run -it -v $(pwd):$(pwd) -w $(pwd) snapcore/snapcraft:stable bash -c read
# This command won't return, so move to a different terminal
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
34d6073caa7a snapcore/snapcraft:stable "bash -c read" 45 seconds ago Up 44 seconds elastic_jang
# find the snapcraft container id from the output - 34d6073caa7a in this example
$ docker exec 34d6073caa7a snapcraft login
$ docker exec 34d6073caa7a snapcraft push
# back in the first terminal press `enter` to close the container
Alternatively spawn a shell on the first invocation and do everything inside the container without multiple docker calls:
$ docker run --rm -it -v $(pwd):$(pwd) -w $(pwd) snapcore/snapcraft:stable bash
# you're now inside the container
$ snapcraft login
$ snapcraft push
$ exit # leave the container which will clean up the environment due to --rm above
If login information is saved to disk, then can I map the dir with config inside container with volume on the host? I looked a little bit, but couldn’t find where the config is stored.
EDIT: Found some information about config at Snapcraft LXD container configuration - need to check that. There is also snap/.snapcraft/state in my local folder, but it doesn’t contain authentication credentials.
And thanks for the hint - it helped a lot - I completely forgot that I can run bash in Docker in interactive mode to execute other commands. All different wrappings of snapcraft in those modes need a diagram to understand what’s going on under the hood. I guess snapcraft could relaunch itself in Docker with additional SNAPCRAFT_BUILD_ENVIRONMENT=docker option. But that needs a diagram, because troubleshooting things after is not easy.