Skip to content

Commit

Permalink
Merge branch 'canonical:main' into sgmoore/add_core24_support
Browse files Browse the repository at this point in the history
  • Loading branch information
ScarlettGatelyMoore authored Oct 8, 2024
2 parents 7647205 + 24e70d6 commit b6cf912
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 112 deletions.
14 changes: 0 additions & 14 deletions Dockerfile

This file was deleted.

74 changes: 0 additions & 74 deletions docker/Dockerfile

This file was deleted.

30 changes: 20 additions & 10 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -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=<risk>` and `--build-arg UBUNTU=<name>` 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
```
2 changes: 1 addition & 1 deletion snapcraft/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions snapcraft/commands/validation_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion snapcraft/linters/linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/linters/test_linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/services/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b6cf912

Please sign in to comment.