Snap folder empty after prime stage

What happened?

Snap folder is empty after prime stage is complete which is why Snap packaging process fails.

What is expected ?

Contents of prime folder should get copied to final snap folder according to the default behaviour of Snapcraft lifecycle.

parts:
  my-part:
    plugin: dump
    source: https://github.com/my-repo/my-project.git
    source-branch: master
    source-type: git
    build-packages:
      - locales
      - gnupg2
      - build-essential
      - zlib1g-dev
      - libgmp-dev
      - nodejs
      - npm
      - openssl
      - libsodium23
      - libsodium-dev
      - autoconf-archive
      - libcmocka0
      - libcmocka-dev
      - procps
      - pkg-config
      - gcc
      - libtool
      - automake
      - libssl-dev
      - uthash-dev
      - autoconf
      - doxygen
      - libjson-c-dev
      - libini-config-dev
      - libcurl4-openssl-dev
      - acl
      - git
      - wget
      - esl-erlang
      - elixir
    build-environment:
      - DEBIAN_FRONTEND: 'noninteractive'
      - LANG: 'en_US.UTF-8'
      - MIX_ENV: 'prod'
      - MIX_HOME: '/root/.mix'
      - CFLAGS: ''
      - CPPFLAGS: ''
      - CXXFLAGS: ''
      - LDFLAGS: ''
      - PKG_CONFIG_PATH: ''
    stage-packages:
      - esl-erlang
      - elixir
      - openssl
      - scylla
      - openjdk-8-jre-headless
      - libsodium23
      - libwxgtk-webview3.0-gtk3-0v5
      - libglu1-mesa
      - unixodbc-dev
      - tpm2-tools
    override-build: |
      locale-gen en_US.UTF-8
      wget https://github.com/tpm2-software/tpm2-tss/releases/download/3.1.0/tpm2-tss-3.1.0.tar.gz
      tar -xf tpm2-tss-3.1.0.tar.gz --one-top-level=tpm2-tss --strip-components 1
      cd tpm2-tss
      ./configure --with-udevrulesdir=/etc/udev/rules.d
      make -j$(nproc) 
      make install
      sed -i "s/tss/$(whoami)/gi" /etc/udev/rules.d/tpm-udev.rules
      udevadm control --reload-rules
      udevadm trigger
      ldconfig
      apt install -y tpm2-tools
      cd -
      make
      mix local.hex --if-missing --force &
      wait $!
      mix local.rebar --if-missing --force &
      wait $!
      mix deps.get &
      wait $!
      cd assets
      npm install
      npm ci
      npm run deploy
      cd -
      mix phx.digest &
      wait $!
      mix distillery.release &
      wait $!
      VERSION=$(grep 'version:' mix.exs | cut -d '"' -f2)
      tar zxvf _build/prod/rel/my-project/releases/$VERSION/my-app.tar.gz -C $SNAPCRAFT_PART_INSTALL/

OUTPUT

snapcraft --use-lxd --debug --shell-after
Launching a container.
Waiting for container to be ready
Waiting for network to be ready...
Skipping pull my-part (already ran)
Skipping build my-part (already ran)
Skipping stage my-part (already ran)
Skipping prime my-part (already ran)
Failed to generate snap metadata: The specified command '$SNAP/bin/my-app' defined in the app 'my-app' does not exist.
Ensure that '$SNAP/bin/my-app' is installed with the correct path.

what do you get when running:

find prime/ -name '*my-app*'

… in the toplevel of your build tree … note that the snap/ directory in your build tree only holds metadata files, nothing gets copied around, the prime/ dir is actually used directly by the snap pack command for all payload data when creating the snap. your command: entry needs to point to the correct path relative to the prime directory …

Fixed the issue by changing $SNAP/bin/my-app to bin/my-app in app command.

1 Like