Snapping a python app that calls bash scripts

Hi, I developped a python application that calls bash scripts.

The structure looks like this (ls -R *) :

requirements.txt

assets: armox_icon.png

cis: linux_test_all.sh

data: os_config.ini

snap: snapcraft.yaml

src: main.py

My snapcraft.yaml file looks like this :

name: hardenos

base: core22

version: '0.1'

summary: a python and bash hardening app

description: hardenos is a powerful and versatile tool designed to automate and streamline the process of hardening operating systems 

grade: devel
confinement: devmode

parts:
  hardenos:
    plugin: python
    source: .
    source-type: local
    python-requirements: [requirements.txt]

  scripts:
    plugin: dump
    source: ./cis
    organize:
      centos7_test_all.sh: usr/bin/centos7_test_all.sh

apps:
  hardenos:
    command: usr/bin/python3 $SNAP/main.py

Using the --verbose and --debug arguments, I copied the last log traces that showed up to me when failed:

Creating snap package… Command β€˜[β€˜snap’, β€˜pack’, β€˜β€“filename’, β€˜hardenos_0.1_amd64.snap’, β€˜β€“compression’, β€˜xz’, PosixPath(’/root/prime’), PosixPath(β€˜/root/project’)]’ returned non-zero exit status 1. Launching shell on build environment…

I appreciate all recommendations and support from the community , thank you.

Hi @Chawpe .

The error could emanate of the python file itself or the bash one . I need more information.

Command lines cannot have /usr/bin/python3 ${SNAP}/main.py… add

/usr/bin/env python3 at the first line, or use the shell file as command.

I think you should do this instead (at the level of the concerned section)

apps:
  hardenos:
    command: /usr/bin/python3 $SNAP/main.py

The absolute path.

This is a full trace logs generated when adding --verbose argument:

Starting Snapcraft 8.0.2
Logging execution to '/home/chawpe/.local/state/snapcraft/log/snapcraft-20240204-125304.649819.log'
Running on amd64 for amd64
Launching instance...
Creating instance from base instance
Starting instance
Starting Snapcraft 8.0.2
Logging execution to '/tmp/snapcraft.log'
Running on amd64 for amd64
Initializing parts lifecycle
Installing build-packages
Installing build-snaps
Pulling hardenos
Pulling scripts
Building hardenos
:: + python3 -m venv /root/parts/hardenos/install
:: + PARTS_PYTHON_VENV_INTERP_PATH=/root/parts/hardenos/install/bin/python3
:: + /root/parts/hardenos/install/bin/pip install -U pip setuptools wheel
:: Requirement already satisfied: pip in /root/parts/hardenos/install/lib/python3.10/site-packages (22.0.2)
:: Collecting pip
::   Downloading pip-24.0-py3-none-any.whl (2.1 MB)
::      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 986.0 kB/s eta 0:00:00
:: Requirement already satisfied: setuptools in /root/parts/hardenos/install/lib/python3.10/site-packages (59.6.0)
:: Collecting setuptools
::   Downloading setuptools-69.0.3-py3-none-any.whl (819 kB)
::      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 819.5/819.5 KB 1.1 MB/s eta 0:00:00
:: Collecting wheel
::   Downloading wheel-0.42.0-py3-none-any.whl (65 kB)
::      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 65.4/65.4 KB 1.1 MB/s eta 0:00:00
:: Installing collected packages: wheel, setuptools, pip
::   Attempting uninstall: setuptools
::     Found existing installation: setuptools 59.6.0
::     Uninstalling setuptools-59.6.0:
::       Successfully uninstalled setuptools-59.6.0
::   Attempting uninstall: pip
::     Found existing installation: pip 22.0.2
::     Uninstalling pip-22.0.2:
::       Successfully uninstalled pip-22.0.2
:: Successfully installed pip-24.0 setuptools-69.0.3 wheel-0.42.0
:: + /root/parts/hardenos/install/bin/pip install -U -r requirements.txt
:: Collecting tabulate (from -r requirements.txt (line 1))
::   Downloading tabulate-0.9.0-py3-none-any.whl (35 kB)
:: Collecting rich (from -r requirements.txt (line 2))
::   Downloading rich-13.7.0-py3-none-any.whl.metadata (18 kB)
:: Collecting pyfiglet (from -r requirements.txt (line 3))
::   Downloading pyfiglet-1.0.2-py3-none-any.whl.metadata (7.1 kB)
:: Collecting markdown-it-py>=2.2.0 (from rich->-r requirements.txt (line 2))
::   Downloading markdown_it_py-3.0.0-py3-none-any.whl.metadata (6.9 kB)
:: Collecting pygments<3.0.0,>=2.13.0 (from rich->-r requirements.txt (line 2))
::   Downloading pygments-2.17.2-py3-none-any.whl.metadata (2.6 kB)
:: Collecting mdurl~=0.1 (from markdown-it-py>=2.2.0->rich->-r requirements.txt (line 2))
::   Downloading mdurl-0.1.2-py3-none-any.whl (10.0 kB)
:: Downloading rich-13.7.0-py3-none-any.whl (240 kB)
::    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 240.6/240.6 kB 1.0 MB/s eta 0:00:00
:: Downloading pyfiglet-1.0.2-py3-none-any.whl (1.1 MB)
::    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.1/1.1 MB 1.1 MB/s eta 0:00:00
:: Downloading markdown_it_py-3.0.0-py3-none-any.whl (87 kB)
::    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 87.5/87.5 kB 900.2 kB/s eta 0:00:00
:: Downloading pygments-2.17.2-py3-none-any.whl (1.2 MB)
::    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 1.0 MB/s eta 0:00:00
:: Installing collected packages: tabulate, pygments, pyfiglet, mdurl, markdown-it-py, rich
:: Successfully installed markdown-it-py-3.0.0 mdurl-0.1.2 pyfiglet-1.0.2 pygments-2.17.2 rich-13.7.0 tabulate-0.9.0
:: + '[' -f setup.py ']'
:: + '[' -f pyproject.toml ']'
:: + xargs -0 sed -i '1 s|^#\!/root/parts/hardenos/install/bin/python3.*$|#!/usr/bin/env python3|'
:: + find /root/parts/hardenos/install -type f -executable -print0
:: ++ grep errexit
:: ++ set +o
:: + opts_state='set +o errexit'
:: + set +e
:: + install_dir=/root/parts/hardenos/install/usr/bin
:: + stage_dir=/root/stage/usr/bin
:: +++ readlink -f /root/parts/hardenos/install/bin/python3
:: ++ basename /usr/bin/python3.10
:: + basename=python3.10
:: + echo Looking for a Python interpreter called '"python3.10"' in the payload...
:: Looking for a Python interpreter called "python3.10" in the payload...
:: ++ find /root/parts/hardenos/install/usr/bin /root/stage/usr/bin -type f -executable -name python3.10 -print -quit
:: + payload_python=
:: + '[' -n '' ']'
:: + echo 'Python interpreter not found in payload.'
:: Python interpreter not found in payload.
:: + symlink_target=/usr/bin/python3.10
:: + '[' -z /usr/bin/python3.10 ']'
:: + eval 'set +o errexit'
:: ++ set +o errexit
:: + ln -sf /usr/bin/python3.10 /root/parts/hardenos/install/bin/python3
Building scripts
:: + cp --archive --link --no-dereference . /root/parts/scripts/install
Staging hardenos
Staging scripts
Priming hardenos
Priming scripts
Extracting and updating metadata...
Copying snap assets...
Generating snap metadata...
Generated snap metadata
Reading snap metadata...
Running linters...
Running linter: classic
Running linter: library
Creating snap package...
Command '['snap', 'pack', '--filename', 'hardenos_0.1_amd64.snap', '--compression', 'xz', PosixPath('/root/prime'), PosixPath('/root/project')]' returned non-zero exit status 1.
Launching shell on build environment...

Even the absolute path doesn’t worked I couldn’t figure out what’s causing the problem, I hope this might help you to a better recommendations

I tried even with /usr/bin/env python3 ${SNAP}/main.py but I got the same behaviour.

I think the snapcraft.yaml should be updated, it’s somehow wrong, my project can be adopted based on your recommendations.

@Chawpe Can you show the The construction log (the build log), perhaps in $HOME/.local/state/snapcraft/log (the last log)?

is the snapcraft manifest file or the project open and somewhere in the internet? If yes can you share it with us?

Yes , you can find below the construction log :

chawpe@polarproxy:~$ cat /home/chawpe/.local/state/snapcraft/log/snapcraft-20240204-142258.952259.log
2024-02-04 14:22:58.952 Starting Snapcraft 8.0.2
2024-02-04 14:22:58.954 lifecycle command: 'pack', arguments: Namespace(destructive_mode=False, use_lxd=False, debug=True, enable_manifest=False, manifest_image_information=None, bind_ssh=False, build_for=None, http_proxy=None, https_proxy=None, ua_token=None, enable_experimental_ua_services=False, enable_experimental_plugins=False, enable_experimental_extensions=False, enable_developer_debug=False, enable_experimental_target_arch=False, target_arch=None, provider=None, directory=None, output=None)
2024-02-04 14:22:58.954 command: pack, arguments: Namespace(destructive_mode=False, use_lxd=False, debug=True, enable_manifest=False, manifest_image_information=None, bind_ssh=False, build_for=None, http_proxy=None, https_proxy=None, ua_token=None, enable_experimental_ua_services=False, enable_experimental_plugins=False, enable_experimental_extensions=False, enable_developer_debug=False, enable_experimental_target_arch=False, target_arch=None, provider=None, directory=None, output=None)
2024-02-04 14:22:58.961 CPU count (from process affinity): 1
2024-02-04 14:22:58.961 Invalid SNAPCRAFT_MAX_PARALLEL_BUILD_COUNT ''
2024-02-04 14:22:58.961 Running on amd64 for amd64
2024-02-04 14:22:58.962 Checking build provider availability
2024-02-04 14:22:59.057 Retrieved snap config: {}
2024-02-04 14:22:59.057 Using default provider 'lxd' on linux system.
2024-02-04 14:22:59.167 Executing on host: lxc --project default profile show local:default
2024-02-04 14:22:59.238 Using hostname 'snapcraft-hardenos-on-amd64-for-amd64-1200383'
2024-02-04 14:22:59.238 Launching instance...
2024-02-04 14:22:59.238 Executing on host: lxc remote list --format=yaml
2024-02-04 14:22:59.275 Remote 'craft-com.ubuntu.cloud-buildd' already exists.
2024-02-04 14:22:59.275 Executing on host: lxc project list local: --format=yaml
2024-02-04 14:22:59.322 Set LXD instance name to 'snapcraft-hardenos-on-amd64-for-amd64-1200383'
2024-02-04 14:22:59.322 Checking for instance 'snapcraft-hardenos-on-amd64-for-amd64-1200383' in project 'snapcraft' in remote 'local'
2024-02-04 14:22:59.322 Executing on host: lxc --project snapcraft list local: --format=yaml
2024-02-04 14:22:59.401 Instance 'snapcraft-hardenos-on-amd64-for-amd64-1200383' does not exist.
2024-02-04 14:22:59.408 Set LXD instance name to 'base-instance-snapcraft-buildd-base-v40--fd08e731c976fdc7c5bc'
2024-02-04 14:22:59.408 Checking for base instance 'base-instance-snapcraft-buildd-base-v40--fd08e731c976fdc7c5bc' in project 'snapcraft' in remote 'local'
2024-02-04 14:22:59.408 Executing on host: lxc --project snapcraft list local: --format=yaml
2024-02-04 14:22:59.457 Checking validity of instance 'base-instance-snapcraft-buildd-base-v40--fd08e731c976fdc7c5bc'.
2024-02-04 14:22:59.457 Executing on host: lxc --project snapcraft info local:base-instance-snapcraft-buildd-base-v40--fd08e731c976fdc7c5bc
2024-02-04 14:22:59.498 Executing on host: lxc --project snapcraft info local:base-instance-snapcraft-buildd-base-v40--fd08e731c976fdc7c5bc
2024-02-04 14:22:59.537 Executing on host: lxc --project snapcraft config get local:base-instance-snapcraft-buildd-base-v40--fd08e731c976fdc7c5bc user.craft_providers.status
2024-02-04 14:22:59.576 Instance 'base-instance-snapcraft-buildd-base-v40--fd08e731c976fdc7c5bc' is ready.
2024-02-04 14:22:59.576 Instance is valid.
2024-02-04 14:22:59.577 Creating instance from base instance
2024-02-04 14:22:59.577 Creating instance from base instance 'base-instance-snapcraft-buildd-base-v40--fd08e731c976fdc7c5bc'.
2024-02-04 14:22:59.577 Executing on host: lxc --project snapcraft list local: --format=yaml
2024-02-04 14:22:59.630 Executing on host: lxc --project snapcraft copy local:base-instance-snapcraft-buildd-base-v40--fd08e731c976fdc7c5bc local:snapcraft-hardenos-on-amd64-for-amd64-1200383
2024-02-04 14:23:23.243 Executing on host: lxc --project snapcraft list local: --format=yaml
2024-02-04 14:23:23.643 Executing on host: lxc --project snapcraft config set local:snapcraft-hardenos-on-amd64-for-amd64-1200383 raw.idmap 'both 1000 0'
2024-02-04 14:23:23.695 Executing on host: lxc --project snapcraft config get local:snapcraft-hardenos-on-amd64-for-amd64-1200383 raw.idmap
2024-02-04 14:23:23.735 Got LXD idmap for instance 'snapcraft-hardenos-on-amd64-for-amd64-1200383': 'both 1000 0'
2024-02-04 14:23:23.735 Starting instance
2024-02-04 14:23:23.736 Executing on host: lxc --project snapcraft start local:snapcraft-hardenos-on-amd64-for-amd64-1200383
2024-02-04 14:23:24.246 Executing on host: lxc --project snapcraft file push /tmp/tmpg5k1ld4u local:snapcraft-hardenos-on-amd64-for-amd64-1200383/etc/hostname --mode=0644
2024-02-04 14:23:24.329 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 chown root:root /etc/hostname
2024-02-04 14:23:24.470 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 hostname -F /etc/hostname
2024-02-04 14:23:24.583 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 test -f /etc/craft-instance.conf
2024-02-04 14:23:24.699 Executing on host: lxc --project snapcraft file pull local:snapcraft-hardenos-on-amd64-for-amd64-1200383/etc/craft-instance.conf /home/chawpe/tmpjvgjxs0p.tmp-craft/tmpvj9ce_3i
2024-02-04 14:23:24.790 Instance has already been setup.
2024-02-04 14:23:24.790 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 cat /etc/os-release
2024-02-04 14:23:24.893 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 test -f /etc/craft-instance.conf
2024-02-04 14:23:25.011 Executing on host: lxc --project snapcraft file pull local:snapcraft-hardenos-on-amd64-for-amd64-1200383/etc/craft-instance.conf /home/chawpe/tmp5nk6rliq.tmp-craft/tmpug32qyzt
2024-02-04 14:23:25.085 Instance is compatible with compatibility tag 'snapcraft-buildd-base-v4.0'
2024-02-04 14:23:25.085 No cache path set, not mounting cache directories.
2024-02-04 14:23:25.085 Waiting for environment to be ready...
2024-02-04 14:23:25.085 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 systemctl is-system-running
2024-02-04 14:23:25.218 systemctl is-system-running status: initializing
2024-02-04 14:23:25.468 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 systemctl is-system-running
2024-02-04 14:23:25.561 systemctl is-system-running status: initializing
2024-02-04 14:23:25.812 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 systemctl is-system-running
2024-02-04 14:23:26.723 systemctl is-system-running status: starting
2024-02-04 14:23:26.974 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 systemctl is-system-running
2024-02-04 14:23:27.550 systemctl is-system-running status: starting
2024-02-04 14:23:27.801 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 systemctl is-system-running
2024-02-04 14:23:27.912 systemctl is-system-running status: starting
2024-02-04 14:23:28.162 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 systemctl is-system-running
2024-02-04 14:23:28.457 systemctl is-system-running status: starting
2024-02-04 14:23:28.707 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 systemctl is-system-running
2024-02-04 14:23:29.244 Waiting for networking to be ready...
2024-02-04 14:23:29.245 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 getent hosts snapcraft.io
2024-02-04 14:23:29.463 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 snap unset system proxy.http
2024-02-04 14:23:29.560 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 snap unset system proxy.https
2024-02-04 14:23:29.658 Installing snap 'snapcraft' with channel=None and classic=True
2024-02-04 14:23:29.659 Installing snap 'snapcraft' from host (classic=True)
2024-02-04 14:23:30.255 Installing base snap 'core22' for 'snapcraft' from host
2024-02-04 14:23:30.255 Installing snap 'core22' from host (classic=False)
2024-02-04 14:23:30.284 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 test -f /etc/craft-instance.conf
2024-02-04 14:23:30.349 Executing on host: lxc --project snapcraft file pull local:snapcraft-hardenos-on-amd64-for-amd64-1200383/etc/craft-instance.conf /home/chawpe/tmpvunvpp34.tmp-craft/tmp4kl8dsrd
2024-02-04 14:23:30.435 Revisions found: host='1033', target='1033'
2024-02-04 14:23:30.435 Skipping snap injection: target is already up-to-date with revision on host
2024-02-04 14:23:30.436 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 test -f /etc/craft-instance.conf
2024-02-04 14:23:30.502 Executing on host: lxc --project snapcraft file pull local:snapcraft-hardenos-on-amd64-for-amd64-1200383/etc/craft-instance.conf /home/chawpe/tmpb4ms0twi.tmp-craft/tmpzjn1ogr8
2024-02-04 14:23:30.547 Revisions found: host='10436', target='10436'
2024-02-04 14:23:30.547 Skipping snap injection: target is already up-to-date with revision on host
2024-02-04 14:23:30.737 Setting instance timezone to match host timezone 'Africa/Tunis'.
2024-02-04 14:23:30.737 Executing on host: lxc --project snapcraft config set local:snapcraft-hardenos-on-amd64-for-amd64-1200383 environment.TZ Africa/Tunis
2024-02-04 14:23:30.803 Executing on host: lxc --project snapcraft config device show local:snapcraft-hardenos-on-amd64-for-amd64-1200383
2024-02-04 14:23:30.841 Executing on host: lxc --project snapcraft config device add local:snapcraft-hardenos-on-amd64-for-amd64-1200383 disk-/root/project disk source=/home/chawpe/hardenos path=/root/project
2024-02-04 14:23:30.912 Executing on host: lxc --project snapcraft file push /tmp/tmpcwls7cmd local:snapcraft-hardenos-on-amd64-for-amd64-1200383/root/.bashrc --mode=644
2024-02-04 14:23:30.954 Executing in container: lxc --project snapcraft exec local:snapcraft-hardenos-on-amd64-for-amd64-1200383 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 chown root:root /root/.bashrc
2024-02-04 14:23:31.022 Emitter: Pausing control of the terminal

And you can find below the trace logs from /tmp/snapcraft.log from inside the VM:

2024-02-04 14:23:34.791 Starting Snapcraft 8.0.2
2024-02-04 14:23:34.793 lifecycle command: 'pack', arguments: Namespace(destructive_mode=False, use_lxd=False, debug=True, enable_manifest=False, manifest_image_information=None, bind_ssh=False, build_for='amd64', http_proxy=None, https_proxy=None, ua_token=None, enable_experimental_ua_services=False, enable_experimental_plugins=False, enable_experimental_extensions=False, enable_developer_debug=False, enable_experimental_target_arch=False, target_arch=None, provider=None, directory=None, output=None)
2024-02-04 14:23:34.793 command: pack, arguments: Namespace(destructive_mode=False, use_lxd=False, debug=True, enable_manifest=False, manifest_image_information=None, bind_ssh=False, build_for='amd64', http_proxy=None, https_proxy=None, ua_token=None, enable_experimental_ua_services=False, enable_experimental_plugins=False, enable_experimental_extensions=False, enable_developer_debug=False, enable_experimental_target_arch=False, target_arch=None, provider=None, directory=None, output=None)
2024-02-04 14:23:34.800 CPU count (from process affinity): 1
2024-02-04 14:23:34.800 Invalid SNAPCRAFT_MAX_PARALLEL_BUILD_COUNT ''
2024-02-04 14:23:34.800 Running on amd64 for amd64
2024-02-04 14:23:34.801 Initializing parts lifecycle
2024-02-04 14:23:34.802 is_snap: True, SNAP_NAME set to snapcraft
2024-02-04 14:23:34.802 process hardenos:Step.PULL
2024-02-04 14:23:34.802 add action hardenos:Step.PULL(ActionType.RUN)
2024-02-04 14:23:34.802 process scripts:Step.PULL
2024-02-04 14:23:34.802 add action scripts:Step.PULL(ActionType.RUN)
2024-02-04 14:23:34.803 process hardenos:Step.BUILD
2024-02-04 14:23:34.803 add action hardenos:Step.BUILD(ActionType.RUN)
2024-02-04 14:23:34.803 process scripts:Step.BUILD
2024-02-04 14:23:34.803 add action scripts:Step.BUILD(ActionType.RUN)
2024-02-04 14:23:34.803 process hardenos:Step.STAGE
2024-02-04 14:23:34.803 add action hardenos:Step.STAGE(ActionType.RUN)
2024-02-04 14:23:34.803 process scripts:Step.STAGE
2024-02-04 14:23:34.803 add action scripts:Step.STAGE(ActionType.RUN)
2024-02-04 14:23:34.803 process hardenos:Step.PRIME
2024-02-04 14:23:34.803 add action hardenos:Step.PRIME(ActionType.RUN)
2024-02-04 14:23:34.804 process scripts:Step.PRIME
2024-02-04 14:23:34.804 add action scripts:Step.PRIME(ActionType.RUN)
2024-02-04 14:23:34.804 ignore patterns: ['*.snap']
2024-02-04 14:23:34.804 plugin build packages: {'python3-venv', 'findutils', 'python3-dev'}
2024-02-04 14:23:34.805 ignore patterns: ['*.snap']
2024-02-04 14:23:34.805 Installing build-packages
2024-02-04 14:23:34.806 Requested build-packages: ['findutils', 'python3-dev', 'python3-venv']
2024-02-04 14:23:36.759 Marking python3-venv (and its dependencies) to be fetched
2024-02-04 14:23:36.760 package: python3-venv
2024-02-04 14:23:36.773 Marking findutils (and its dependencies) to be fetched
2024-02-04 14:23:36.773 package: findutils
2024-02-04 14:23:36.779 Marking python3-dev (and its dependencies) to be fetched
2024-02-04 14:23:36.779 package: python3-dev
2024-02-04 14:23:36.803 Executing: ['apt-get', 'update']
2024-02-04 14:23:37.373 :: Get:1 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
2024-02-04 14:23:37.383 :: Hit:2 http://archive.ubuntu.com/ubuntu jammy InRelease
2024-02-04 14:23:37.536 :: Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
2024-02-04 14:23:38.083 :: Hit:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
2024-02-04 14:23:38.204 :: Get:5 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [1325 kB]
2024-02-04 14:23:39.651 :: Fetched 1554 kB in 3s (573 kB/s)
2024-02-04 14:23:40.879 :: Reading package lists...
2024-02-04 14:23:41.007 Installing packages: findutils python3-dev python3-venv
2024-02-04 14:23:41.140 :: Reading package lists...
2024-02-04 14:23:41.366 :: Building dependency tree...
2024-02-04 14:23:41.369 :: Reading state information...
2024-02-04 14:23:41.494 :: findutils is already the newest version (4.8.0-1ubuntu3).
2024-02-04 14:23:41.494 :: python3-dev is already the newest version (3.10.6-1~22.04).
2024-02-04 14:23:41.494 :: The following additional packages will be installed:
2024-02-04 14:23:41.495 :: python3-pip-whl python3-setuptools-whl python3.10-venv
2024-02-04 14:23:41.641 :: The following NEW packages will be installed:
2024-02-04 14:23:41.642 :: python3-pip-whl python3-setuptools-whl python3-venv python3.10-venv
2024-02-04 14:23:41.762 :: 0 upgraded, 4 newly installed, 0 to remove and 79 not upgraded.
2024-02-04 14:23:41.762 :: Need to get 2474 kB of archives.
2024-02-04 14:23:41.762 :: After this operation, 2890 kB of additional disk space will be used.
2024-02-04 14:23:41.762 :: Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 python3-pip-whl all 22.0.2+dfsg-1ubuntu0.4 [1680 kB]
2024-02-04 14:23:43.509 :: Get:2 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 python3-setuptools-whl all 59.6.0-1.2ubuntu0.22.04.1 [788 kB]
2024-02-04 14:23:44.279 :: Get:3 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 python3.10-venv amd64 3.10.12-1~22.04.3 [5716 B]
2024-02-04 14:23:44.286 :: Get:4 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 python3-venv amd64 3.10.6-1~22.04 [1038 B]
2024-02-04 14:23:44.580 :: Fetched 2474 kB in 3s (938 kB/s)
2024-02-04 14:23:44.620 :: Selecting previously unselected package python3-pip-whl.
2024-02-04 14:23:44.692 :: (Reading database ... 17525 files and directories currently installed.)
2024-02-04 14:23:44.692 :: Preparing to unpack .../python3-pip-whl_22.0.2+dfsg-1ubuntu0.4_all.deb ...
2024-02-04 14:23:44.697 :: Unpacking python3-pip-whl (22.0.2+dfsg-1ubuntu0.4) ...
2024-02-04 14:23:44.739 :: Selecting previously unselected package python3-setuptools-whl.
2024-02-04 14:23:44.739 :: Preparing to unpack .../python3-setuptools-whl_59.6.0-1.2ubuntu0.22.04.1_all.deb ...
2024-02-04 14:23:44.743 :: Unpacking python3-setuptools-whl (59.6.0-1.2ubuntu0.22.04.1) ...
2024-02-04 14:23:44.784 :: Selecting previously unselected package python3.10-venv.
2024-02-04 14:23:44.784 :: Preparing to unpack .../python3.10-venv_3.10.12-1~22.04.3_amd64.deb ...
2024-02-04 14:23:44.789 :: Unpacking python3.10-venv (3.10.12-1~22.04.3) ...
2024-02-04 14:23:44.821 :: Selecting previously unselected package python3-venv.
2024-02-04 14:23:44.821 :: Preparing to unpack .../python3-venv_3.10.6-1~22.04_amd64.deb ...
2024-02-04 14:23:44.825 :: Unpacking python3-venv (3.10.6-1~22.04) ...
2024-02-04 14:23:44.856 :: Setting up python3-setuptools-whl (59.6.0-1.2ubuntu0.22.04.1) ...
2024-02-04 14:23:44.869 :: Setting up python3-pip-whl (22.0.2+dfsg-1ubuntu0.4) ...
2024-02-04 14:23:44.881 :: Setting up python3.10-venv (3.10.12-1~22.04.3) ...
2024-02-04 14:23:44.981 :: Setting up python3-venv (3.10.6-1~22.04) ...
2024-02-04 14:23:45.380 Found installed version 22.0.2+dfsg-1ubuntu0.4 for package python3-pip-whl
2024-02-04 14:23:45.380 Found installed version 59.6.0-1.2ubuntu0.22.04.1 for package python3-setuptools-whl
2024-02-04 14:23:45.380 Found installed version 3.10.6-1~22.04 for package python3-venv
2024-02-04 14:23:45.380 Found installed version 3.10.12-1~22.04.3 for package python3.10-venv
2024-02-04 14:23:45.381 Installing build-snaps
2024-02-04 14:23:46.341 verify plugin environment for part 'hardenos'
2024-02-04 14:23:46.342 verify plugin environment for part 'scripts'
2024-02-04 14:23:46.342 Pulling hardenos
2024-02-04 14:23:46.343 execute action hardenos:Action(part_name='hardenos', step=Step.PULL, action_type=ActionType.RUN, reason=None, project_vars=None, properties=ActionProperties(changed_files=None, changed_dirs=None))
2024-02-04 14:23:46.362 Pulling scripts
2024-02-04 14:23:46.363 execute action scripts:Action(part_name='scripts', step=Step.PULL, action_type=ActionType.RUN, reason=None, project_vars=None, properties=ActionProperties(changed_files=None, changed_dirs=None))
2024-02-04 14:23:46.381 Building hardenos
2024-02-04 14:23:46.382 execute action hardenos:Action(part_name='hardenos', step=Step.BUILD, action_type=ActionType.RUN, reason=None, project_vars=None, properties=ActionProperties(changed_files=None, changed_dirs=None))
2024-02-04 14:23:46.382 load state file: /root/parts/hardenos/state/pull
2024-02-04 14:23:46.386 remove directory /root/parts/hardenos/build
2024-02-04 14:23:46.387 Executing PosixPath('/root/parts/hardenos/run/build.sh')
2024-02-04 14:23:46.388 :: + python3 -m venv /root/parts/hardenos/install
2024-02-04 14:23:48.708 :: + PARTS_PYTHON_VENV_INTERP_PATH=/root/parts/hardenos/install/bin/python3
2024-02-04 14:23:48.709 :: + /root/parts/hardenos/install/bin/pip install -U pip setuptools wheel
2024-02-04 14:23:48.958 :: Requirement already satisfied: pip in /root/parts/hardenos/install/lib/python3.10/site-packages (22.0.2)
2024-02-04 14:23:49.174 :: Collecting pip
2024-02-04 14:23:49.387 ::   Downloading pip-24.0-py3-none-any.whl (2.1 MB)
2024-02-04 14:23:51.355 ::      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 1.1 MB/s eta 0:00:00
2024-02-04 14:23:51.365 :: Requirement already satisfied: setuptools in /root/parts/hardenos/install/lib/python3.10/site-packages (59.6.0)
2024-02-04 14:23:51.834 :: Collecting setuptools
2024-02-04 14:23:51.882 ::   Downloading setuptools-69.0.3-py3-none-any.whl (819 kB)
2024-02-04 14:23:52.648 ::      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 819.5/819.5 KB 1.1 MB/s eta 0:00:00
2024-02-04 14:23:52.715 :: Collecting wheel
2024-02-04 14:23:52.761 ::   Downloading wheel-0.42.0-py3-none-any.whl (65 kB)
2024-02-04 14:23:52.830 ::      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 65.4/65.4 KB 1.2 MB/s eta 0:00:00
2024-02-04 14:23:53.036 :: Installing collected packages: wheel, setuptools, pip
2024-02-04 14:23:53.127 ::   Attempting uninstall: setuptools
2024-02-04 14:23:53.130 ::     Found existing installation: setuptools 59.6.0
2024-02-04 14:23:53.215 ::     Uninstalling setuptools-59.6.0:
2024-02-04 14:23:53.237 ::       Successfully uninstalled setuptools-59.6.0
2024-02-04 14:23:54.077 ::   Attempting uninstall: pip
2024-02-04 14:23:54.079 ::     Found existing installation: pip 22.0.2
2024-02-04 14:23:54.646 ::     Uninstalling pip-22.0.2:
2024-02-04 14:23:54.661 ::       Successfully uninstalled pip-22.0.2
2024-02-04 14:23:56.866 :: Successfully installed pip-24.0 setuptools-69.0.3 wheel-0.42.0
2024-02-04 14:23:57.354 :: + /root/parts/hardenos/install/bin/pip install -U -r requirements.txt
2024-02-04 14:23:59.265 :: Collecting tabulate (from -r requirements.txt (line 1))
2024-02-04 14:24:01.260 ::   Downloading tabulate-0.9.0-py3-none-any.whl (35 kB)
2024-02-04 14:24:03.120 :: Collecting rich (from -r requirements.txt (line 2))
2024-02-04 14:24:03.283 ::   Downloading rich-13.7.0-py3-none-any.whl.metadata (18 kB)
2024-02-04 14:24:03.734 :: Collecting pyfiglet (from -r requirements.txt (line 3))
2024-02-04 14:24:03.869 ::   Downloading pyfiglet-1.0.2-py3-none-any.whl.metadata (7.1 kB)
2024-02-04 14:24:04.274 :: Collecting markdown-it-py>=2.2.0 (from rich->-r requirements.txt (line 2))
2024-02-04 14:24:04.426 ::   Downloading markdown_it_py-3.0.0-py3-none-any.whl.metadata (6.9 kB)
2024-02-04 14:24:04.717 :: Collecting pygments<3.0.0,>=2.13.0 (from rich->-r requirements.txt (line 2))
2024-02-04 14:24:04.887 ::   Downloading pygments-2.17.2-py3-none-any.whl.metadata (2.6 kB)
2024-02-04 14:24:05.313 :: Collecting mdurl~=0.1 (from markdown-it-py>=2.2.0->rich->-r requirements.txt (line 2))
2024-02-04 14:24:06.072 ::   Downloading mdurl-0.1.2-py3-none-any.whl (10.0 kB)
2024-02-04 14:24:07.801 :: Downloading rich-13.7.0-py3-none-any.whl (240 kB)
2024-02-04 14:24:09.094 ::    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 240.6/240.6 kB 185.1 kB/s eta 0:00:00
2024-02-04 14:24:09.266 :: Downloading pyfiglet-1.0.2-py3-none-any.whl (1.1 MB)
2024-02-04 14:24:11.647 ::    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.1/1.1 MB 459.6 kB/s eta 0:00:00
2024-02-04 14:24:12.267 :: Downloading markdown_it_py-3.0.0-py3-none-any.whl (87 kB)
2024-02-04 14:24:12.481 ::    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 87.5/87.5 kB 436.3 kB/s eta 0:00:00
2024-02-04 14:24:12.724 :: Downloading pygments-2.17.2-py3-none-any.whl (1.2 MB)
2024-02-04 14:24:14.266 ::    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 766.8 kB/s eta 0:00:00
2024-02-04 14:24:14.351 :: Installing collected packages: tabulate, pygments, pyfiglet, mdurl, markdown-it-py, rich
2024-02-04 14:24:15.772 :: Successfully installed markdown-it-py-3.0.0 mdurl-0.1.2 pyfiglet-1.0.2 pygments-2.17.2 rich-13.7.0 tabulate-0.9.0
2024-02-04 14:24:16.692 :: + '[' -f setup.py ']'
2024-02-04 14:24:16.693 :: + '[' -f pyproject.toml ']'
2024-02-04 14:24:16.695 :: + xargs -0 sed -i '1 s|^#\!/root/parts/hardenos/install/bin/python3.*$|#!/usr/bin/env python3|'
2024-02-04 14:24:16.695 :: + find /root/parts/hardenos/install -type f -executable -print0
2024-02-04 14:24:16.725 :: ++ grep errexit
2024-02-04 14:24:16.727 :: ++ set +o
2024-02-04 14:24:16.729 :: + opts_state='set +o errexit'
2024-02-04 14:24:16.730 :: + set +e
2024-02-04 14:24:16.730 :: + install_dir=/root/parts/hardenos/install/usr/bin
2024-02-04 14:24:16.731 :: + stage_dir=/root/stage/usr/bin
2024-02-04 14:24:16.731 :: +++ readlink -f /root/parts/hardenos/install/bin/python3
2024-02-04 14:24:16.734 :: ++ basename /usr/bin/python3.10
2024-02-04 14:24:16.737 :: + basename=python3.10
2024-02-04 14:24:16.738 :: + echo Looking for a Python interpreter called '"python3.10"' in the payload...
2024-02-04 14:24:16.738 :: Looking for a Python interpreter called "python3.10" in the payload...
2024-02-04 14:24:16.739 :: ++ find /root/parts/hardenos/install/usr/bin /root/stage/usr/bin -type f -executable -name python3.10 -print -quit
2024-02-04 14:24:16.743 :: + payload_python=
2024-02-04 14:24:16.744 :: + '[' -n '' ']'
2024-02-04 14:24:16.744 :: + echo 'Python interpreter not found in payload.'
2024-02-04 14:24:16.745 :: Python interpreter not found in payload.
2024-02-04 14:24:16.745 :: + symlink_target=/usr/bin/python3.10
2024-02-04 14:24:16.746 :: + '[' -z /usr/bin/python3.10 ']'
2024-02-04 14:24:16.746 :: + eval 'set +o errexit'
2024-02-04 14:24:16.746 :: ++ set +o errexit
2024-02-04 14:24:16.746 :: + ln -sf /usr/bin/python3.10 /root/parts/hardenos/install/bin/python3
2024-02-04 14:24:17.462 Building scripts
2024-02-04 14:24:17.463 execute action scripts:Action(part_name='scripts', step=Step.BUILD, action_type=ActionType.RUN, reason=None, project_vars=None, properties=ActionProperties(changed_files=None, changed_dirs=None))
2024-02-04 14:24:17.465 load state file: /root/parts/scripts/state/pull
2024-02-04 14:24:17.471 remove directory /root/parts/scripts/build
2024-02-04 14:24:17.473 Executing PosixPath('/root/parts/scripts/run/build.sh')
2024-02-04 14:24:17.478 :: + cp --archive --link --no-dereference . /root/parts/scripts/install
2024-02-04 14:24:18.002 Staging hardenos
2024-02-04 14:24:18.003 execute action hardenos:Action(part_name='hardenos', step=Step.STAGE, action_type=ActionType.RUN, reason=None, project_vars=None, properties=ActionProperties(changed_files=None, changed_dirs=None))
2024-02-04 14:24:19.235 Staging scripts
2024-02-04 14:24:19.236 execute action scripts:Action(part_name='scripts', step=Step.STAGE, action_type=ActionType.RUN, reason=None, project_vars=None, properties=ActionProperties(changed_files=None, changed_dirs=None))
2024-02-04 14:24:19.697 Priming hardenos
2024-02-04 14:24:19.698 execute action hardenos:Action(part_name='hardenos', step=Step.PRIME, action_type=ActionType.RUN, reason=None, project_vars=None, properties=ActionProperties(changed_files=None, changed_dirs=None))
2024-02-04 14:24:20.478 patch_elf: not enabled for part 'hardenos'
2024-02-04 14:24:20.479 Priming scripts
2024-02-04 14:24:20.481 execute action scripts:Action(part_name='scripts', step=Step.PRIME, action_type=ActionType.RUN, reason=None, project_vars=None, properties=ActionProperties(changed_files=None, changed_dirs=None))
2024-02-04 14:24:20.499 patch_elf: not enabled for part 'scripts'
2024-02-04 14:24:20.499 Extracting and updating metadata...
2024-02-04 14:24:20.500 Copying snap assets...
2024-02-04 14:24:20.501 finalize icon: None
2024-02-04 14:24:20.501 relative icon path: None
2024-02-04 14:24:20.501 Generating snap metadata...
2024-02-04 14:24:20.503 Generated snap metadata
2024-02-04 14:24:20.503 Reading snap metadata...
2024-02-04 14:24:20.505 Running linters...
2024-02-04 14:24:20.506 Running linter: classic
2024-02-04 14:24:20.506 Running linter: library
2024-02-04 14:24:20.627 pack_snap: output=None, compression='xz'
2024-02-04 14:24:20.627 pack_snap: check skeleton
2024-02-04 14:24:21.320 Creating snap package...
2024-02-04 14:24:21.321 Pack command: ['snap', 'pack', '--filename', 'hardenos_0.1_amd64.snap', '--compression', 'xz', PosixPath('/root/prime'), PosixPath('/root/project')]
2024-02-04 14:24:21.339 Command '['snap', 'pack', '--filename', 'hardenos_0.1_amd64.snap', '--compression', 'xz', PosixPath('/root/prime'), PosixPath('/root/project')]' returned non-zero exit status 1.
2024-02-04 14:24:21.340 Launching shell on build environment...
2024-02-04 14:24:21.340 Emitter: Pausing control of the terminal

I hope this might help

The project is built internally and is not yet released but I’m happy to provide you with the information you need

This is the code of where the python code calls the bash script to be run :

    if len(T_R_refs)>0:
        for TRref in T_R_refs:
            print(f"TRref :{TRref} ")
            if TRref == "T":
                subprocess.run(f"bash ../cis/centos7_test_all.sh", shell = True)

it works fine when using virtualenv and without snap

I just want to know… which command needs to invoked first? What is the starting point of this app?

The starting point of this app is main.py

And that bash is transparent when launching the app, and will be executed only after launching main.py

Try with adding the /usr/bin/env python3 at the starting of the file? Then you’ll not need to run it like python3 …

There are no apparent errors in the log .

Maybe one of the problems is there .

This β†’ subprocess.run(f"bash ../cis/centos7_test_all.sh", shell = True)

If your project is public you can share the link (I will be ready to compile the project) .

I got the same behavior even when adding the line

I’d be happy to schedule a brief meeting to troubleshoot this issue togeher and then post the solution in the forum. I’m available at this time 2024-02-06T07:00:00Zβ†’2024-02-06T10:00:00Z , please let me know your availability, thank you.

Thank you for your support, Could we schedule a quick meeting ?

That will be cool :slightly_smiling_face:, if we have access to the project via a git repository.

On this line, I recommend you to give an **absolute path for the bash interpreter and to remove this β†’ .

subprocess.run(f"bash ../cis/centos7_test_all.sh", shell = True)

You will have something like this :

subprocess.run(f"/usr/bin/bash ./cis/centos7_test_all.sh", shell = True)
1 Like

It’s always a good idea to use

snap run --shell SNAP_NAME
cd $SNAP

to check whether the files have really ended up where you thought they would. You can run your scripts in the snap-shell-environment and maybe that gives you some more info.

To prevent problems by using Paths beginning with β€œ.” I sometimes use (ugly) code like this:

#Path of python script in Snap
pyScriptRoot = os.path.dirname(os.path.realpath(__file__))
#Add relative path to assets / scripts / etc
shScriptPath = os.path.join(pyScriptRoot , '.', 'cis', 'centos7_test_all.sh')