From 0633e5a65d2088d5b5165c41769bf81955803052 Mon Sep 17 00:00:00 2001 From: Callahan Date: Mon, 7 Oct 2024 09:56:32 -0500 Subject: [PATCH 1/2] chore: fix deprecation warnings (#5094) Fixes a handful of deprecation warnings from libraries. Signed-off-by: Callahan Kovacs --- snapcraft/application.py | 2 +- snapcraft/commands/validation_sets.py | 6 ++++-- snapcraft/linters/linters.py | 2 +- tests/unit/linters/test_linters.py | 4 ++-- tests/unit/services/test_package.py | 16 ++++++++-------- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/snapcraft/application.py b/snapcraft/application.py index f8fd99f980..0b0f96281c 100644 --- a/snapcraft/application.py +++ b/snapcraft/application.py @@ -141,7 +141,7 @@ def _register_default_plugins(self) -> None: @override def _configure_services(self, provider_name: str | None) -> None: - self.services.set_kwargs( + self.services.update_kwargs( "package", build_plan=self._build_plan, snapcraft_yaml_path=self._snapcraft_yaml_path, diff --git a/snapcraft/commands/validation_sets.py b/snapcraft/commands/validation_sets.py index 50f1ef97ed..8ab5fbfdb1 100644 --- a/snapcraft/commands/validation_sets.py +++ b/snapcraft/commands/validation_sets.py @@ -136,7 +136,9 @@ def _submit_validation_set( key_name: Optional[str], store_client: StoreClientCLI, ) -> None: - emit.debug(f"Posting assertion to build: {edited_validation_sets.json()}") + emit.debug( + f"Posting assertion to build: {edited_validation_sets.model_dump_json()}" + ) build_assertion = store_client.post_validation_sets_build_assertion( validation_sets=edited_validation_sets.marshal() ) @@ -148,7 +150,7 @@ def _submit_validation_set( response = store_client.post_validation_sets( signed_validation_sets=signed_validation_sets ) - emit.debug(f"Response: {response.json()}") + emit.debug(f"Response: {response.model_dump_json()}") def _generate_template( diff --git a/snapcraft/linters/linters.py b/snapcraft/linters/linters.py index 507c8642cc..798d796f7a 100644 --- a/snapcraft/linters/linters.py +++ b/snapcraft/linters/linters.py @@ -87,7 +87,7 @@ def report( issues_by_result.setdefault(issue.result, []).append(issue) if json_output: - display(json.dumps([x.dict(exclude_none=True) for x in issues])) + display(json.dumps([x.model_dump(exclude_none=True) for x in issues])) else: # show issues by result for result, header in _lint_reports.items(): diff --git a/tests/unit/linters/test_linters.py b/tests/unit/linters/test_linters.py index cf2adec6b7..7e9c87d3d3 100644 --- a/tests/unit/linters/test_linters.py +++ b/tests/unit/linters/test_linters.py @@ -256,8 +256,8 @@ def test_base_linter_is_file_ignored(): # The "test-path" Path must be ignored by the "main" filter and all categories. assert linter.is_file_ignored(Path("test-path")) - assert linter.is_file_ignored(Path("test-path", category="test-1")) - assert linter.is_file_ignored(Path("test-path", category="test-2")) + assert linter.is_file_ignored(Path("test-path"), category="test-1") + assert linter.is_file_ignored(Path("test-path"), category="test-2") # "test-1-path" is ignored by the "test-1" only assert not linter.is_file_ignored(Path("test-1-path")) diff --git a/tests/unit/services/test_package.py b/tests/unit/services/test_package.py index 57949bd4f8..9590130d01 100644 --- a/tests/unit/services/test_package.py +++ b/tests/unit/services/test_package.py @@ -76,7 +76,7 @@ def test_metadata( ): project_path = new_dir / "snapcraft.yaml" snapcraft_yaml(filename=project_path) - default_factory.set_kwargs( + default_factory.update_kwargs( "lifecycle", work_dir=Path("work"), cache_dir=new_dir, @@ -122,7 +122,7 @@ def test_write_metadata( default_build_plan, new_dir, ): - default_factory.set_kwargs( + default_factory.update_kwargs( "lifecycle", work_dir=Path("work"), cache_dir=new_dir, @@ -163,7 +163,7 @@ def test_write_metadata_with_manifest( new_dir, ): monkeypatch.setenv("SNAPCRAFT_BUILD_INFO", "1") - default_factory.set_kwargs( + default_factory.update_kwargs( "lifecycle", work_dir=Path("work"), cache_dir=new_dir, @@ -180,7 +180,7 @@ def test_write_metadata_with_manifest( # This will be different every time due to started_at differing, we can check # that it's a valid manifest and compare some fields to snap.yaml. manifest_dict = yaml.safe_load((prime_dir / "snap" / "manifest.yaml").read_text()) - manifest = models.Manifest.parse_obj(manifest_dict) + manifest = models.Manifest.model_validate(manifest_dict) assert manifest.snapcraft_version == __version__ assert ( @@ -208,7 +208,7 @@ def test_write_metadata_with_project_hooks( shutil.move(new_dir / "snap" / "snapcraft.yaml", new_dir) shutil.rmtree(new_dir / "snap") - default_factory.set_kwargs( + default_factory.update_kwargs( "lifecycle", work_dir=work_dir, cache_dir=new_dir, @@ -257,7 +257,7 @@ def test_write_metadata_with_built_hooks( new_dir, ): work_dir = new_dir / "work" - default_factory.set_kwargs( + default_factory.update_kwargs( "lifecycle", work_dir=work_dir, cache_dir=new_dir, @@ -307,7 +307,7 @@ def test_write_metadata_with_project_gui( new_dir, ): work_dir = new_dir / "work" - default_factory.set_kwargs( + default_factory.update_kwargs( "lifecycle", work_dir=work_dir, cache_dir=new_dir, @@ -367,7 +367,7 @@ def test_update_project_parse_info( ): work_dir = Path("work").resolve() - default_factory.set_kwargs( + default_factory.update_kwargs( "lifecycle", work_dir=work_dir, cache_dir=new_dir, From 24e70d6db3a05760e8a1aae551b3f5ba2f233e67 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Mon, 7 Oct 2024 21:21:33 +0300 Subject: [PATCH 2/2] chore!: remove Dockerfile and document snapcraft-rocks registry (#5063) Signed-off-by: Anatoli Babenia --- Dockerfile | 14 --------- docker/Dockerfile | 74 ----------------------------------------------- docker/README.md | 30 ++++++++++++------- 3 files changed, 20 insertions(+), 98 deletions(-) delete mode 100644 Dockerfile delete mode 100644 docker/Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 35d4d115f1..0000000000 --- a/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM ubuntu:xenial - -RUN apt-get update && \ - apt-get dist-upgrade --yes && \ - apt-get install --yes \ - git \ - snapcraft \ - && \ - apt-get autoclean --yes && \ - apt-get clean --yes - -# Required by click. -ENV LC_ALL C.UTF-8 -ENV SNAPCRAFT_SETUP_CORE 1 diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index bffb2192c4..0000000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,74 +0,0 @@ -ARG RISK=edge -ARG UBUNTU=xenial - -FROM ubuntu:$UBUNTU as builder -ARG RISK -ARG UBUNTU -RUN echo "Building snapcraft:$RISK in ubuntu:$UBUNTU" - -# Grab dependencies -RUN apt-get update -RUN apt-get dist-upgrade --yes -RUN apt-get install --yes \ - curl \ - jq \ - squashfs-tools - -# Grab the core snap (for backwards compatibility) from the stable channel and -# unpack it in the proper place. -RUN curl -L $(curl -H 'X-Ubuntu-Series: 16' 'https://api.snapcraft.io/api/v1/snaps/details/core' | jq '.download_url' -r) --output core.snap -RUN mkdir -p /snap/core -RUN unsquashfs -d /snap/core/current core.snap - -# Grab the core18 snap (which snapcraft uses as a base) from the stable channel -# and unpack it in the proper place. -RUN curl -L $(curl -H 'X-Ubuntu-Series: 16' 'https://api.snapcraft.io/api/v1/snaps/details/core18' | jq '.download_url' -r) --output core18.snap -RUN mkdir -p /snap/core18 -RUN unsquashfs -d /snap/core18/current core18.snap - -# Grab the core20 snap (which snapcraft uses as a base) from the stable channel -# and unpack it in the proper place. -RUN curl -L $(curl -H 'X-Ubuntu-Series: 16' 'https://api.snapcraft.io/api/v1/snaps/details/core20' | jq '.download_url' -r) --output core20.snap -RUN mkdir -p /snap/core20 -RUN unsquashfs -d /snap/core20/current core20.snap - -# Grab the snapcraft snap from the $RISK channel and unpack it in the proper -# place. -RUN curl -L $(curl -H 'X-Ubuntu-Series: 16' 'https://api.snapcraft.io/api/v1/snaps/details/snapcraft?channel='$RISK | jq '.download_url' -r) --output snapcraft.snap -RUN mkdir -p /snap/snapcraft -RUN unsquashfs -d /snap/snapcraft/current snapcraft.snap - -# Fix Python3 installation: Make sure we use the interpreter from -# the snapcraft snap: -RUN unlink /snap/snapcraft/current/usr/bin/python3 -RUN ln -s /snap/snapcraft/current/usr/bin/python3.* /snap/snapcraft/current/usr/bin/python3 -RUN echo /snap/snapcraft/current/lib/python3.*/site-packages >> /snap/snapcraft/current/usr/lib/python3/dist-packages/site-packages.pth - -# Create a snapcraft runner (TODO: move version detection to the core of -# snapcraft). -RUN mkdir -p /snap/bin -RUN echo "#!/bin/sh" > /snap/bin/snapcraft -RUN snap_version="$(awk '/^version:/{print $2}' /snap/snapcraft/current/meta/snap.yaml | tr -d \')" && echo "export SNAP_VERSION=\"$snap_version\"" >> /snap/bin/snapcraft -RUN echo 'exec "$SNAP/usr/bin/python3" "$SNAP/bin/snapcraft" "$@"' >> /snap/bin/snapcraft -RUN chmod +x /snap/bin/snapcraft - -# Multi-stage build, only need the snaps from the builder. Copy them one at a -# time so they can be cached. -FROM ubuntu:$UBUNTU -COPY --from=builder /snap/core /snap/core -COPY --from=builder /snap/core18 /snap/core18 -COPY --from=builder /snap/core20 /snap/core20 -COPY --from=builder /snap/snapcraft /snap/snapcraft -COPY --from=builder /snap/bin/snapcraft /snap/bin/snapcraft - -# Generate locale and install dependencies. -RUN apt-get update && apt-get dist-upgrade --yes && apt-get install --yes snapd sudo locales && locale-gen en_US.UTF-8 - -# Set the proper environment. -ENV LANG="en_US.UTF-8" -ENV LANGUAGE="en_US:en" -ENV LC_ALL="en_US.UTF-8" -ENV PATH="/snap/bin:/snap/snapcraft/current/usr/bin:$PATH" -ENV SNAP="/snap/snapcraft/current" -ENV SNAP_NAME="snapcraft" -ENV SNAP_ARCH="amd64" diff --git a/docker/README.md b/docker/README.md index 528fb9acfb..4615244cbb 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,16 +1,26 @@ -# Creating docker containers for snapcraft +# Docker images for `snapcraft` -By default the `Dockerfile` builds Ubuntu 16.04 (Xenial) image with `snapcraft` from the `edge` channel. +OCI-compliant container images and their sources are officially supported by the +https://github.com/canonical/snapcraft-rocks/ project. - docker build . --no-cache +To build a snap with the docker container, you need to choose an image that +matches snap `base`. For example, to build `base: core24` snap: -It is however possible to choose the base Ubuntu version and the Snapcraft channel (risk levels): + docker run -it -v `pwd`:/project ghcr.io/canonical/snapcraft:8_core24 -- `edge` -- `beta` -- `candidate` -- `stable` + * `8` in `8_core24` is the version of snapcraft. + * `\; -v` construction at the end is required to see `snapcraft` output. -To do that, use `--build-arg RISK=` and `--build-arg UBUNTU=` arguments: +For more details, see official `snapcraft-rocks` repo from Canonical. - docker build . --no-cache --build-arg RISK=beta --build-arg UBUNTU=bionic +### Building snaps with `podman` + +`podman` was born as a rootless alternative to Docker. It is default on Fedora +to have `podman` instead of Docker, but SELinux there doesn't allow containers +to write to volumes, so we just turn this "feature" off with + `--security-opt label=disable`. + +```sh +podman run -it --rm --security-opt label=disable \ + -v `pwd`:/project ghcr.io/canonical/snapcraft:8_core24 \; -v +```