canonical / craft-parts

https://canonical-craft-parts.readthedocs-hosted.com
GNU Lesser General Public License v3.0
10 stars 34 forks source link

Organize does not raise error if source file does not exist #553

Open amandahla opened 10 months ago

amandahla commented 10 months ago

Bug Description

While building a rock for Synapse charm, there is a configuration file that should be dumped in a specific directory with a specific name by using the "organize" keyword. Its name was changed in the repository but not in the rockcraft.yaml. This went unnoticed until deploying the charm because the rock was successfully built but the file was not there.

To Reproduce

This is an example of the part that was expected to raise an error since the source file in "organize" does not exist.

not-found-login_ubuntu.py is a file that does not exist.

synapse-conf:
        plugin: dump
        source: attributemaps
        organize:
            not-found-login_ubuntu.py: /usr/local/attributemaps/login_ubuntu.py

part yaml

# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

name: synapse
summary: Synapse rock
description: Synapse OCI image for the Synapse charm
version: "1.0"
base: ubuntu:22.04
build-base: ubuntu:22.04
license: Apache-2.0
platforms:
  amd64:
parts:
    synapse:
        build-packages:
            - build-essential
            - curl
            - git
            - libffi-dev
            - libssl-dev
            - pkg-config
            - libjpeg-dev
            - libpq-dev
            - libwebp-dev
            - libxml++2.6-dev
            - libxslt1-dev
            - openssl
            - zlib1g-dev
            - libicu-dev
            - python3-dev
            - python3-pip
            - python3-setuptools
        stage-packages:
            - bash
            - coreutils
            - curl
            - gosu
            - libffi-dev
            - libjpeg-turbo8
            - libpq5
            - libwebp7
            - xmlsec1
            - libjemalloc2
            - libicu70
            - libssl-dev
            - openssl
            - python3
        plugin: nil
        source: https://github.com/matrix-org/synapse/
        source-type: git
        source-tag: v1.85.2
        override-build: |
            craftctl default
            export RUSTUP_HOME=/rust
            export CARGO_HOME=/cargo
            export PATH=/cargo/bin:/rust/bin:$PATH
            export CARGO_NET_GIT_FETCH_WITH_CLI=false
            mkdir -p /rust /cargo /synapse /install
            curl -m 30 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --default-toolchain stable --profile minimal
            pip3 install -U pip setuptools
            pip3 install --root-user-action=ignore "poetry==1.3.2"
            cp pyproject.toml poetry.lock /synapse/
            /usr/local/bin/poetry export --extras all -o /synapse/requirements.txt
            pip3 install --prefix="/install" --no-deps --no-warn-script-location -r /synapse/requirements.txt
            cp -r synapse /synapse/
            cp -r rust /synapse/
            cp pyproject.toml README.rst build_rust.py Cargo.toml Cargo.lock /synapse/
            pip3 install --prefix="/install" --no-deps --no-warn-script-location /synapse[all];
            cp docker/start.py $CRAFT_PART_INSTALL/
            chmod 755 $CRAFT_PART_INSTALL/start.py
            sed -i 's/#!\/usr\/local\/bin\/python/#!\/usr\/bin\/python3/' $CRAFT_PART_INSTALL/start.py
            cp -r docker/conf $CRAFT_PART_INSTALL/
            cp -r /usr/local $CRAFT_PART_INSTALL/usr/
            cp -r /install/local/* $CRAFT_PART_INSTALL/usr/local/
            mkdir -p $CRAFT_PART_INSTALL/usr/local/attributemaps
            chmod 755 $CRAFT_PART_INSTALL/usr/local/attributemaps
    synapse-conf:
        plugin: dump
        source: attributemaps
        organize:
            u1staging.py: /usr/local/attributemaps/u1staging.py

Relevant log output

2023-09-13T20:31:10.7322269Z 2023-09-13 20:31:05.623 Executed: build synapse
2023-09-13T20:31:10.7322656Z 2023-09-13 20:31:05.623 Executing parts lifecycle: build synapse-conf
2023-09-13T20:31:10.7323025Z 2023-09-13 20:31:05.623 Executing action
2023-09-13T20:31:10.7323789Z 2023-09-13 20:31:05.627 execute action synapse-conf:Action(part_name='synapse-conf', step=Step.BUILD, action_type=ActionType.RUN, reason=None, project_vars=None, properties=ActionProperties(changed_files=None, changed_dirs=None))
2023-09-13T20:31:10.7324443Z 2023-09-13 20:31:05.628 load state file: /root/parts/synapse-conf/state/pull
2023-09-13T20:31:10.7324897Z 2023-09-13 20:31:05.635 remove directory /root/parts/synapse-conf/build
2023-09-13T20:31:10.7325894Z 2023-09-13 20:31:05.637 Executing PosixPath('/root/parts/synapse-conf/run/build.sh')
2023-09-13T20:31:10.7326621Z 2023-09-13 20:31:05.644 :: + cp --archive --link --no-dereference . /root/parts/synapse-conf/install
2023-09-13T20:31:10.7327037Z 2023-09-13 20:31:06.424 Executed: build synapse-conf
2023-09-13T20:31:10.7327436Z 2023-09-13 20:31:06.425 Executing parts lifecycle: stage pebble
tigarmo commented 10 months ago

I suspect that this happens because of this iglob() call: if the path matches no files, the iterator is 'empty' and never enters the subsequent loop. That is, the behavior is an accidental consequence of the implementation.

syncronize-issues-to-jira[bot] commented 2 months ago

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CRAFT-2943.

This message was autogenerated