Repository: beeware/briefcase

Issue:
Briefcase data directory is still being mounted in to containers for `brutus` user when `root` is used
### Describe the bug

With #1331, the user in Docker containers can now be `root` as well as `brutus`; however, Briefcase always mounts the data directory in to `.cache` directory for `brutus`. This doesn't appear to be having adverse effects right now....but it should probably be reconciled.

### Steps to reproduce

1. Using Docker Desktop, run `briefcase open linux --target debian`
2. Run `whoami` to see current user
3. Run `ls -lh /home/brutus/.cache/`

### Expected behavior

I suppose it doesn't _actually_ hurt anything to leave this as is....but it seems a lot more consistent if we use a user-agnostic location to bind mount the Briefcase data directory given we're not always using the `brutus` user now.

### Screenshots

_No response_

### Environment

- Operating System: pop os 22.04
- Python version: 3.10.12
- Software versions:
  - Briefcase: `0.3.16.dev20+g8b020d6c`


### Logs

_No response_

### Additional context

_No response_

Discussion:
rmartin16: > This makes sense as an approach, and the mechanics here make sense; however, don't we also need to make a change so that `BRIEFCASE_HOME` points to `/briefcase`?

I don't think so. Briefcase never actually runs inside the container.....so, nothing running in the container is inherently respecting `BRIEFCASE_HOME`. That said, if processes inside the container need to know where Briefcase's data directory is, they'll need to be informed directly. For instance, AppImage builds update `PATH` so linuxdeploy can find its plugins.

Patch:
diff --git a/changes/1374.bugfix.rst b/changes/1374.bugfix.rst
new file mode 100644
index 00000000..9c33eab7
--- /dev/null
+++ b/changes/1374.bugfix.rst
@@ -0,0 +1,1 @@
+Inside of Docker containers, the Briefcase data directory is now mounted at ``/briefcase`` instead of ``/home/brutus/.cache/briefcase``.
diff --git a/src/briefcase/integrations/docker.py b/src/briefcase/integrations/docker.py
index d1b69538..0651fcca 100644
--- a/src/briefcase/integrations/docker.py
+++ b/src/briefcase/integrations/docker.py
@@ -390,9 +390,9 @@ class DockerAppContext(Tool):
         self.python_version: str
 
     @property
-    def docker_data_path(self) -> PurePosixPath:
+    def docker_briefcase_path(self) -> PurePosixPath:
         """The briefcase data directory used inside container."""
-        return PurePosixPath("/home/brutus/.cache/briefcase")
+        return PurePosixPath("/briefcase")
 
     @classmethod
     def verify_install(
@@ -505,7 +505,9 @@ class DockerAppContext(Tool):
         if arg == sys.executable:
             return f"python{self.python_version}"
         arg = arg.replace(os.fsdecode(self.host_bundle_path), "/app")
-        arg = arg.replace(os.fsdecode(self.host_data_path), str(self.docker_data_path))
+        arg = arg.replace(
+            os.fsdecode(self.host_data_path), os.fsdecode(self.docker_briefcase_path)
+        )
 
         return arg
 
@@ -548,7 +550,7 @@ class DockerAppContext(Tool):
                 "--volume",
                 f"{self.host_bundle_path}:/app:z",
                 "--volume",
-                f"{self.host_data_path}:{self.docker_data_path}:z",
+                f"{self.host_data_path}:{self.docker_briefcase_path}:z",
             ]
         )
 


Test patch:
diff --git a/tests/integrations/docker/test_DockerAppContext__check_output.py b/tests/integrations/docker/test_DockerAppContext__check_output.py
index 226f62a9..f036a413 100644
--- a/tests/integrations/docker/test_DockerAppContext__check_output.py
+++ b/tests/integrations/docker/test_DockerAppContext__check_output.py
@@ -17,7 +17,7 @@ def test_simple_call(mock_docker_app_context, tmp_path, sub_check_output_kw, cap
             "--volume",
             f"{tmp_path / 'bundle'}:/app:z",
             "--volume",
-            f"{tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z",
+            f"{tmp_path / 'briefcase'}:/briefcase:z",
             "briefcase/com.example.myapp:py3.X",
             "hello",
             "world",
@@ -48,7 +48,7 @@ def test_extra_mounts(mock_docker_app_context, tmp_path, sub_check_output_kw, ca
             "--volume",
             f"{tmp_path / 'bundle'}:/app:z",
             "--volume",
-            f"{tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z",
+            f"{tmp_path / 'briefcase'}:/briefcase:z",
             "--volume",
             "/path/to/first:/container/first:z",
             "--volume",
@@ -83,7 +83,7 @@ def test_cwd(mock_docker_app_context, tmp_path, sub_check_output_kw, capsys):
             "--volume",
             f"{tmp_path / 'bundle'}:/app:z",
             "--volume",
-            f"{tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z",
+            f"{tmp_path / 'briefcase'}:/briefcase:z",
             "--workdir",
             "/app/foobar",
             "briefcase/com.example.myapp:py3.X",
@@ -122,7 +122,7 @@ def test_call_with_arg_and_env(
             "--volume",
             f"{tmp_path / 'bundle'}:/app:z",
             "--volume",
-            f"{tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z",
+            f"{tmp_path / 'briefcase'}:/briefcase:z",
             "--env",
             "MAGIC=True",
             "--env",
@@ -167,11 +167,11 @@ def test_call_with_path_arg_and_env(
             "--volume",
             f"{tmp_path / 'bundle'}:/app:z",
             "--volume",
-            f"{tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z",
+            f"{tmp_path / 'briefcase'}:/briefcase:z",
             "--env",
             "MAGIC=True",
             "--env",
-            "PATH=/somewhere/safe:/home/brutus/.cache/briefcase/tools:/app/location",
+            "PATH=/somewhere/safe:/briefcase/tools:/app/location",
             "--workdir",
             f"{tmp_path / 'cwd'}",
             "briefcase/com.example.myapp:py3.X",
@@ -205,7 +205,7 @@ def test_simple_verbose_call(
             "--volume",
             f"{tmp_path / 'bundle'}:/app:z",
             "--volume",
-            f"{tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z",
+            f"{tmp_path / 'briefcase'}:/briefcase:z",
             "briefcase/com.example.myapp:py3.X",
             "hello",
             "world",
@@ -218,7 +218,7 @@ def test_simple_verbose_call(
         ">>>     docker run "
         "--rm "
         f"--volume {tmp_path / 'bundle'}:/app:z "
-        f"--volume {tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z "
+        f"--volume {tmp_path / 'briefcase'}:/briefcase:z "
         "briefcase/com.example.myapp:py3.X "
         "hello world\n"
         ">>> Working Directory:\n"
diff --git a/tests/integrations/docker/test_DockerAppContext__dockerize_path.py b/tests/integrations/docker/test_DockerAppContext__dockerize_path.py
index 784a22ff..093c39f8 100644
--- a/tests/integrations/docker/test_DockerAppContext__dockerize_path.py
+++ b/tests/integrations/docker/test_DockerAppContext__dockerize_path.py
@@ -24,12 +24,12 @@ import pytest
         # data path is replaced with ~brutus/.cache/briefcase
         (
             "{tmp_path}/briefcase/path/to/file",
-            "/home/brutus/.cache/briefcase/path/to/file",
+            "/briefcase/path/to/file",
         ),
         # Multiple references in a single path are converted
         (
             "/unmodified/path:{tmp_path}/bundle/path/to/file:{tmp_path}/briefcase/path/to/other/file",
-            "/unmodified/path:/app/path/to/file:/home/brutus/.cache/briefcase/path/to/other/file",
+            "/unmodified/path:/app/path/to/file:/briefcase/path/to/other/file",
         ),
     ],
 )
diff --git a/tests/integrations/docker/test_DockerAppContext__run.py b/tests/integrations/docker/test_DockerAppContext__run.py
index c05c27cb..429181b5 100644
--- a/tests/integrations/docker/test_DockerAppContext__run.py
+++ b/tests/integrations/docker/test_DockerAppContext__run.py
@@ -18,7 +18,7 @@ def test_simple_call(mock_docker_app_context, tmp_path, sub_stream_kw, capsys):
             "--volume",
             f"{tmp_path / 'bundle'}:/app:z",
             "--volume",
-            f"{tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z",
+            f"{tmp_path / 'briefcase'}:/briefcase:z",
             "briefcase/com.example.myapp:py3.X",
             "hello",
             "world",
@@ -49,7 +49,7 @@ def test_interactive(mock_docker_app_context, tmp_path, sub_kw, capsys):
             "--volume",
             f"{tmp_path / 'bundle'}:/app:z",
             "--volume",
-            f"{tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z",
+            f"{tmp_path / 'briefcase'}:/briefcase:z",
             "briefcase/com.example.myapp:py3.X",
             "hello",
             "world",
@@ -85,7 +85,7 @@ def test_extra_mounts(mock_docker_app_context, tmp_path, sub_stream_kw, capsys):
             "--volume",
             f"{tmp_path / 'bundle'}:/app:z",
             "--volume",
-            f"{tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z",
+            f"{tmp_path / 'briefcase'}:/briefcase:z",
             "--volume",
             "/path/to/first:/container/first:z",
             "--volume",
@@ -125,7 +125,7 @@ def test_cwd(mock_docker_app_context, tmp_path, sub_stream_kw, capsys):
             "--volume",
             f"{tmp_path / 'bundle'}:/app:z",
             "--volume",
-            f"{tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z",
+            f"{tmp_path / 'briefcase'}:/briefcase:z",
             "--workdir",
             "/app/foobar",
             "briefcase/com.example.myapp:py3.X",
@@ -171,7 +171,7 @@ def test_call_with_arg_and_env(
             "--volume",
             f"{tmp_path / 'bundle'}:/app:z",
             "--volume",
-            f"{tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z",
+            f"{tmp_path / 'briefcase'}:/briefcase:z",
             "--env",
             "MAGIC=True",
             "--env",
@@ -222,11 +222,11 @@ def test_call_with_path_arg_and_env(
             "--volume",
             f"{tmp_path / 'bundle'}:/app:z",
             "--volume",
-            f"{tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z",
+            f"{tmp_path / 'briefcase'}:/briefcase:z",
             "--env",
             "MAGIC=True",
             "--env",
-            "PATH=/somewhere/safe:/home/brutus/.cache/briefcase/tools:/app/location",
+            "PATH=/somewhere/safe:/briefcase/tools:/app/location",
             "--workdir",
             f"{tmp_path / 'cwd'}",
             "briefcase/com.example.myapp:py3.X",
@@ -279,7 +279,7 @@ def test_interactive_with_path_arg_and_env_and_mounts(
             "--volume",
             f"{tmp_path / 'bundle'}:/app:z",
             "--volume",
-            f"{tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z",
+            f"{tmp_path / 'briefcase'}:/briefcase:z",
             "--volume",
             "/path/to/first:/container/first:z",
             "--volume",
@@ -287,7 +287,7 @@ def test_interactive_with_path_arg_and_env_and_mounts(
             "--env",
             "MAGIC=True",
             "--env",
-            "PATH=/somewhere/safe:/home/brutus/.cache/briefcase/tools:/app/location",
+            "PATH=/somewhere/safe:/briefcase/tools:/app/location",
             "--workdir",
             f"{tmp_path / 'cwd'}",
             "briefcase/com.example.myapp:py3.X",
@@ -323,7 +323,7 @@ def test_simple_verbose_call(mock_docker_app_context, tmp_path, sub_stream_kw, c
             "--volume",
             f"{tmp_path / 'bundle'}:/app:z",
             "--volume",
-            f"{tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z",
+            f"{tmp_path / 'briefcase'}:/briefcase:z",
             "briefcase/com.example.myapp:py3.X",
             "hello",
             "world",
@@ -339,7 +339,7 @@ def test_simple_verbose_call(mock_docker_app_context, tmp_path, sub_stream_kw, c
         "Docker| >>>     docker run "
         "--rm "
         f"--volume {tmp_path / 'bundle'}:/app:z "
-        f"--volume {tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z "
+        f"--volume {tmp_path / 'briefcase'}:/briefcase:z "
         "briefcase/com.example.myapp:py3.X "
         "hello world\n"
         "Docker| >>> Working Directory:\n"
diff --git a/tests/platforms/linux/appimage/test_build.py b/tests/platforms/linux/appimage/test_build.py
index 617cf9f0..ca0980f8 100644
--- a/tests/platforms/linux/appimage/test_build.py
+++ b/tests/platforms/linux/appimage/test_build.py
@@ -414,7 +414,7 @@ def test_build_appimage_in_docker(build_command, first_app, tmp_path, sub_stream
             "--volume",
             f"{tmp_path / 'base_path' / 'build' / 'first-app' / 'linux' / 'appimage'}:/app:z",
             "--volume",
-            f"{build_command.data_path}:/home/brutus/.cache/briefcase:z",
+            f"{build_command.data_path}:/briefcase:z",
             "--env",
             "LINUXDEPLOY_OUTPUT_VERSION=0.0.1",
             "--env",
@@ -426,7 +426,7 @@ def test_build_appimage_in_docker(build_command, first_app, tmp_path, sub_stream
             "--workdir",
             "/app",
             f"briefcase/com.example.first-app:py3.{sys.version_info.minor}",
-            "/home/brutus/.cache/briefcase/tools/linuxdeploy-wonky.AppImage",
+            "/briefcase/tools/linuxdeploy-wonky.AppImage",
             "--appdir",
             "/app/First App.AppDir",
             "--desktop-file",
@@ -531,12 +531,12 @@ def test_build_appimage_with_plugins_in_docker(
             "--volume",
             f"{tmp_path / 'base_path' / 'build' / 'first-app' / 'linux' / 'appimage'}:/app:z",
             "--volume",
-            f"{build_command.data_path}:/home/brutus/.cache/briefcase:z",
+            f"{build_command.data_path}:/briefcase:z",
             "--env",
             "DEPLOY_GTK_VERSION=3",
             "--env",
             (
-                "PATH=/home/brutus/.cache/briefcase/tools/linuxdeploy_plugins/gtk"
+                "PATH=/briefcase/tools/linuxdeploy_plugins/gtk"
                 ":/app:/docker/bin:/docker/sbin"
             ),
             "--env",
@@ -550,7 +550,7 @@ def test_build_appimage_with_plugins_in_docker(
             "--workdir",
             "/app",
             f"briefcase/com.example.first-app:py3.{sys.version_info.minor}",
-            "/home/brutus/.cache/briefcase/tools/linuxdeploy-wonky.AppImage",
+            "/briefcase/tools/linuxdeploy-wonky.AppImage",
             "--appdir",
             "/app/First App.AppDir",
             "--desktop-file",
diff --git a/tests/platforms/linux/test_DockerOpenCommand.py b/tests/platforms/linux/test_DockerOpenCommand.py
index 1b813ee7..a3fae7f3 100644
--- a/tests/platforms/linux/test_DockerOpenCommand.py
+++ b/tests/platforms/linux/test_DockerOpenCommand.py
@@ -87,7 +87,7 @@ def test_open_docker(open_command, first_app_config, tmp_path):
             "--volume",
             f"{open_command.base_path}/build/first-app/linux/appimage:/app:z",
             "--volume",
-            f"{open_command.data_path}:/home/brutus/.cache/briefcase:z",
+            f"{open_command.data_path}:/briefcase:z",
             f"briefcase/com.example.first-app:py3.{sys.version_info.minor}",
         ],
         stream_output=False,
diff --git a/tests/platforms/linux/test_LocalRequirementsMixin.py b/tests/platforms/linux/test_LocalRequirementsMixin.py
index 8de76c1e..34eb2806 100644
--- a/tests/platforms/linux/test_LocalRequirementsMixin.py
+++ b/tests/platforms/linux/test_LocalRequirementsMixin.py
@@ -170,7 +170,7 @@ def test_install_app_requirements_in_docker(create_command, first_app_config, tm
             "--volume",
             f"{tmp_path / 'base_path' / 'build' / 'first-app' / 'tester' / 'dummy'}:/app:z",
             "--volume",
-            f"{tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z",
+            f"{tmp_path / 'briefcase'}:/briefcase:z",
             "briefcase/com.example.first-app:py3.X",
             "python3.X",
             "-u",
@@ -338,7 +338,7 @@ def test_install_app_requirements_with_locals(
             "--volume",
             f"{tmp_path / 'base_path' / 'build' / 'first-app' / 'tester' / 'dummy'}:/app:z",
             "--volume",
-            f"{tmp_path / 'briefcase'}:/home/brutus/.cache/briefcase:z",
+            f"{tmp_path / 'briefcase'}:/briefcase:z",
             "briefcase/com.example.first-app:py3.X",
             "python3.X",
             "-u",